Interrupt connected Button fired when power supply spike [SOLVED]

I am developing a control device using a photon. The device will be controlling a 12VDC solenoid and will be powered from the 12V (45Ah battery) supply through a 5V regulator board. I am using software timers to control the on time and the main loop() has various states (timing, standby being the key ones). There is one button to control this with a simple connection to pull up a digital pin when the switch is made to the 3.3V supply on the photon. The digital pin is setup with INPUT_PULLDOWN.

pinMode(wake, INPUT_PULLDOWN);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
attachInterrupt(wake, wakeupButtonPressed, RISING);

I have a 10K ohm resistor to limit the current and a 100nF capacitor in parallel with the resistor to debounce. Currently, I am powering the photon from a iMac using the USB lead.

The problem I am experiencing is that if there is any light/power socket switched on nearby I keep seeing ghost button presses. I assume these are spikes in the input power supply.

I thought the capacitor would fix this - could anyone help with suggestions about how to fix this issue. Bigger capacitor - software debounce in the interrupt handler function?

UPDATE: I did some web searches on switch debouncing and changed the damper circuit I was using. This appears to be working for now. There is a lot of materials on the web for debouncing (electronic circuits and special ICs as well as software algorithms). This site is good switch debouncingand so are the tutorials on the arduino site. I have updated as solved.

2 Likes