Tactile button maximum cable lenght?

You can probably go pretty far, may need to add addtional pullup resistor to ensure a good high level when the switch is open.

Or pulldown. But what do you mean by additional?

So 10-20 meters will not be a problem?
Maybe shielded cable?

I also have some water flow sensors here - here also I ask myself how long I can make
the cable.

This is what I mean by additional - not relying on internal pullup resistor.

Hard to say about the flow sensor without any data.

MrGlasspoole:
Or pulldown. But what do you mean by additional?

So 10-20 meters will not be a problem?
Maybe shielded cable?

I also have some water flow sensors here - here also I ask myself how long I can make
the cable.

Definitely shielded cable for that length, and some protection at the Arduino end from transients (1nF -- 10nF or so to ground?).
Where-ever you run cables for long distances near mains wiring (hard to avoid) you should expect switching transients to be an issue.

MrGlasspoole:
what is the maximum cable length to connect a tactile button to the Arduino?
What cable would be the best (awg)?

I dunno, but it's a looooooong way.

Do the math:

At 5V DC the AVR chip recognizes anything below 1V as "LOW" so you can afford to lose 4V over the wire.

The internal pullup resistors are about 30K Ohms so a pin will put out 0.15mA when configured as an input with pullup enabled.

Here's a table of wire gauges with resistances in ohms per kilometer (or kilofeet if you're still using old-fashioned units):

You've now got two of the variables in Ohm's law (current and resistance) so the rest is easy.

V = R * 0.00015

Any value of R that gives an answer less than 4V over your required distance is good enough (though you may want to limit it to 1V just to be on the safe side...)

1V is not correct.
V in high minimum with Vcc = 5V is 0.6 * Vcc, or 3V.
V in low maximum with Vcc = 5V is 0.3 8 Vcc, or 1.5V.
So you want that pin sitting above 3V when the switch is open, or below 1.5V when it is closed.
1.5V to 3V, you may get high or low readings from that.

See Table 29-1 in the '328 datasheet.

fungus:

MrGlasspoole:
what is the maximum cable length to connect a tactile button to the Arduino?
What cable would be the best (awg)?

I dunno, but it's a looooooong way.

Do the math:

At 5V DC the AVR chip recognizes anything below 1V as "LOW" so you can afford to lose 4V over the wire.

The internal pullup resistors are about 30K Ohms so a pin will put out 0.15mA when configured as an input with pullup enabled.

Here's a table of wire gauges with resistances in ohms per kilometer (or kilofeet if you're still using old-fashioned units):

American wire gauge - Wikipedia

You've now got two of the variables in Ohm's law (current and resistance) so the rest is easy.

V = R * 0.00015

Any value of R that gives an answer less than 4V over your required distance is good enough (though you may want to limit it to 1V just to be on the safe side...)

I dont think the resistance is the problem... I would more worry about induced currents and capacitance. Therefore it mainly depends on your environment.

MrGlasspoole:
So 10-20 meters will not be a problem?
Maybe shielded cable?

Should be no problem at all (so long as you don't pass next to any spinning magnets).

Arty:
I dont think the resistance is the problem... I would more worry about induced currents and capacitance. Therefore it mainly depends on your environment.

I don't think capacitance matters for a push button.

fungus:

Arty:
I dont think the resistance is the problem... I would more worry about induced currents and capacitance. Therefore it mainly depends on your environment.

I don't think capacitance matters for a push button.

I agree. The high voltage switching margins for a AVR input pin (.3vcc/.7vcc) gives the input pin quite a bit of 'noise immunity' and one should be able to run a passive switch contact a pretty long distance. I would consider using an external pull-up resistor of 1K ohms to lower the overall impedance of the switch wiring 'loop'. Anyway, as with any passive switch input you should use some kind of software debouncing function anyway, so any capacitance and inductive effects of a long wire run will not be a factor, you could probably reliably read a passive switch contact with a 1000 ft of twisted pair cable if you really wanted to. The problem with long cable runs is when one is trying to pass higher speed data signals where the cable run capacitance and inductive reactance has an effect of signal rise time, fall time, signal reflections, and external EMI interference.

Lefty

CrossRoads:
You can probably go pretty far, may need to add addtional pullup resistor to ensure a good high level when the switch is open.

(Old thread I know) I've been researching this topic and I want to question your statement. I'm a novice but what how does the strength of the pullup have any effect when the switch is open? It seems that if the switch is open any length of wire attached to the input has no effect. How can a long wire affect the level? It seems that even if a signal is induced onto a long wire that it would have no effect since the line is already high. On a length of open wire what could possibly cause it to bring the line low other than a connection to ground?

A long wire is an antenna. It picks up electrical and magnetic noise. The stronger pullup increases the signal-to-noise ratio.

This is what I have done in the past, See image.
My switches where 500ma rated gold plated contacts and limit switches are 10amp rated(minimum current for these to work correctly is 50Ma) and I use 8 of them, the system runs from 24V (could be 12V) and I used 3 1K5 resistors in parallel to create 50Ma current draw (this is to make sure good contact is made) A zener diode to clamp and a schottky diode then a 4K7 pull resistor and then 100K current limiting resistor with a 100N as the filter, I've found this very reliable and my cable length is about 10 meters and it has never suffered any problems or incorrect press detects, Also in the code is some debcounce routine. On checking with the scope the signal to the Arduino is very clean. Also carried out noise test's and induced 100-1000khZ noise on the line and still a clean signal and no issues. The 3 resistors and switch are mounted off the PCB, At the end of the 10meters of cable)

Comments welcome.

MorganS:
A long wire is an antenna. It picks up electrical and magnetic noise. The stronger pullup increases the signal-to-noise ratio.

But that is kind of my point. So it picks up some noise. The noise could only be an impulse right? How could it be a drain that would drag the line low?

Because the Arduino inputs are very sensitive and very fast. If the line dips below 3V for a nanosecond, that could be read as low. It would be very inconsistent and difficult to find the problem.

How much energy does it take to change the voltage on a 1pF (that's 10-12) capacitor by 2V for 1ns (10-9)? I haven't worked it out but I'm sure it's really small. A good antenna might pick up that much energy from a thunderstorm on the other side of the planet.

I don't mean to beat a dead horse but I'm still confused. You say it could pick up energy... If it's picking up energy why would that cause a line that is at 5V (and held there by a pullup) to DROP by 2V? Even for a nanosecond.

Because the internal pullup is weak. The antenna formed by a long wire can overpower it. A stronger pullup will require more energy to overcome. Long wire = stronger pullup.

freakdaddy:
But that is kind of my point. So it picks up some noise. The noise could only be an impulse right? How could it be a drain that would drag the line low?

What about a negative pulse :wink: With a pull-up, the line will be at 5V. A negative pulse will pull the line to another voltage.

+5V ---------+  +-------
             |  |
             |  |
             +--+
            pulse

Instead of a negative pulse, you can superimpose a sinewave or squarewave or whatever on the 5V line which better reflects noise.

Ok... that makes sense. I never really considered that the pulse could be negative.