GPIO Default State

Before connecting a button to an MCU’s GPIO, we must use a resistor to set up the default GPIO state. The GPIO pin’s default state can be one of three: floating, HIGH, or LOW.

Floating State

A GPIO pin in a floating state is not connected to a defined voltage (either HIGH or LOW). In this state, the GPIO pin is susceptible to noise and interference, leading to unpredictable behavior. A pull-up or pull-down resistor is required to stabilize the pin and define its default state.

High State

To ensure the default GPIO state is HIGH, we can use a resistor to connect the GPIO to 3.3V. By connecting one end of the resistor to 3.3V and the other end to the GPIO pin, we set the GPIO to a HIGH state by default. This resistor is called a Pull-Up resistor because it “pulls” the GPIO pin up to a HIGH state.

Do not connect the pull-up resistor to 5V. The safe voltage level for ESP32 GPIO pins is 3.3V. The ESP32 GPIO pins are not 5V tolerant. Exposing them to 5V can damage the ESP32 or shorten its lifespan.

Low State

We can also set the default GPIO state to LOW by connecting one end of the resistor to GND and the other end to the GPIO pin. This ensures the GPIO pin is in a LOW state by default. This resistor is called a Pull-Down resistor because it “pulls” the GPIO pin down to a LOW state.

A typical pull-up and pull-down resistor value is 10kΩ. It provides enough resistance to limit current while allowing the GPIO pin to reliably read HIGH or LOW.

RELATED ARTICLES