BeginnerInteractive Control

Blinking LED

Your first GPIO output. Make an LED blink on a schedule.

Time
30 min
Estimated cost
~£12
Hardware
ESP32-DevKitC V4 (38-pin)

Example code — not yet validated

Try it in the browser

What you will build

An LED on a breadboard that switches on and off at a steady rhythm. You will change one number and watch the rhythm change. This is the "hello world" of electronics: if it blinks, your board, cable, drivers and upload tool all work.

How it works

The sketch sets GPIO 26 as an output. In loop() it drives the pin HIGH (3.3 V, LED on), waits, drives it LOW (0 V, LED off), waits, and repeats forever. The resistor limits the current so the LED and the pin are not damaged.

Parts

Part Qty Purpose Required
ESP32-DevKitC V4 (38-pin) 1 Runs your program Yes
5 mm LED (any colour) 1 The light Yes
220 Ω resistor 1 Limits current Yes
Breadboard + 2 jumper wires 1 set Connections Yes
USB data cable 1 Power and upload Yes

Build steps

  1. Push the ESP32 into the breadboard so it straddles the centre gap.
  2. Insert the LED. The long leg (anode) goes towards GPIO 26, the short leg (cathode) towards GND.
  3. Connect GPIO 26 → 220 Ω resistor → LED long leg.
  4. Connect the LED short leg → GND.
  5. Plug in the USB cable. In Arduino IDE 2 choose Tools → Board → ESP32 Dev Module and the correct port.
  6. Paste the code below and click Upload. Checkpoint: the LED blinks once per second.
  7. Change BLINK_MS to 200, upload again, and watch it blink faster.

Try it in the browser

Playground Simulation. Open the sketch in the Playground: the virtual LED on the breadboard follows the same code. Edit BLINK_MS and press Run. The simulation shows logic levels, not real voltage or current.

Open Simulator Playground

Code

Download blinking-led.ino

// Blinking LED — XBOTNOW
// Board: ESP32-DevKitC V4 · Core: esp32 v3.x
const int LED_PIN = 26;      // GPIO connected to the resistor
const int BLINK_MS = 1000;   // time on and time off, in milliseconds

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // LED on
  delay(BLINK_MS);
  digitalWrite(LED_PIN, LOW);   // LED off
  delay(BLINK_MS);
}

Troubleshooting

Symptom Likely cause Check
No port in Arduino IDE Charge-only cable or missing USB driver Try another cable; install the CP210x or CH340 driver for your board
Upload stuck at "Connecting…" Board not in boot mode Hold BOOT, click Upload, release when writing starts
Uploads but LED stays dark LED reversed or wrong pin Flip the LED; confirm the wire is on GPIO 26
LED very dim Resistor too large Use 220–330 Ω

Safety and limitations

Always use the resistor. GPIO pins supply a few milliamps of logic current. They cannot power motors, LED strips or anything over 3.3 V.

Checklist

Next project

Button-controlled Light: make the LED react to you instead of a timer.

Next project: Button-controlled Light