Pages: [1]   Go Down
Author Topic: Pull Up resistor  (Read 583 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Sr. Member
****
Karma: 4
Posts: 320
Arduino - very interesting !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What exactly is a pull up resistor ?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26341
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Generally it isa resistor that connects between a pin and +5V.
It brings an input (or a signal) to a known high state when nothing is connected to drive the input high or low (i.e. floating).
Common usage: the internal pullups on input pins (about 20K to Vcc) can be enabled so that a switch which is connected to ground, when open will read as a digital 1, and when closed will read as a digital 0.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the internal pullups on input pins (about 20K to Vcc) can be enabled

and this is how you enable one:
Code:
// put this in setup
pinMode(mySwitchPin, INPUT);
digitalWrite(mySwitchPin, HIGH);
Logged

--
My New Arduino Book: http://www.arduinobook.com

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 329
KC4MM
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To old timers this sounds like a simple question. To newbies it is often an item of considerable confusion and understandably so.

First lets get some terminology and jargon out of the way.

In digital electronics the more positive power supply level (usually +5 Volts or +3.3 volts) is variously referred to as "Vcc", HIGH, "Logic 1", and often "UP"
The nore negative power supply level (0v) is referred to as "ground (GND)", "Logic 0", "LOW", and "DOWN".

If you take a look at the data sheet for a digital chip's input pin it will say (for example for an ATmega 328) you will see that  it says that a voltage on the pin lower than .3Vcc (1.5volts if VCC is +5V) is guaranteed to be recognized as a LOW input. A voltage above .6Vcc (3.0V) is guaranteed to be recognized as a logic HIGH input.
It doesn't say a thing about voltages in-between 1.5 and 3.0 volts which merely means that it may be recognized as a High or Low depending on a lot of factors. This isn't a good thing in the digital world which is counting on things happening predictably.

Now the input pins are often very high impedance which means that they are easily swayed by outside influences like "pick-up" from the air even. Ever touch the input of an audio amplifier and hear a hum from the speaker? That's due to pickup of electricity from the air by your body acting as an antenna. Lots of other things can cause the same thing. We don't want that.

So what do we do? We connect something to the input pin to "pull" its voltage to some known level in the absence of something else (like a switch maybe) overriding it. That something is almost always a resistor in the range of say 1k to 30k ohms. A compromise value which doesn't draw a lot of current from our power supply yet is low enough in value to be pretty much sure that the logic level on the pin is where we expect it to be if, say, the switch we have connected isn't closed.

If that resistor is connected between the input pin and the positive power rail (+5v) it's referred to as a "pullup", if it's between the input pin and ground (0V) we call it a "pulldown"

There are cases where a pullup or pulldown are neither needed nor desirable - for example if an input pin is connected to the output pin of some other logic IC -- but in many cases they ARE absolutely necessary. The case of connecting an input pin to a switch is one of them. There are so many cases where they are needed that the microprocessor manufacturer thoughtfully provided a built-in pullup resistor for every digital input pin on the chip! By default these pullups aren't connected but you can very simply cause a pullup (about 20k ohms) to be connected to an input pin that you are using by adding one line of code to your sketch!

Let's say you have a normally open pushbutton switch connected between Digital Pin 7 and ground. You know that pressing the button will connect pin 7 to 0 volts (Logic LOW). What you need is to be sure that when the button is NOT pressed pin 7 will be at +5Volts (Logic HIGH). Solution - connect a PULLUP resistor between pin 7 and +5V.
You can add a resistor externally by wiring it in OR use the on-chip pullup and save a part by adding the following to your code say in setup()

pinMode(7,INPUT); // specifies that pin 7 is an input pin
digitalWrite(7,HIGH); // when you write a HIGH to an input pin it causes the internal pullup resistor to be connected!

Simple as that.

Have fun.
« Last Edit: June 02, 2011, 07:05:41 am by RoyK » Logged

UK
Offline Offline
Sr. Member
****
Karma: 4
Posts: 320
Arduino - very interesting !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the replies guys

very much appreciated

so basically a pull up resistor allows electricity to flow (above a recognisable voltage)
Logged

CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so basically a pull up resistor allows electricity to flow (above a recognisable voltage)

The current flow through a pullup resistor will be (should be) negligible, and the function of a resistor isn't voltage dependent, in the sense you are describing. Any time there is a potential difference across the resistor, current will flow. In the context of a pullup resistor, it's almost tempting to describe that current as a side-effect, except of course that with no current flow, there would be no voltage drop at all, and thus we wouldn't be able to use a pullup to bring a pin to a potential of 5V (or whatever our logic HIGH is).

Here's another description of pull up/down resistors which I found to be quite helpful.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html (That's by forum member Grumpy Mike)
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Pages: [1]   Go Up
Jump to: