Article & guide
Read the full article
## A small circuit with a useful lesson A button and an LED are enough to explore the core loop of many devices: read an input, make a decision and change an output. In this build the LED stays on while you hold the button and turns off when you release it. That makes the first result easy to check before adding toggle behaviour or more complex logic. ## Components - Classic ESP32-WROOM-32 development board — 1 - Breadboard — 1 - Tactile push button — 1 - LED — 1 - 330 ohm resistor — 1 - Jumper wires and a USB data cable ## What you will understand An input needs a defined idle state. INPUT_PULLUP uses an internal pull-up so an open button reads HIGH; pressing it connects the input to ground and reads LOW. The output logic therefore treats LOW as pressed. The LED resistor limits current and belongs in series with the LED, not across the supply. A four-leg tactile switch usually has two permanently connected legs on each side. Identify the switched pair with an unpowered continuity check rather than guessing from how the body looks. ## Check your result With power applied after inspection, release the button: the LED should be off. Hold the button: it should be on. Repeat several times. A permanently lit LED suggests the input is always grounded or your chosen switch legs are already connected. No light suggests an LED polarity problem, missing common ground or the wrong GPIO label. This deliberately uses held-button behaviour. A later toggle project should handle contact bounce before treating each transition as a separate press. ## Reference ESP32 GPIO API: https://docs.espressif.com/projects/arduino-esp32/en/latest/api/gpio.html ## Before you begin This is an educational build plan for a classic ESP32-WROOM-32 development board, not a report of a physically tested prototype. Check the pin labels and documentation for your exact board. Disconnect USB before changing wiring. Keep the circuit at USB/3.3 V levels; do not connect mains power. The AI-generated cover is illustrative and is not a wiring diagram.
1. Wire the output
With USB disconnected, connect GPIO23 to a 330 ohm resistor, the resistor to the LED anode, and the LED cathode to GND. Confirm the LED polarity using its datasheet or a component tester.
2. Wire the input
Connect one switched terminal of the button to GPIO18 and the other to GND. Do not connect this input to 5 V. Check the board pin labels, not just the physical row position.
3. Upload the sketch
Select your exact board in Arduino IDE with ESP32 support installed, then upload: ```cpp const int buttonPin = 18; const int ledPin = 23; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, digitalRead(buttonPin) == LOW ? HIGH : LOW); } ``` If upload fails, check that the USB cable supports data and the selected port belongs to this board.
4. Keep a build record
Record the board model, GPIOs, resistor value and the release/hold results. Photograph the completed wiring after you verify it; use your own photograph when sharing a tested build.
