

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
- 1 PULL-UP & Its Uses
- 2 PULL-DOWN & Its Uses
- 3 EXAMPLES OF FLOATING INPUTS
- 4 PRACTICAL SOLUTION EXAMPLES
- 5 USEFUL VIDEOS ABOUT PULL-UP AND PULL-DOWN
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.
|
Quantity |
Component |
Link |
|
1 |
ESP-WROOM-32 |
|
|
1 |
Blue LED |
|
|
1 |
270 ohm resistor |
|
|
1 |
2K ohm resistor |
|
|
1 |
Dupont cables |
|
|
1 |
Breadboard |
|
|
Partly combined solution |
||
|
1 |
Push button, LED, and Dupont cables |
Component mega kit – ebits.dk — current selection; check compatibility |