How long is too long for digital switch leads?

Hey guys,

A friend of mind is planning on taking a circuit that animates leds and putting the switches for it out on long leads. He'll probably be using standard ribbon cable, but he may use 28-24 awg wires. (I mention this because I assume the gauge makes a difference.) The leads will be around 3 feet long.

If those switches are used as pulldowns by the microcontroller that I assume is onboard, do you think there will be any issues with voltage drop or noise causing the switches to fail to work properly?

Probably OK, use lower value pull-up or pull-down resistors (2k2?) if problems occur..

Yes, switch contacts with lowish value pull-up or pull-down resistors (say 1k-5k ohms) is one of the few applications where you can run pretty long wires to a arduino digital input pin. You still have to be concerned and deal with contact bounce in your code or with external filtering just as with any switched contact input to an arduino digital input pin.

Lefty

I hadn't considered someone putting the pullup/pulldown resistors on the switch rather than the pin. I generally use the internal pullups and have the switch pull to ground without a resistor.

So would the switch having the resistor on it be the worst case then? If there were a 20K pullup on the pin, but the switch just went to ground, there should be no problem right?

The lower the pull up resistor value, the more current flows and so the further away from zero volts is the input because of the resistance of the return wire.

The higher the pull up resistor the more susceptible to noise is the input.

There is no real answer it is a compromise.

This is probably not an issue, but do be aware that (at least with weak pull-ups) it will take some time for the voltage on the switch wire to rise.

I ran into this when I replaced digitalRead with digitalReadFast in some code, and a switch reading became erratic.

Turned out the problem activating the internal pull-up immediately before reading the switch. digitalRead was slow enough for the voltage to rise on the switch line, but digitalReadFast was quick enough to catch the line while the voltage was still rising. (I assume this reflects the capacitance of a long wire going to the switch). Adding a 1 us delay after activating the pullups fixed it.

The lower the pull up resistor value, the more current flows and so the further away from zero volts is the input because of the resistance of the return wire.

The higher the pull up resistor the more susceptible to noise is the input.

That's only if the resistor is on the switch though, right?

If I were to use a switch on long leads like this in one of my own projects, and I used the internal 20K pullups on the Arduino, and wired the switch straight to ground, then the pulldown would be pretty darn strong compared to the pullup. And any noise that that wire might be picking up from RF when the switch isn't triggered would be pretty weak compared to a 20K pullup, wouldn't it?

So noise shouldn't really be an issue with that kind of setup even with fairly long (say 2 meter) leads, right?

This is probably not an issue, but do be aware that (at least with weak pull-ups) it will take some time for the voltage on the switch wire to rise.

I ran into this when I replaced digitalRead with digitalReadFast in some code, and a switch reading became erratic.

Turned out the problem activating the internal pull-up immediately before reading the switch. digitalRead was slow enough for the voltage to rise on the switch line, but digitalReadFast was quick enough to catch the line while the voltage was still rising. (I assume this reflects the capacitance of a long wire going to the switch). Adding a 1 us delay after activating the pullups fixed it.

Yeah, I should have remembered this because I had a similar issue with a board I built that used resistive touch switches.

The pins I used to read them had 1M pulldowns on them, and when you bridged two wires your skin provided a conductive path for +5v. But because the 1M pulldowns were so weak, the reading was really noisy unless I gave it time to settle. I finally solved the issue by putting a 10K pulldown on another analog pin, switching to that briefly, then switching back to the touch switch pins to read them. Because the pins are multiplexed to a single input inside the Atmega, the 10K was able to pull it down, and with only 1M holding it low, the +5v through around 100K of skin resistance, if there, was able to overpower it quickly. Each time I read it though, the 10K would reset it to ground before I took my new reading.

Worked amazingly well too. Noise was almost completely gone.

Also, the reason I couldn't just use a delay to stabilize the signal is because that stops everything, and with the 1M and skin resistance the delay needed to be pretty long to get a clean reading without the 10K trick.

That's only if the resistor is on the switch though, right?

No. If the resistor is on the arduino then you have the resistance of the there and back.

And any noise that that wire might be picking up from RF when the switch isn't triggered would be pretty weak compared to a 20K pullup, wouldn't it?

No.

Worked amazingly well too. Noise was almost completely gone.

I doubt if this is very repeatable.

If the resistor is on the arduino then you have the resistance of the there and back.

Are you talking about the resistance of the wires? That's negligible, isn't it? I mean when I say long leads I'm only talking 3-4 feet, and for 24-26 awg wire, a table I found online indicates it's only like 2-4 ohms every 100'.

And any noise that that wire might be picking up from RF when the switch isn't triggered would be pretty weak compared to a 20K pullup, wouldn't it?

No.

Hm... ohms law calculator says 5v and 20K ohms = 0.25mA. I thought it would be a lot more. I guess I can see how with that little current RF noise might affect it. Though I really haven't any idea how strong RF interference might be.

I doubt if this is very repeatable.

Oh? You said you were "quite chuffed" with my solution when I first posted about it. :) I'm not sure what your definition of repeatable is, but I've built like 10 of the circuits using those touch switches and they all continue to work great.

Here's that post where I first discussed this technique: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277629105

Here's that post where I first discussed this technique:

Ah, sorry I didn't remember the post, it was nearly 10000 posts ago and it wasn't clear in your reply above that you were using the analogue inputs.

Though I really haven't any idea how strong RF interference might be.

Have you got a scope? If so touch the lead and see the voltage pickup. It is very easy to get 20V peak to peak into a very high impedance. Now try putting a 20K resistor across the scope leads and touching it. It probably drops to zero. But that is only the signal from you with general mains pickup. If you add things like motors starting, florescent lights firing up and a Taxi outside calling back to base, then it can get considerably higher. In commercial electronics when going for approvals with things like access control that have to be wired between rooms, they actually but surges and spikes of 2KV on the lines to see if there is any disturbance.

No, I don't have a scope. :(

Hm, this RF interference stuff concerns me because in the board I am currently designing I also expect people to want to put switches on long leads. And I'd planned to use the internal pullups because they would allow for maximum flexibility, being that they can be turned off if I want to use the pins as outputs.

But now I'm wondering exactly how long it would be reasonable for those leads to be with switches and potentiometers. (I posted once before about some fellows I know who were trying to extend the leads on some pots on an amp and it was screwing up.)

I guess I'm just going to have to throw together something to test that at some point in the future. I assume if I still don't have a scope, I can put a switch on an analog pin and read the voltages I get I can tell from that how noisy my signal is and what kind of voltage drop I'm getting from various pullup resistors. And as long as I stay above 3.3v I'm okay there. Though the pots are a different story, I don't want those to drop much. (I know even a 5v Arduino can read 3.3v as a high from my SD card research.)