Make Your First Light Blink!
The Story
You're the captain of a tiny spaceship — the ESP32.
Right now every light on your ship is off. Mission Control is waiting for a sign you're online.
Your first command? Turn on one small LED. When it blinks, you'll know your ship heard you — and you're officially a maker.
Explain Like I'm 12
- An LED is a tiny light on a chip.
- Your ESP32 is the brain — it has pins you connect wires to.
- Power on → LED glows. Power off → LED goes dark.
- Blink on, blink off — that's your first program!
Watch the tutorial
Follow this guide’s wiring and GPIO assignments when building; the video may use different pins or a different board.
Before you start
- Supported board and tools
- Classic ESP32-WROOM-32/32E DevKit exposing GPIO2. Arduino IDE 2.x and esp32 by Espressif Systems 3.x; select the matching board and port. Complete the IDE setup guide first.
- Hardware and expected result
- External ordinary indicator LED, 220–330 ohm series resistor, breadboard, jumpers and USB data cable. GPIO2 HIGH lights the LED for 500 ms; LOW turns it off for 500 ms. No onboard LED is required.
- GPIO2 restriction
- On classic ESP32, GPIO2 must be floating or LOW when entering serial download mode. This LED-to-ground circuit has no pull-up. If uploading fails, unplug USB, disconnect the GPIO2 wire, upload, then unplug again before reconnecting. Other ESP32 families need their own pin map.
- Safety and verification
- Disconnect USB before rewiring; never connect 5 V to GPIO. This update was reviewed against documentation, not compiled for ESP32 or hardware tested.
Prerequisites
Components Required
- ESP32 DevKit boardClassic ESP32-WROOM DevKit exposing GPIO2; other families need their own wiring.
- LEDOrdinary indicator LED; the supplied build photos use a green LED. External LED, not an assumed onboard LED.
- 220 ohm resistor220 ohms (red-red-brown for a four-band resistor) or 330 ohms; verify with a meter if unclear.
- BreadboardHalf-size is perfect
- Jumper wiresMale-to-male, at least 3
- USB cableMust carry data — not charge-only
How Does Blinking Work?
- Each pin on the ESP32 can be ON or OFF — these are called GPIO pins.
- The resistor protects the LED from too much power — like a speed bump for electricity.
- setup() runs once and tells the pin to be an output.
- loop() repeats forever — turn on, wait, turn off, wait. That's the blink!
Wiring Diagram
Follow these steps in order. Unplug USB before you change any wires.
-
1
Unplug USB. Place the ESP32 on the left and the breadboard on the right.
-
2
Push the LED into the breadboard — long leg (+) in one row, short leg (−) in a different row.
-
3
Connect GPIO 2 on the ESP32 to one end of the 220 ohm resistor (white wire in the supplied build photos).
-
4
Connect the other end of the resistor to the same row as the LED's long leg (+).
-
5
Connect the LED's short leg (−) row to GND on the ESP32 (black wire).
-
6
Double-check — GPIO 2 → resistor → long leg → LED → short leg → GND.
-
7
Plug in USB and upload the code. Watch your LED blink!
GPIO Table
| Signal | ESP32 Pin | Mode | Notes |
|---|---|---|---|
| LED output | GPIO2 | OUTPUT | Sends HIGH to turn the LED on and LOW to turn it off. |
| LED current path | GPIO2 through 220 ohm resistor | Current limited output | The resistor protects the LED and ESP32 pin from too much current. |
| Ground return | GND | Ground | Completes the circuit so current can return to the ESP32. |
Arduino Code
Copy this into Arduino IDE, then click Upload.
#include <Arduino.h>
constexpr uint8_t LED_PIN = 2;
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
}
- Save this complete Arduino sketch as blink_led.ino and upload after selecting the board and port. No extra library is needed.
- setup() configures GPIO2 and starts LOW; loop() alternates HIGH and LOW every 500 ms.
- Change both delays to 200 or 1000 to compare timing.
- This guide supplies only the complete Arduino example. PlatformIO and ESP-IDF alternatives are deferred until their full project setup and code are provided.
Real external LED build photos and clip
Explore the build photos and recorded results. Open any image to inspect the details.
About this recorded build
The contributed build uses a green external LED, a white GPIO2 jumper and a black ground jumper. The logical diagram uses illustrative colours; follow the GPIO2 → series resistor → LED anode → LED cathode → GND connections, not wire colour alone.
The supplied sketch matches the complete example: GPIO2 HIGH for 500 ms, then LOW for 500 ms. Photographs do not verify hidden breadboard connections or establish a board-package version; check the diagram and the labels on your own parts.

