Your first LED: from circuit to light

Connect an LED and series resistor to GPIO25, program a blink, and connect code instructions with a working circuit.

Getting started with ESP32 and ArduinoBeginner60 min

What you will learn

  • Identify LED polarity and explain the purpose of a series resistor.
  • Assemble a breadboard circuit using GPIO labels and a schematic.
  • Use pinMode() and digitalWrite() to control a digital output.
  • Calculate a blink period and create a two-flash signal.

Before you start

Complete course 01: configure Arduino IDE and independently upload a sketch to a classic ESP32.

Reference setup

Board in Arduino IDE
ESP32 Dev Module
Arduino-ESP32
3.3.12
Serial Monitor
115200 baud

This is a reference profile, not an identification of the pictured board. Adapt the GPIO mapping and verify the circuit before using ESP32-C3/S2/S3 or a differently labelled board.

What you will build

Build an LED circuit that stays on for half a second and off for half a second. Connect a program instruction with the electrical state of an output pin.

This can become a connection indicator or warning signal. An external LED makes the activity independent of your board's built-in lights.

Learning objectives

  • Identify an LED's anode and cathode.
  • Connect a series resistor and explain its purpose.
  • Identify connected groups of holes on a breadboard.
  • Use pinMode() and digitalWrite() to control an output.
  • Calculate a blink period from its on and off times.

Prerequisites

Complete course 01 first. You should be able to select ESP32 Dev Module, upload a sketch, and open Serial Monitor. Allow about 60 minutes, including assembly and the independent challenge.

We use a classic ESP32/ESP32-WROOM-32 and GPIO25. The number identifies the GPIO function, not the twenty-fifth physical pin. ESP32-C3, S2, and S3 boards require a different wiring profile.

Equipment

ComponentQuantitySpecification and notes
Development board with a classic ESP32-WROOM-32 module1Match the reference GPIO labels; check physical header positions on the actual board.
USB data and power cable1Use the connector fitted to your board; the pictured kit lists Micro-USB.
Solderless breadboard1The kit lists 830 tie points. Check whether the power rails are split.
Red LED1Anode A and cathode K; identify polarity on the actual part.
220 Ω resistor1One current-limiting resistor per LED branch; use the kit’s 220 Ω resistors.
Jumper wires3Use male-to-male or female-to-male leads to suit the board headers.

Jumper count is approximate and depends on the physical arrangement.

Choose an ordinary red LED and a 220 Ω resistor. A standard four-band resistor uses red–red–brown for this value, followed by its tolerance band. If the markings are unclear, check with a meter or the component supplier's information.

How it works

An LED conducts current and emits light when correctly biased. Its leads are the anode, A, and cathode, K. On a typical new LED, the longer lead is the anode; the shorter lead and flat edge usually identify the cathode. If uncertain, check the component information. Arduino explains external LED wiring.

The resistor limits current. GPIO25, the resistor, and the LED form a single path to GND. The resistor must be part of that path; placing it in a nearby unconnected row achieves nothing. A resistor has no polarity.

On a typical breadboard, each group of five holes shares a metal contact. The centre channel separates the two groups. Side power rails may have a break halfway along their length, so check your breadboard's markings. For this activity, you can connect GND directly to the cathode's row and avoid the rails.

Connections

Wiring diagram

The drawing shows electrical connections by GPIO label, not the board’s physical header layout. Power the board through USB.

Wiring diagram — electrical connections listed in the table below
Wiring diagramEnlargeSVGPNG
Connections · Wiring diagram
FromToConnection
ESP32.GPIO25R1.1Control the LED branch.
R1.2D1.AConnect the 220 Ω resistor to the LED anode.
D1.KESP32.GNDConnect the cathode to common ground.
  1. Unplug USB. Locate the GPIO25/IO25/25 and GND labels on your board.
  2. Insert the LED with its leads in different, unconnected groups of holes.
  3. Connect one end of the 220 Ω resistor to the anode's group. Put its other end in an unused group.
  4. Run a jumper wire from GPIO25 to the resistor's free end.
  5. Connect the LED cathode to ESP32 GND.
  6. Trace the path: GPIO25, resistor, anode, LED, cathode, GND. Reconnect USB only after checking it.

