EN

Pull-up and pull-down resistors

How to set the level of a digital input and which resistor value to choose

What they are for

A CMOS digital input has an extremely high impedance: if it is not connected to anything it is left floating and its level is decided by any electrostatic charge, the capacitance of the cable or the noise of a nearby motor. The result is readings that change on their own and, on top of that, extra current draw, because the input stage sits halfway between 0 and 1. A resistor to the supply (pull-up) or to ground (pull-down) sets a resting level; the push-button, the sensor or the open-drain output only has to force the opposite level.

With a pull-up, the input reads 1 at rest and 0 when pressed (active-low logic); with a pull-down, the other way round. The pull-up is the most common choice: the button goes to ground, which is usually available everywhere, and almost every microcontroller has internal pull-ups.

Calculator for a digital input

Circuit
V
kΩ
Input data (datasheet)
V
V
µA
pF
Requirements
mA
µs

How it is calculated

The resistor value is bounded on two sides:

\[ R_{\min} = \frac{V_{CC}}{I_{\max}} \qquad R_{\max} = \frac{V_{CC} - V_{IH}}{n\,I_{\text{leak}}} \qquad t_r = 2.2\,R\,C \]

With a pull-down, the leakage condition is \(n\,I_{\text{leak}}\,R \le V_{IL}\). The rise time \(t_r\) is the time the voltage takes to go from 10 to 90 % (a little over two time constants). In practice, the real upper limit is noise: an input with 1 MΩ picks up interference even if it meets the formula. That is why usual values lie between 4.7 kΩ and 47 kΩ, and 10 kΩ is the default choice for push-buttons.

Strong and weak pull-ups

A strong pull-up is a low value (1 to 4.7 kΩ): it draws more current but gives fast edges and good immunity, useful on long cables and buses. A weak pull-up (47 kΩ to 100 kΩ, or the internal ones) draws little, but is only suitable for short connections on the board. In noisy environments or with cables longer than a few centimetres, an external resistor of a few kΩ is advisable and, if there are push-buttons, a debounce filter.

Internal resistors of microcontrollers

Almost every microcontroller can enable a pull-up (and many a pull-down too) on each pin. They are weak and their value varies a lot between units:

FamilyInternal pull-upInternal pull-downHow to enable it
AVR (ATmega328P, Arduino Uno)20 to 50 kΩNopinMode(pin, INPUT_PULLUP)
ESP32about 45 kΩabout 45 kΩINPUT_PULLUP / INPUT_PULLDOWN
STM32about 40 kΩabout 40 kΩPUPDR register or GPIO_PULLUP in HAL
RP2040 (Raspberry Pi Pico)50 to 80 kΩ50 to 80 kΩgpio_pull_up() / gpio_pull_down()
PIC (ports with WPU)weak, tens of kΩDepends on modelWPUx registers

Indicative values from the datasheets; some pins (for example the input-only pins of the ESP32) have no internal resistors.

Open-collector and open-drain outputs

An open-drain output (open-collector if it is bipolar) only has the transistor that pulls the line to ground: it can drive a 0, but for a 1 it needs an external pull-up. This allows two very useful things: connecting several outputs to the same line without them fighting (any of them can pull it to 0, which forms a wired-AND function) and returning the pull-up to a voltage different from the chip's own, which works as level shifting. Reset lines, shared interrupts, the 1-Wire bus and the I²C bus all work this way.

I²C bus pull-ups

The SDA and SCL lines of the I²C bus are open-drain and each needs one pull-up (not one per device). The minimum resistance is set by the current the outputs can sink without exceeding the maximum low level; the maximum, by the rise time the specification allows with the bus capacitance.

V
pF
V
\[ R_{p,\min} = \frac{V_{CC} - V_{OL,\max}}{I_{OL}} \qquad R_{p,\max} = \frac{t_r}{0.8473\,C_b} \]

The factor 0.8473 is \(\ln(0.7/0.3)\): the rise is measured between 30 and 70 % of VCC. Each device adds about 10 pF and each centimetre of track or cable around 1 pF; commercial modules often already carry their own pull-ups (usually 4.7 or 10 kΩ), and when several are connected they end up in parallel.

ModeFrequencyMaximum trMaximum CbIOL at VOL = 0.4 V
Standard100 kHz1000 ns400 pF3 mA
Fast400 kHz300 ns400 pF3 mA
Fast plus1 MHz120 ns550 pF20 mA

If the minimum resistance turns out higher than the maximum, the bus has too much capacitance for that speed: drop to a slower mode, shorten the wiring or use an I²C repeater or bus extender.

Common mistakes

Related: push-button debouncing, logic level shifting, transistor as a switch and Ohm's law.