Pages: [1]   Go Down
Author Topic: Resistor: why?  (Read 393 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I am reading the book "Getting started with Arduino". One of the first examples is to connect a pushbutton to the Arduino board. So there is a cable from 5V to the pushbutton; from the pushbutton to the digital input on the board and from the pushbutton via a resistor to the ground. Why is the resistor needed?

I don't understand why you need to go from the pushbutton to the ground AND to the digital input on the board?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is a pulldown resistor. Without the resistor, when the pushbutton is released the arduino input pin is disconnected, leaving it free to pick up noise and return unexpected values. This resistor keeps the value at 0 when the pushbutton is released, but when it is pressed, the arduino pin goes to 1 since it is getting voltage from 5v
Logged

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The world is not a perfect place. If you just connect an input pin to one end of a pushbutton you can't be 100% sure of its state, because electrically it's not connected to anything. Static electricity, line noise, even cosmic radiation will cause stray readings.

You can see this yourself by writing a small program that just loops on "Serial.println(digitalRead(INPUT_PIN))" with nothing connected. It will randomly print 1s and 0s; for extra fun try touching the pin and you'll see even your body's capacitance will affect the readings.

So, you tie the input pin to ground. This way you're guaranteed consistent readings of 0 when the button is not pressed.

The resistor is to limit the current flow when the button is pressed. Look at your schematic and see what would happen with no resistor. When you press the button you'll be connecting +5V directly to ground, shorting out your circuit. Probably not what you want...

Good luck!

PS Google something like "how does a pullup resistor work" for much better explanations etc.
Logged

http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you measured the pin with the switch open, it would not be at 5v... but it won't necessarily be at 0v either- pins "float" at an undetermined voltage if not forced to 5 or 0v. So you need to connect the pin to ground when the switch is open.

BUT if you just put the other side of the switch directto 0v, when you closed the switch you would short circuit the 5v straight to ground and fry the board. So the resistor provides a load in that circuit to reduce the current that would other wise be there from the short.
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16459
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Keep in mind that there is a way to wire a simple push button switch to a input pin without requiring a external resistor, but still staying away from a 'floating input pin' condition. You wire one side of the switch to ground (not +5vdc) and the other side of the switch to the digital input pin. Then you activate the optional software enabled internal pull-up resistor for that digital pin number. Then in your sketch logic when the switch is pressed it will return a 0 and when released will return a 1.

Lefty
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Signal from a pushbutton without the resistor:
YouTube Video: http://www.youtube.com/embed/dBIBFLYCjMM

Signal from a pushbutton with a resistor:
YouTube Video: http://www.youtube.com/embed/SAIw7LLVl-U

You do not need to be an an engineer to understand that the first one is "bad" and the second one is "good".
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Pages: [1]   Go Up
Jump to: