Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

Pull-Up Resistors

by a1ronzo | December 02, 2010 | 17 commentsSkill Level: Beginner

Let's say I have a microcontroller (MCU) with one pin configured as an input. If I dont connect anything to the pin, it is considered floating. This means the MCU might have a difficult time reading the state or voltage on the input pin. A pull-up or pull-down resistor will hold the pin to either a high or low state, while using a low amount of current. Pull-ups are common on most input logic lines, two-wire (I2C) lines, reset lines, et al. An application of a pull-up resistor is attaching a button to an input pin.

With a pull-up resistor, the input pin will read a high state when the button is open. When the button closes, it connects the input pin directly to ground, thus reading a low state. For this discussion we are ignoring the debounce of the button. So what value resistor should you choose? The short and easy answer is that you want a resistor value on the order of 10kOhm for the pull-up.

A low resistor value is called a strong pull-up, a high resistor value is called a weak pull-up.

The value of the pull-up resistor needs to be chosen to satisfy two conditions: 1. 2. When the button is pressed, the input pin is pulled low. The value of the resistor controls how much current you want to flow from VCC through the resistor R1, through the button, and then to ground. When the button is not pressed, the input pin is pulled high. The value of the pull-up resistor controls the voltage on the input pin. For condition 1, you don't want the resistor's value too low. The lower the resistor, the more power will be used when the button is hit. You generally want a large resistor value, but not too large as to conflict with condition 2. The general rule for condition 2 is to use a pull-up resistor (R1) that is an order of magnitude (1/10th) less than the input impedance (R2) of the input pin. An input pin on a microcontroller has an impedance that varies around 100k1MOhm. For this discussion, impedance is just a fancy way of saying resistance and is represented by R2 in the picture above. So, when the button is not pressed, a very small amount of current flows from VCC through R1 and into the input pin. The pull-up resistor R1 and input pin impedance R2 divides the voltage, and this voltage needs to be high enough for the input pin to read a high state. For example, if you use a 1MOhm resistor for the pull-up R1, and the input pin's impedance R2 is on the order of 1MOhm, the voltage on the input pin is going to be around half of VCC and the microcontroller might not register the pin being in a high state. In other words, with increasing values for R1, the voltage on the input pin decreases and you don't want it too low. Keep in mind that many MCUs, like the ATmega328 on the Arduino, have internal pull-ups that can be enabled and disabled. Another thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to voltage changes. This is because the system that feeds the input pin is essentially a capacitor coupled with the pull-up resistor, thus forming a RC filter. And RC filters take some time to charge and discharge. If you have a really fast changing signal (like USB), a large pull-up can limit the speed at which the pin can reliably change state.

All of these factors play into the decision on what value pull-up resistor to use.

So Let's See an Example

Let's say you want to limit the current to exactly 1mA when the button is pressed in the circuit above, where Vcc = 5V. What resistor value should you use? It is easy to show how to calculate the pull-up resistor using Ohm's Law:

Referring to the pictures above, Ohm's Law now is:

Rearrange the above equation with some simple algebra to solve for the resistor :

Remember to convert all of your units into Volts, Amps and Ohms before calculating (e.g. 1mA = 0.001 Amps). The solution is to use a 5K Ohm restistor.

Comments17 comments
Login or register to post comments.

helluva engineer | about 2 years ago 2 Another option is to connect your pull-up resistor to another MCU pin instead of directly to Vcc. Benefit: + You can switch power to your pull-up resistor so that you arent always drawing current, even when you arent reading that pin.

Draw backs: It takes up another MCU pin. Not very useful for asynchronous or interrupt-driven pins.

Ryan | about 2 years ago 2 Just use a 4.7k resistor for your pull-up or down for that matter unless the datasheet says otherwise (some call for a rather hefty imho 1k or other vaules) Easy rule of thumb and Ive been doing this for years Never had an issue when it comes to micros or digital logic. 10k works just fine most of the time too, better for higher voltage logic if its current your worried about. And as for current its more of an issue for switches than mom. buttons. Id sit and worry about pull up values if I had to launch something into space or was really super worried about battery life. Other than that you are just wasting your time. Use a 4.7k or 10k and move on. dave2 | about 2 years ago 1 Its useful to remember this is an Active Low input, arranged this way, ie it will return a 0 when read when its active. Take that into account for your code! The other handy thing is many microcontrollers have built-in pullups on inputs. On AVR chips, for example, you can get rid of the external pullup by using its internal one. Say, for example, were reading a button on PortB1, attach the switch to GND and directly to the pin PortB1, and in your code:

DDRB &= ~(_BV(PORTB1)); /* Make Port B1 input */<br /> PORTB |= _BV(PORTB1); /* Enable pull-up on Port B1 */<br /> nstatus = PINB & _BV(PORTB1); /* read switch, active low! */<br /> PORTB &= ~(_BV(PORTB1)); /* disable pull-up */<br />
(This also saves a tiny bit of power for switches not being read very often.) YMMV, I havent tested that code on real hardware :)

