Image of eBits Academy fundamentals illustration

Pull-Up and Pull-Down Resistors - An Essential Tool!

  • January 20, 2022
  • |
  • Jesper Nielsen

 

If your electronics projects do not always behave as intended, you may be missing a pull-up or pull-down resistor somewhere in the circuit. This article explains and illustrates how pull-up and pull-down resistors are used, and shows what can happen without one. They are a valuable tool to keep in your toolbox for future projects.
Pull-up and pull-down resistors help hold an input at a defined level, either logic 1 or logic 0. If the input is not held at a level, it may float. This means it can jump between logic 0 and logic 1. As with many things, the transition between 0 and 1 is not perfectly sharp: the voltage follows a curve from logic 0 to logic 1 and vice versa. 
The image above illustrates how an ESP32 uses defined voltage thresholds to distinguish logic 0 from logic 1. The image is only a general illustration: ESP32 GPIO operates at 3.3V and must not be connected to 5V. Use the VIL and VIH limits in the datasheet for the specific chip.
The diagrams below show where to place the resistor depending on whether you want a pull-up or pull-down resistor. We will look more closely at each method below, including calculations and practical examples.
 

 

 

CONTENTS

PULL-UP & Its Uses

A pull-up resistor is often useful for holding an input pin in a known state when there is no input. This is done by adding a pull-up resistor between the input and a supply voltage, such as +5V in the image above for a suitable 5V system. For ESP32, connect the pull-up to 3.3V, not 5V. The input is then read as logic 1, or high.

CALCULATING THE VALUE

Choose the pull-up resistor based on the output’s allowed sink current and VOL at the low level, together with the input leakage current, VIH, and signal rise time. The current limit sets a lower resistance limit; leakage and rise time may set an upper limit. 10k ohms is a common starting point for slow button inputs, but is not a universal value. Do not use the older formula illustration below as the sole basis for sizing.

Vsupply is the supply voltage. Vh(min), also called VIH, is the lowest voltage guaranteed to be read as high. Read the allowed sink current together with the output VOL specification in the datasheet; VIH is not the voltage drop across an actively low output.

PULL-DOWN & Its Uses

Pull-down has the opposite function to pull-up: pulling the voltage down. As shown above, a resistor is connected between the input and ground. This causes the input to be read as logic 0, or low.

CALCULATING THE VALUE

The pull-down resistor must keep the input below VIL despite leakage current while avoiding overloading an actively high output. Leakage current typically sets an upper resistance limit, while allowed output current may set a lower limit. 10k ohms is a common starting point for slow button inputs; check the datasheet and signal speed. Do not use the older formula illustration below as the sole basis for sizing.

Vl(max), also called VIL, is the highest voltage guaranteed to be read as low. Distinguish between input leakage current and the current an active output can source; they are used for different sizing limits.

EXAMPLES OF FLOATING INPUTS (HI Z)

The example is implemented on an ESP32 using MicroPython. To read more about setting up MicroPython on ESP32, see this article: MicroPython

The example has a resistor in series with an LED on pin 4. On Pin23, we read whether the level is 0 or 1. The example shows that without a resistor pulling to logic 0 (pull-down), or a resistor pulling to logic 1 (pull-up), the input may float between 0 and 1. The video below illustrates this.

from machine import Pin
import time

p4=Pin(4,Pin.OUT)
p23=Pin(23,Pin.IN)

print(p23.value())

while 1:
    print(p23.value())
    if p23.value() == 1:
        p4.value(1)
    else:
        p4.value(0)
    time.sleep_ms(100)
    

 

PRACTICAL SOLUTION EXAMPLES

Here is an example with a pull-down resistor and a switch to prevent floating or unwanted readings on Pin23. The diagram below shows the breadboard setup. The pull-down resistor is R2 in this case. The video shows how switch SW1 lets us control the reading on Pin23. 

The diagram below shows the opposite: a pull-up resistor R4 that holds the input high, ensuring that it reads logic 1. Pressing switch SW2 pulls it to logic 0, turning off the LED. 

SPECIFICATIONS

The following materials were used for the tests above. All are available here at ebits.dk. Note: the push button, LED, and Dupont cables are available in the component mega kit at the bottom of the table.

USEFUL VIDEOS ABOUT PULL-UP AND PULL-DOWN

Leave a comment

Please note, comments need to be approved before they are published.