#01 Beginner ⏱ 15 min
ESP32: Blinking LED
The first program on every microcontroller: turn an LED on and off every second. You learn what a digital output is, why you need a resistor and what the endless loop() looks like.
Open it interactively in 3D →What you learn
pinMode / digitalWrite / delayAnode vs cathodeWhy always a resistor with an LEDHow breadboard columns join components
You need
- ESP32 DevKit V1 — microcontroller with WiFi and Bluetooth
- Breadboard — wiring without soldering
- Jumper wires — M–M, M–F, F–F
- LED — light-emitting diode 5 mm
- Resistor — 220 Ω, 1 kΩ, 10 kΩ…
How it works
Current flows in a circle: GPIO 2 → LED → resistor → GND. When the program writes digitalWrite(2, HIGH), the pin is internally connected to 3.3 V and current flows — the LED lights. With LOW the pin goes to 0 V, no voltage difference, no current — the LED goes dark.
The setup() function runs once (we say the pin is an output), and loop() repeats forever. delay(1000) "freezes" the processor for 1000 ms — simple, but later we will learn a better way with millis().
Wiring
| From | To | Why |
|---|---|---|
| ESP32 · D2 (GPIO 2) | LED anode (+), column 20 | The pin gives 3.3 V (HIGH) or 0 V (LOW). The long leg of the LED is in column 20, so everything in that column (a–e) is joined to the pin. |
| LED cathode (−) | column 21 | Current leaves the LED through the short leg into column 21. |
| column 21 | Resistor 220 Ω → − rail | The resistor limits the current to (3.3 − 2)/220 ≈ 6 mA. Without it the LED and the pin suffer. |
| ESP32 · GND | − rail of the breadboard | Closes the loop: current returns into the ESP32. Without GND nothing works. |
Step by step
- Put the LED into columns 20 (long leg, anode) and 21 (short leg, cathode), row c.
- The 220 Ω resistor: one leg in 21a, the other in the − rail above it.
- Wire from D2 on the ESP32 to hole 20a.
- Wire from GND on the ESP32 to the − rail.
- Connect USB, select board "DOIT ESP32 DEVKIT V1" and the port in the Arduino IDE, upload the code.
- The LED blinks every second. Change the delay() values and see what happens.
Code (Arduino IDE)
// Project 1: Blinking LED
const int LED_PIN = 2; // D2 — also the built-in blue LED
void setup() {
pinMode(LED_PIN, OUTPUT); // the pin will SUPPLY voltage (output)
}
void loop() {
digitalWrite(LED_PIN, HIGH); // 3.3 V → LED on
delay(1000); // wait 1000 ms
digitalWrite(LED_PIN, LOW); // 0 V → LED off
delay(1000);
}Typical problems
LED not lighting? Flip it — reversed polarity is the most common mistake.
Upload stuck at "Connecting…"? Hold the BOOT button until it starts.
The built-in blue LED blinks too — that is because it is also on GPIO 2.
More projects (7 more) with a free sign-in in the course. Projects →