Unpowered wiring overview. Use the logical wiring diagram to trace the connection path; confirm your breadboard’s internal rows.
View full-size image
The contributor’s arrow identifies D2/GPIO2. Follow your actual board label rather than a generic header position.
View full-size image
Contributor-marked LED polarity. Verify the flat edge, leads and the documentation for your LED; the photograph is not a universal package drawing.
View full-size image
External LED off in the supplied capture. The board power indicator can remain lit.
View full-size image
External green LED on in the supplied capture. Board indicators may also light; this guide does not rely on them.
View full-size imageOpen the silent demonstration clip
Code and files
Expected Behaviour
Illustrative expected output, not recorded hardware data:
The external LED lights for 500 ms, then goes dark for 500 ms, repeatedly. An onboard LED is not required and its GPIO/polarity can differ by board.
If the external LED stays off, disconnect USB before checking GPIO2 → resistor → LED anode → cathode → GND.
Troubleshooting
Most ESP32 problems are wiring, power, library, or timing issues. Check these first.
LED does not turn on
Likely cause: The LED may be backwards, the wire may be on the wrong GPIO, or the resistor may not share the same row as the LED long leg.
Fix: Disconnect USB, then trace GPIO2 → resistor → LED anode → LED cathode → GND. Verify the breadboard rows and reconnect power only after correcting wiring.
LED is very dim
Likely cause: The resistor value may be too large or the LED may not be fully seated in the breadboard.
Fix: Disconnect USB before reseating the LED/resistor. Verify a 220–330 ohm resistor and your indicator LED’s forward-voltage specification; LED types and colours can differ.
Upload succeeds but nothing blinks
Likely cause: Some boards do not connect the onboard LED to GPIO2, or the external LED wiring is incomplete.
Fix: Use the external LED circuit from the wiring diagram and check the exact GPIO label on your board.
Upload fails
Likely cause: The wrong board, wrong port, or a charge-only USB cable is selected.
Fix: Check board, port and a data USB cable using the IDE setup guide. On classic ESP32 GPIO2 must not be pulled HIGH for serial download; unplug, disconnect the GPIO2 circuit, upload, then unplug before reconnecting.
Engineer Tip
Before blaming the code, trace the physical circuit with your finger. GPIO2 should go to the resistor, the resistor should go to the LED long leg, and the LED short leg should return to GND.
Knowledge Check
Quick check — no grades, just confidence!
Q1. Why do we use a resistor with the LED?
Q2. Which line of code turns the LED on?
Q3. Which pin is the LED connected to in this mission?
Mini Challenge
No wrong answers — experiment and have fun!
- Blink faster — change delay(500) to delay(200).
- Blink slower — try delay(1000) for a calm, slow pulse.
- Blink SOS — three short, three long, three short.
- Invent your own pattern — can you make a heartbeat or a disco flash?
FAQs
Why does the LED need a resistor?
The resistor limits current. Without it, too much current can flow through the LED and possibly damage the LED or the ESP32 GPIO pin.
Which ESP32 pin should I use for the blink mission?
This external-LED circuit uses GPIO2 on a classic ESP32-WROOM DevKit. It does not assume an onboard LED. GPIO2 is also a boot-strapping pin; follow the setup note if upload fails. A different board/pin needs matching wiring and code.
What does HIGH mean in the blink code?
HIGH tells the ESP32 to drive the output pin toward 3.3 V. In this circuit, that lets current flow through the resistor and LED, so the LED turns on.
What does LOW mean in the blink code?
LOW tells the ESP32 to drive the output pin toward GND. With no voltage pushing current through the LED, the LED turns off.
Next Mission
Continue Learning
Technical references
- Espressif Arduino GPIO API — pinMode and digitalWrite for a digital output.
- Espressif classic ESP32 boot-mode selection — GPIO2 requirements during serial download; these are classic ESP32 restrictions.

