OTD ACADEMY
Sign in / Sign up
Library

LIBRARYGPIO: reading and driving pins.

How a GPIO pin drives a line high or low or reads a button or sensor, why a floating input misbehaves, and what a pull-up resistor does. With ESP32 3.3 V examples.

A GPIO pin, for general-purpose input/output, is a microcontroller's connection to the outside world. Set it as an output to drive a wire high or low and light an LED or switch something on. Set it as an input to read a button or a sensor line. You pick the direction, then you read or write.

Output: driving a pin high or low

As an output, the pin connects internally either to the chip's supply, 3.3 V, for a high, or to ground, 0 V, for a low. That is enough to light an LED, switch a transistor, or send a signal to another chip. But each pin can only source or sink a limited current, on the order of tens of milliamps, so drive small loads directly and put a transistor between the pin and anything larger. Over-draw a pin and you damage it.

Input: reading a level

As an input, the pin reports whether the voltage on it sits above or below a threshold, returning a high or a low. The catch is a pin connected to nothing: it floats, picking up stray noise, and reads high and low at random. So any input that is not always driven by something needs a resistor to hold it at a known level when idle.

Pull-ups and pull-downs

A pull resistor ties an undriven input to a default level. A pull-up connects the pin to 3.3 V, so it reads high until something actively pulls it low. A pull-down connects it to ground, so it reads low until something pulls it high. A button wired to ground with a pull-up is the classic input: high when released, low when pressed. The ESP32 has internal pull-ups and pull-downs you switch on in firmware, so you often need no external resistor at all.

I=VpullRI = \frac{V_{pull}}{R}

That current matters: a 10 kΩ pull-up on a 3.3 V rail passes about 0.33 mA while the line is held low, which is why a weak (larger) pull-up saves power and a strong (smaller) one resists noise better. It is Ohm's law on the pull resistor.

Deep dive· 3.3 V logic, and why 5 V can kill a pin

The ESP32's pins are 3.3 V logic and are not 5 V tolerant. Feed a 5 V signal straight into an input and you can damage the pin, because it drives current into the chip's internal protection. If you need to read a 5 V line, level-shift it, or divide it down with a voltage divider first, so the pin never sees more than about 3.3 V. Outputs, in turn, only ever swing between 0 V and 3.3 V, which is worth remembering when driving a part that expects a taller 5 V logic high.

Inputs

Result

300

Ω · series resistor

Nearest standard value (E24): 300 Ω

Power in the resistor

7.5 mW

Size the series resistor when a 3.3 V GPIO drives an LED.
A GPIO pin as an output driving an LED through a resistor, and the same kind of pin as an input reading a button with a pull-up resistor.
One pin, two directions: driving an LED as an output, reading a button as an input.

On a One Thousand Drones L1.01 board a GPIO drives the on-board LED through a resistor, and the BOOT button pulls a pin to ground, exactly the output and input patterns above.

Checkpoint

Quick check

Before you read or drive a GPIO pin, what must you set?
Why does a floating input pin (connected to nothing) misbehave?
What does an internal pull-up resistor do to an input pin?
0 / 3 correct

One Thousand Drones engineering team · verified 2026-07