USB powers the development board; the GPIO controls the LED using 3.3 V logic. The 5V pin is not used. Do not connect GPIO25 directly to GND or bypass the resistor.

Arduino setup

Download the Arduino example (.zip), extract it, and open first_led.ino inside the folder named first_led. Use Arduino IDE 2.x, “esp32 by Espressif Systems” version 3.3.12, and ESP32 Dev Module. Select your device's port. No additional libraries are required.

If ESP32 support is missing, return to course 01 or follow Espressif's installation instructions. Do not substitute an example for an unspecified built-in LED: this circuit requires GPIO25.

Program

Upload the original example first. The downloadable .ino is the same program shown here.

first_led.ino Arduino / C++
Download .ino

#include <Arduino.h>

constexpr uint8_t LED_PIN = 25;
constexpr uint32_t BLINK_INTERVAL_MS = 500;

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  Serial.println("WB Maker Bridge - LED blink on GPIO25");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(BLINK_INTERVAL_MS);
  digitalWrite(LED_PIN, LOW);
  delay(BLINK_INTERVAL_MS);
}

Code walkthrough

pinMode() configures GPIO25 as OUTPUT. digitalWrite() then requests HIGH or LOW. With this wiring, HIGH allows current through the LED and turns it on; LOW turns it off. Espressif's GPIO documentation defines these operations.

The loop turns the LED on, waits 500 milliseconds, turns it off, and waits another 500 milliseconds. The cycle totals approximately one second. BLINK_INTERVAL_MS controls both waits. For different durations in your copy, replace the first wait's argument with 200 and the second with 800.

Here, delay() introduces a simple way to separate events in time. The following lines of our sketch do not advance during that wait. When a device must also monitor buttons or several sensors, we will schedule activities with millis() instead.

Run and expected results

Run Verify, then Upload. Watch the external LED for at least ten seconds. It should switch on and off evenly. A power light on the ESP32 is not enough: observe the component you connected.

If you open Serial Monitor, select 115200 baud. The main result is the physical LED blinking. Compilation checks translation of the program; the working circuit provides evidence that the connections match your intentions.

Change one timing setting at a time and compare the result with your prediction.

Observation record

SettingPredict before uploadingExpected result
500 ms on, 500 ms offEqual durationsAbout one cycle per second
1000 ms on, 1000 ms offSlower blinkingAbout one cycle every two seconds
200 ms on, 800 ms offShort flash, longer pauseStill about one cycle per second

Troubleshooting

ProblemWhat to check
LED stays darkUnplug USB and check A/K, resistor, GND, and the GPIO25 label.
Both LED leads share one groupMove one lead to an unconnected group; breadboard contacts must not bridge the LED.
LED stays onConfirm the new sketch was uploaded and the wire comes from GPIO25 rather than 3V3.
Editing does not change the blinkSave and click Upload again; Verify alone does not change the board's program.
Upload failsRepeat the cable, board, and port checks from course 01.
A component becomes warmDisconnect USB immediately and check the resistor value and possible shorts.

Independent challenge

Create two short flashes followed by a longer pause. One cycle must contain 100 ms on, 100 ms off, 100 ms on, and 700 ms off. Write the sequence on paper, edit your copy of the sketch, and compare the observed result with your prediction.

Check your understanding

  1. Why does the LED need a series resistor?
  2. Why should you not count physical pins to find GPIO25?
  3. How long is a cycle with 200 ms on and 800 ms off?

Answer guidance

For the challenge, repeat the on/off instruction pair twice, with waits of 100, 100, 100, and 700 ms. Their total is 1000 ms. The recognizable pair of flashes therefore repeats approximately once per second.

Answers: the resistor limits current; header layouts vary between development boards; the specified cycle lasts one second. Restore the original blink for the next course and retain the GPIO25–resistor–LED–GND wiring. Unplug USB before adding the button.

Downloads

Primary references