I am using 4 normally open switches (2 roller + 2 push button) as input in my latest project (PetCurfew II). To simplify things, I have used the internal pullup resistor and am using interrupt service routines to detect switch closure. The setup is as follows (for each switch):
attachInterrupt(constCloseDoorSwitch, onCloseDoor, FALLING);
Every once in a while, say once every couple of days, one of the switches isr will fire by itself. It is not always the same switch and the time of day or night varies.
Have you encountered this before and is there a workaround? It kind of defeats the purpose if the door that is supposed to keep my cat safe unlocks by itself…
Full code is here: petcurfew.ino
You may want to try an external pullup resistor(s) and play with the values until the nuisance tripping goes away.
very common problem, you are experiencing…
I agree, try using lower value (like <1KOhm) external pull ups, to counter any noise that might get picked up by the wires between the switches and the photon. You can also try placing a 100nF cap across the switches, that may also help with noise issues (as well as contact bounce.)
Thanks, I will try that. I was hoping to do away with the extra hardware but oh well.
Is there a way to distinguish between these events and real ones in software maybe?
That way lies madness, you’re effectively connecting a decent sized antenna to the input pins, and the on-chip pull-ups/downs, are not enough to override the antenna-like behaviour.
@AndyW is it possible to augment the internal pull ups with additional external resistors? Or is it best to just disable the internals in sw and add the externals?
@netpex, you should use one or the other but not both at the same time. In your case, an external pull-up is better since the internal one is “weak” at ~40K ohms.