Mattamatta | about 2 years ago 1 A pin left floating is NOT the same as being tristated/high-z. When configured as an input, it will be a high-impedance node, but not in the same sense as a tristated pin. http://en.wikipedia.org/wiki/Three-state_logic Aside from that, this is a useful article, and pullups/pulldowns are something simple thats often underestimated and misunderstood.

o
Mattamatta:

a1ronzo | about 2 years ago 1 A pin left floating is NOT the same as being tristated/high-z.

Good catch! A floating pin might not always be high-Z or tri-stated. However, in the situation I was referring to, an input pin on some microcontrollers can be configured to be tri-stated or in one of 3 possible states (high_Z, low, or

high). For the atmega328, the tri-state case would be ({DDxn, PORTxn} = 0b00, see page 77 http://www.atmel.com/dyn/resources/prod_documents/doc8271.pdf).

Chris-33 | about 2 years ago 1 So is a pull-up resistor just a fancy way of saying a current limiting resistor? Tartan5 | about 2 years ago 2 Not really. A current limiting resistors function is to limit the amount of current flowing into something, ie the resistor before an led limits the forward current through the led so you dont burn it out. A pullup resistor is used (among other reasons) to provide a known state to an input. For example, if the resistor is eliminated from the above schematic, the input is known to be low (0 V) when the button is pressed, but the pin would be floating (not connected to any source) when the button is not pressed. If you read this input, you may get a 1, or you may get a 0, depending on noise coupling, etc. Note that some input pins can be configured internal to the device with a pullup.. AdamTolley | about 2 years ago 1 But why have a resistor at all? It seems like the concept of providing a logic high to the pin still applies with near zero resistance, and then the only reason for the resistor is to prevent too much current. The only way I can understand a pull-up resistor is as the current limiting part of a simple circuit segment that provides a known state to the input pin. That is to say it is the entire segment, or path to VCC that pulls the level high, and in that pull-up segment, the resistor is necessary, so we call it a pull up resistor. does that make sense or have too many bite-sized primers reduced me to babbling? icyfyer | about 2 years ago 1 @ Adam I think youre trying to ask if you could use a jumper instead of a resistor to achieve the same result, except without the current limitation. The answer is yes, of course, but that current limitation is necessary to avoid destroying your chip. Tartan5 | about 2 years ago 1 No, in the circuit above, replacing the resistor with a wire results in vcc being shorted to ground when the button is pressed, a very bad thing. In this case, it IS current limiting the current through the button AND providing a logic hi when not pressed. AdamTolley | about 2 years ago 1 So then, it is limiting current in both cases, but the flow of current would be the same direction with a zero ohm wire for each case correct? put another way, is there anything about the resistor that actually changes the flow direction of current which is what I always think when I hear pull-up like the value of the resistor would determine, at some threshold, the direction of the current but thats incorrect. correct? Brodie | about 2 years ago 1 correct! (correct that the direction of current changes assumption is incorrect) the direction of current flow only changes in the example when the button is pushed, well it just adds a second current path, basically it will take the path of lowest resistance. and the input will go from 1 to 0. pulling up or down is really just there to stop you input from jumping around from 0 to one randomly because of interference etc.

sirfuzz | about 2 years ago 1 Theres a slight typo in the last sentence (restistor). :) Mark Willis | about 2 years ago 1 Another thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to voltage changes. This is because the system that feeds the input pin is essentially a capacitor coupled with the pull-up

resistor, thus forming a RC filter. And RC filters take some time to charge and discharge. If you have a really fast changing signal (like USB), a large pull-up can limit the speed at which the pin can reliably change state. The -smaller- the resistance of the pull-up, the more effect itll have on the input signal, though; a pull-up is there to help the input signal to fall into the reading circuits logic levels, a 0.01 Ohm resistor would -really- mess up a USB input sighal, a 10Meg resistor would usually not do much for you. Mark (The Bypass Cap Maniac LOL)

Member #262106 | last year 1 When I was trying to pull up a PMOS transistor with a 10k resistor at the rate of 200 Hz, I actually found that the pull up was happening too slowly and the transistor was taking longer than 5 ms to actually switch off. Switched to a 2k resistor and all was well. For buttons and the like just use a 10k. For high speed stuff on the milli or micro second scalejust use 1-5k. mite51 | about 2 months ago 1 If Im designing system that has multiple sensors ( the same sensor ) with I2C connected to lengths of cable ( from 1 to 8 feet ) and use a multiplexer on the both the SDA and SCL lines ( as an alternate way to select a device since all devices have the same address ), where should I put the pullup resistors? Between the micro-controller and the multiplexer or on the PCB closer to the sensor? Seems like it should be closer to the sensor, but thats just a gut feeling without any sound scientifical reasoning( yes I did spell it wrong on purpose ). Any other related questions or input is welcome. MikeGrusin | about 2 months ago 1 As only one set of pullups is needed per I2C bus, it would probably make sense to have them near the microcontroller so that they can work for any stub that is switched into the bus. But do check the specs for your multiplexer to see whether additional pullups are needed on each stub; if its a repeater it may need them.

You might also like