longer lead lengths cause random triggering

I have three momentary SPST switches attached to three of an Arduino Mega's hardware interrupt pins: 2, 18, and 19. A switch closure, grounds its respective interrupt pin. I am using "pinMode(sw[1], INPUT_PULLUP)" on the pins.

I also use: attachInterrupt(digitalPinToInterrupt(sw[1]), SW[1], FALLING);

When I use short jumper wires between the switches and the Arduino, the interrupts respond accurately to switch closures. But when I extend the switches using a 4 or 5 foot long ribbon cable, interrupts other than the intended interrupt are randomly triggered with a switch closure.

Is there a standard noise bypass arrangement that is used in cases such as this? I am wondering whether a .01 mf cap on each lead would help. Or perhaps a 10K pull-up resistor on each lead.

I wanted to keep my wiring as standard as possible.


Switches and interrupts are hardly ever a good mix.

Use simple polling for your switches.

10 to 50ms rate for polling is usually sufficient.

How are your switches wired (schematic) ?

Hopefully a schematic is attached. Although it is very straight forward.

Will simple polling not detect the same random noise on the switch lines? It seems the noise is only present during a switch closure. BTW, I have a 300 ms debounce routine for the switches.

Thanks for your expertise and response.

Arduino Switches.png

Capacitors many help reduce false interrupts caused by noise but if you use them then there is obviously no need for interrupts as capacitors reduce speed of switch changes.

What are these switches connected to and that makes you think interrupts are required ?

Have you considered using switch polling ?

I initially considered using switch polling. But the hardware interrupts looked so simple and straight-forward, I decided to use those. With short jumpers, they worked perfectly.

There is no need for a fast interruption of the program. All the switches do is adjust ten different settings.

There is little need to pursue the hardware interrupts if doing so requires additional hardware.

In response to your earlier suggestion, I researched the code for switch polling. I found a button library, but I doubt that is necessary.

I am also experimenting with other control techniques such as IR receiver/remote and using Bluetooth for iOS device. The IR receiver works. I haven’t hooked up the Bluetooth receiver yet. My goal is to learn how these technologies apply.

Your help is appreciated!

I resolved the noise problem by placing a .01 mfd cap on the Arduino end of the leads from the switches. The hardware interrupts work error-free.

The built-in pullups are far too weak to deal with potential noise pickup on long wires. Use external pullups, anywhere from 100-1000 ohms. If switch bounce is a problem, add 0.1uF capacitors to ground.

Thanks Ray.

Perhaps the reason the caps work so well is that the wires are only about 5' long.

I called them "longer lead lengths" because they aren't the typical pin-type jumpers. But without the caps, the noise rendered the use of hardware-interrupts not possible.

I did try using switch polling, but the nature of the coding, consisting of several timers, installing the caps was the best option to take.

Tried spinning the ground & signal wires of your switch together? Twisted pair goes a log way towards killing off unwanted electrical noise.

-jim lee

There are three switches and I use a ribbon cable from the switches to the Arduino. I agree that either twisting the wires or shielding them could help keep EMI out.

But, the .01 caps eliminated all or enough of the noise to make the arrangement work error free.

Another factor to be considered (before I put the caps on) is that with only one switch connected on the Arduino end, extraneous triggering of the other hardware interrupts did not occur. But as soon as I connected more than one switch, extraneous triggering of the other hardware interrupts became a problem. So... it seems the problem wasn't from external EMI being induced into the wires. All I can figure is that the wires on the open / non-activated switches are tied to the relatively high impedance input pins and they pick-up a noise spike from the activated switch wire rather from other external sources.