Skip to content

Test an ESP32 pull-up button input

Configure GPIO pins for digital output, digital input, and pull-up button input; use serial output as an evidence stream for the active-low LED response.

Use this button build-test cycle to record the pin mode, the observed press and release levels, and the output condition before trusting a GPIO prototype., your practice guide

Use this button build-test cycle to record the pin mode, the observed press and release levels, and the output condition before trusting a GPIO prototype.
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Configure GPIO pins for digital output, digital input, and pull-up button input; use serial output as an evidence stream for the active-low LED response.

Tier 1 · Web · No account

Version tested: Compiled and run in the public Wokwi ESP32 web editor on 2026-10-09. Date: 2026-10-09.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

780 bytes · Circuit connections

Download

sketch.ino

1,574 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled and run in the public Wokwi ESP32 web editor on 2026-10-09 on 2026-10-09; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In the Wokwi editor, paste the supplied diagram and sketch, then inspect the button, LED, and ESP32 wiring before starting.
    You will see
    Input: loaded the supplied diagram and sketch in the public Wokwi ESP32 editor. Observed: the blue button connects GPIO13 to ground when pressed. Observed: GPIO2 drives the green LED through a 220 Ω resistor. Observed: the Simulation panel showed the Start control and the LED was dark.
    Why it matters
    The button has no external resistor, so idle behavior depends on input mode. The ground connection makes a press a LOW input. The LED gives a visible output for the firmware condition. The stopped simulator is a wiring baseline, not an input reading.
    Real Wokwi editor before simulation; the ring marks the grounded input button beside the ESP32 and LED.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the Simulation panel, start Wokwi with GPIO13 configured as INPUT and read the first Serial Monitor line.
    You will see
    Input: started the sketch with GPIO13 in INPUT mode and did not press the button. Observed: the running simulation clock reached 00:02.649. Observed Serial Monitor: `EDGE mode=FLOATING pin=HIGH led=OFF transitions=0 t_ms=512`. Observed: the LED was dark in this one simulator run.
    Why it matters
    The serial line is a real reading from the running simulator. With no pull-up, an unpressed pin has no defined electrical idle level. This simulator happened to resolve it HIGH; that is not a guarantee of stability on hardware. The LED state follows this sketch's active-low condition.
    Running Wokwi circuit and Serial Monitor; ring marks the floating-input HIGH reading from the simulator.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    In the Serial Monitor input field, send P to enable INPUT_PULLUP, then inspect the idle line.
    You will see
    Input: sent `P` in the real Wokwi Serial Monitor. Observed: Serial Monitor printed `COMMAND=P`. Observed: `EDGE mode=PULLUP pin=HIGH led=OFF transitions=0 t_ms=2912`. Observed: the green LED remained dark while the button was released.
    Why it matters
    The command changes GPIO13 to INPUT_PULLUP in the running sketch. The internal pull-up defines a released HIGH level. The active-low LED rule keeps the output off for that HIGH. The next step tests the LOW state by pressing the grounded button.
    Running Wokwi editor with the ring on the pull-up idle HIGH line in Serial Monitor.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    On the Wokwi circuit canvas, press and release the blue button ten times, then inspect the transition count in Serial Monitor.
    You will see
    Input: clicked the real simulated button ten times after enabling the pull-up. Observed: a LOW press line and a HIGH release line appeared for each click. Observed final line: `EDGE mode=PULLUP pin=HIGH led=OFF transitions=20 t_ms=7612`. Observed: the LED returned to dark after the tenth release.
    Why it matters
    Each complete press-release cycle has two electrical edges. Ten cycles produced 20 counted transitions in this run. The final HIGH confirms the button returned to its pulled-up idle state. The LED output returned to the original active-low idle response.
    Wokwi button, LED, and Serial Monitor; ring marks transitions=20 after ten real simulated clicks.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In Serial Monitor, send R to reverse only the LED condition; press the button once on the circuit canvas and read its LOW line.
    You will see
    Input: sent `R`, then clicked the button once. Observed: Serial Monitor printed `COMMAND=R`. Observed: `EDGE mode=PULLUP pin=LOW led=OFF transitions=21 t_ms=8812`. Observed: the input still read LOW on a press while the green LED was dark.
    Why it matters
    The pull-up input did not change electrical meaning. The firmware condition alone reversed the LED output. LOW still identifies the grounded pressed state. Separating pin reading from output policy prevents a false wiring diagnosis.
    Real Wokwi simulation with button pressed; ring marks LOW input and LED OFF after reversed firmware policy.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In Serial Monitor, send N to restore the normal LED condition, then press the button on the circuit canvas once more.
    You will see
    Input: sent `N`, then clicked the same grounded button. Observed: Serial Monitor printed `COMMAND=N`. Observed: `EDGE mode=PULLUP pin=LOW led=ON transitions=23 t_ms=10212`. Observed: the green LED lit during the LOW press and went dark on release.
    Why it matters
    The restored rule lights the LED for a grounded press. The input remains active-low with INPUT_PULLUP. The press after reversal added another pair of transitions. The final state matches the committed sketch's normal LED condition.
    Real Wokwi editor with the ring on LOW input and LED ON after restoring the normal condition.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. A button uses an internal pull-up input. What reading should firmware expect when the button closes to ground?

    Return to the chapter’s knowledge check
  2. In Arduino-style firmware, where should pin setup and repeated sensor checks go?

    Return to the chapter’s knowledge check

Caution

A floating input is electrically undefined. Wokwi showed HIGH in this run; this does not establish how an unconnected physical ESP32 pin behaves in noise or temperature changes.

Return to Microcontroller Programming: Setup and GPIO · Browse Labs