Circuits / Microcontrollers
ESP32 reading a button
A GPIO pin as an input with the internal pull-up: digitalRead(27) reads LOW while S1 is pressed

Tap a part to see its voltages and currents. It is a model, not a measurement.
What do you need?
- Development board ESP32 DevKitSearch on Amazon
- Push buttonSearch on Amazon
- Jumper wires × 3Search on Amazon
- BreadboardSearch on Amazon
How does an ESP32 read a button?
pinMode(27, INPUT_PULLUP) turns pin D27 into an input and connects an internal pull-up resistor of about 45 kΩ to 3.3 V. With the button released, nothing pulls the pin down, so it sits at 3.3 V and digitalRead(27) returns HIGH. The button S1 connects the pin to GND: pressed, the pin drops to 0 V and reads LOW, and only about 73 µA flows through the pull-up. The logic is inverted, pressed is LOW, which is why the program writes "pressed" when it reads LOW. It keeps the last value and prints only when the reading changes, so the serial monitor shows each press and release once. The 20 ms delay between readings also skips most of the bounce, the quick flicker of contacts that a real button makes for a few milliseconds when it closes.
Values from the Protoboard ISO simulation: a model, not a bench measurement.
Hear about the next circuit
One email when a new circuit is out, about twice a month. Nothing else.