Why use a Resistor with this Switch?

I’m not a complete newcomer to electronics, but I am no expert! I was looking through some videos on the Make: website and I came across a video called The Button. The guy in this video uses a resistor on the tact switch on the lead going to a pin on the Arduino. I was just wondering why not leave the resistor out? I don’t understand his explanation (well I do, but I don’t), why did he add a resistor when the switch is open and there isn’t any electricity going through the switch?

I’m assuming you’re talking about a pull-up resistor?

The reason is, if you don’t connect anything to an input, it is said to be “floating”. It could read high, or low.
The pull-up provides a high that can be “overcome” by a short (via the switch) to ground, giving a low.
HTH

But I thought there isn't any electricity going through the switch? Oh I think I see what is going on here. The Arduino pin needs to connect to ground to complete the input? Or am I just babbling?

The Arduino pin needs to connect to ground to complete the input? Or am I just babbling?

Well first just consider an Arduino input pin with nothing at all wired to it. What value would you assume it would read in software? Most beginners assume it would read as a 0 because there is nothing wired to it, no voltage, so it must be a 0. Well in reality if you read that pin you would find that you would get inconsistent values, sometime 0 sometimes 1. The pin in that state of nothing wired to it is said to be a 'floating' input pin and circuit noise will cause it to give inconsistent readings.

So one needs to add either an external pull-up resistor or a pull-down resistor, or in software, enable an internal pull-up resistor. This will ensure that when reading the pin the software will return a consistent value. So a input pin with a pull-up will have a switch wired to the pin and ground, so when you press the switch the software will see a 0 state, and if you are using a pull down resistor then the switch will wire between the pin and +5vdc and will read as a 1 when pressed.

That make sense?

Lefty

1 Like

@Lefty: It makes complete sense, I assumed it would read 0 volts as well, but that makes a lot of sense now.

Thanks!