False Button Presses on Photon

Hi there,

I’ve got a button wired up straight to D4 (and I’ve tried D5, D6, etc. with similar results) and GND. I setup the button this way:

    pinMode(D4, INPUT_PULLUP);
    attachInterrupt(D4, buttonWasPressed, CHANGE);

But somehow some kind of interference from other devices causes a false trigger of buttonWasPressed. This includes plugging in another device on the same surge protector as the photon. I’ve even tried a different photon and the same thing happened.

Any thoughts?

@lanewinfield, a CHANGE interrupt will trigger on a LOW-to-HIGH or HIGH-to-LOW transition. The internal pull-up, though often useful, is quite “weak” at 40K ohms. If you have any noise on the wires leading to the switch, it could trigger the interrupt. How long are your button wires? How are you powering the Photon?

I suggest you use an external 4.7K ohm pull-up instead for the button and add a large decoupling capacitor (100-470 uF) between the Photon’s Vin pin and GND, as near the Vin pin as possible. The fact that other devices are causing interrupts indicates that power to your Photon my be noisy.

5 Likes

Also, you’ll probably want to debounce the switch in software. If you choose a debounce algorithm that requires a minimum width of the LOW signal you can also eliminate the false presses. Though you should also change the pull-up and add the cap.

4 Likes

This is the schematic I keep referring back to for switch debouncing. Diode optional. You can use smaller resistors for a stronger pull-up as @peekay123 suggested.

Linked from: https://i.stack.imgur.com/Zv2Sa.png

2 Likes

I've got a 470uF 16V capacitor across Vin and GND and I thought it was there to provide v.short term backup in case of brown out rather than for decoupling? Or can it do both?

@netpex, the large cap acts as a power line filter to reduce any ripple on the DC supply. It can also act to reduce a brownout voltage dip but only on very short events. You can also add a 0.1uF cap across the 470uF cap to decouple the higher frequencies.

2 Likes

you have to debounce the switch i guess to get the low high balanced