Go Down

### Topic: Pullup resistors...? (Read 1 time)previous topic - next topic

#### Archive555

##### Dec 21, 2008, 09:46 am
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!

#### Sterling

#1
##### Dec 21, 2008, 10:02 am
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).

#### Archive555

#2
##### Dec 21, 2008, 11:31 am
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

#### kg4wsv

#3
##### Dec 21, 2008, 03:27 pm
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

#### mikalhart

#4
##### Dec 21, 2008, 05:40 pm
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: [Select]
`#define BUTTON_PIN 2void 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

#### Archive555

#5
##### Dec 22, 2008, 04:00 am
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

#### mikalhart

#6
##### Dec 22, 2008, 04:14 amLast Edit: Dec 22, 2008, 04:15 am by mikalhart Reason: 1
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

#### Archive555

#7
##### Dec 22, 2008, 10:08 am
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

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!

#### Grumpy_Mike

#8
##### Dec 22, 2008, 10:19 am
If the logic reversal thing bothers you then you can always buy a "push to break" push button.

#### jerrya.net

#9
##### Dec 22, 2008, 05:31 pm
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.

#### Grumpy_Mike

#10
##### Dec 22, 2008, 05:34 pm
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.

#### jerrya.net

#11
##### Dec 23, 2008, 04:56 am
Thanks, that makes sense.

#### sinaptik

#12
##### Dec 23, 2008, 09:44 am
This is a great thread, I was wondering what a pullup resistor was...

#### Archive555

#13
##### Dec 24, 2008, 04:17 am
Yeah, it is a good thread. The people here are so nice and helpful

Go Up

Please enter a valid email to subscribe