## Pull-Up Resistors

Let's say I have a microcontroller (MCU) with one pin configured as an input. If I don’t 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. 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.
2. 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 100k-1MOhm. 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.

### Quiz Question - Optimal Resistor Value I

You are using this system: Due to various design constraints you need to limit the current when the button is pressed to 0.5mA. VCC is 3V. What is the best pull-up resistor value to use?