Pages: [1]   Go Down
Author Topic: Pullup resistors...?  (Read 1463 times)
0 Members and 1 Guest are viewing this topic.
Melbourne, Victoria, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, after reading some of the basic tutorials on the Arduino website (mainly the ones that include a button), they tend to mention these 'Pullup resistors' quite a lot, with one pin of the button connected to GND, another to an I/O pin, and that connected to +5V via a resistor. Here's what I want to know:

Why is the resistor needed? And can it be omitted and just connect the button to +5V on one side, and the I/O pin on the other?

From what I gather, the resistor is there so that you get an accurate reading, instead of it fluctuating between HIGH and LOW. If so, then why is this a problem? How/Why does this occur?
I've made a circuit using a button the way they describe, but I still don't quite understand why  :-[

Thanks for any help, I really appreciate it!  smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
From what I gather, the resistor is there so that you get an accurate reading, instead of it fluctuating between HIGH and LOW. If so, then why is this a problem? How/Why does this occur?

If you leave a pin floating (no pullup or pulldown resistor), you'll get pretty random values out of it (stray capacitance, inductance, resistance, cosmic rays, whatever).  This can be good for say...a random number generator but not so good for things you want to work consistantly...like...switches.

Quote
And can it be omitted and just connect the button to +5V on one side, and the I/O pin on the other?

It depends on the circuit.  For a simple high/low button - probably.  As i said before there can be stray capacitance on a pin that could cause it to stay high/low for longer than you expect.  Resistors are cheap, so I wouldn't omit it.

Pullup / Pull down resistors - Resistors used to drive a pin to a known voltage.  If connected in a switch like shown on the examples, the pin which is normally not connected to GND is "pulled high" by the resistor.  If you took a multimeter to that node it would read just a tad under 5V.  When you push the switch a circuit is made between +5V the pull up resistor, the switch and GND.  The switch has a very small resistance, something like 2 Ohms or less, so most of the voltage is dropped across the pullup resistor.  If you took a multimeter to that same node it would now read just a hair over 0V.  When the switch is released the resistor pulls the node back up towards +5V.  

Pulldown resistors work the same way but are connected to GND instead of +5V (or whatever that Vdd happens to be).
Logged

Melbourne, Victoria, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great. Gotcha. Thanks for the help.
I've been tinkering around with the 'Pushbutton' tutorial on the Arduino website, where they talk about interpreting a 'HIGH' as the button NOT being pressed, this seems unnatural to me, so I've switched the wiring around, so ground is now connected to the resistor, and +5V is not, so should I use a pullDOWN resistor instead?

The tutorial program has +5V going straight to Button pin 1, and GND going through a pullup resistor to button pin 2, as well as to pin 2.
I have the GND going straight to button pin 1, and +5V going through a pullup resistor to button pin 2, as well as to pin 2.

So the GND and +5V have been switched.
So should I use one of these 'Pulldown' resistors instead of a Pullup resistor? If so, what value do you recommend?

Thanks for the help  ;D
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another thing the pull up/down resistors are good for is limiting current, so you don't fry the arduino (or one of its i/o pins) by trying to draw too much current.  While a simple wire could allow theoretically unlimited current to flow, using a pull up/down resistor limits that current to something sane for the device providing the power, while still providing plenty of current for the device doing the sensing.

Failing to provide a current limiting resistor could fry the arduino's outout pin, or could cause the voltage regulator to reset, or could cause your USB port to flake out, depending on the circuit in question.

-j

Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 5
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Archive,

I agree that at first blush the logic which says "if the button is depressed, bring the pin low, otherwise keep it high" might seem contrary.  It did to me.  But there's a pretty good reason to do so if you are as lazy as I am, and that's that Arduino pins have built in pullup resistors, but if you want to implement the "intuitive" logic, you're on your own to provide the pulldown resistor.

To use the built in, just connect the button between pin and ground and use the following code:

Code:
#define BUTTON_PIN 2
void setup()
{
  pinMode(BUTTON_PIN, INPUT); // define pin as INPUT
  digitalWrite(BUTTON_PIN, HIGH); // deploy pullup
}
...

Now when BUTTON_PIN goes low it means that the button has been pressed.

Mikal
Logged

Melbourne, Victoria, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, but I'm using a Bare Bones Board, so are the Pullup resistors still built in?

And I'm still wondering if my setup would work; just reverse the ground/positive pins around, it seems to me that it would, but I'm not sure if it will.

Thanks for the help anyway, I'll try it  smiley
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 5
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your setup will work fine.  That's how I used to wire buttons until I realized I was wasting my time and precious resistors and solder.  The pullups are in the Atmel processor chip, so yes, no matter what board you are using you have them.

Mikal
« Last Edit: December 21, 2008, 10:15:02 pm by mikalhart » Logged

Melbourne, Victoria, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks alot, although I have a feeling I'll be including the resistor for quite some time, I'd really rather not chance it with my new *Duino  smiley-grin

I was mainly concerned with whether or not it would be possible to make it LOW when not being pressed, and HIGH when being pressed, and now I have my answer. Thanks for all the help!  smiley
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34594
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the logic reversal thing bothers you then you can always buy a "push to break" push button.
Logged

St. Louis MO
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there ever a reason not to use a built-in pullup rather than an external one? It seems to me that the tutorials teach the necessity of a pullup, get you used to using them, and after that you can understand why you would use an internal pullup.

But, I've been wondering if there is a downside to using a built-in pullup.
Logged

- Jerry Adlersfluegel

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34594
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The built in pullups are only weak pullups.

That is they are a higher resistance than you would normally use. This means that by using external pullups you can control the amount of current you pull and hence increase the noise immunity of the inputs.

For most projects here you can get away with internal pullups.
Logged

St. Louis MO
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that makes sense.
Logged

- Jerry Adlersfluegel

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a great thread, I was wondering what a pullup resistor was...
Logged

Melbourne, Victoria, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, it is a good thread. The people here are so nice and helpful  ;D
Logged

Pages: [1]   Go Up
Jump to: