By EEDIY Team. Difficulty ★ · About 30-45 minutes
Making an LED blink is the “hello world” of electronics. Once it works, you know your computer, cable, board and code are all working together.
What you need
- 1 ESP32 development board (any common one)
- 1 USB cable that carries data (some cables only charge)
- 1 solderless breadboard
- 1 LED and 1 resistor (from a starter kit’s LED section)
- 2 jumper wires
- A computer (Windows, macOS or Linux)
Words to know
- GPIO: a general-purpose pin your code can switch on and off.
- Sketch: an Arduino program.
- Upload: sending the sketch from your computer to the board.
Step 1: Install the Arduino IDE
Download it from arduino.cc/en/software and install it like any other program.
Step 2: Add ESP32 support
- Open Preferences and paste Espressif’s board-manager URL into “Additional boards manager URLs”: https://espressif.github.io/arduino-esp32/package_esp32_index.json
- Open Boards Manager, search for esp32 and install the package by Espressif Systems.
Step 3: Wire the LED
An LED needs a
series resistor to keep the current below the maximum forward current in the LED’s datasheet. For example, one common red LED datasheet lists 30 mA.
Which resistor? 220–330 Ω is a typical choice. To work it out: R = (3.3 V − Vf) ÷ current, where Vf is the LED’s forward voltage from its datasheet. Example: the Kingbright WP7113ID has a typical Vf of 1.9 V at 10 mA, so (3.3 − 1.9) ÷ 0.010 = 140 Ω minimum. A 220 Ω resistor gives about 6 mA, which is still visible and safely below the limit.
- Connect a GPIO pin to one end of the resistor.
- Connect the other end of the resistor to the LED’s positive leg (anode).
- Connect the LED’s other leg (cathode) to a GND pin.
Not sure which leg is the anode? On the Kingbright WP7113ID drawing, the cathode (−) is the lead on the flat edge of the rim, and the anode (+) is the longer lead. Many 5 mm LEDs follow this, but check your LED’s datasheet.
Check your board’s pinout to pick a normal GPIO pin, and write down its number. Avoid
strapping pins (pins the chip reads at startup to decide how to boot): GPIO 0, 2, 5, 12 and 15 on the classic ESP32, and GPIO 4, 5, 8, 9 and 15 on the ESP32-C6. The example uses GPIO 18, which is not a strapping pin on either chip.
Step 4: Select your board and port
Plug in the board. In
Tools, choose the board that matches the chip on yours:
ESP32 Dev Module for a classic ESP32,
ESP32C6 Dev Module for an ESP32-C6, or your exact model if it’s listed. Then choose the port that appeared.
Step 5: Upload the sketch
const int LED_PIN = 18; // change to the GPIO you used
void setup() {
pinMode(LED_PIN, OUTPUT); // make the pin an output
}
void loop() {
digitalWrite(LED_PIN, HIGH); // LED on
delay(500); // wait half a second
digitalWrite(LED_PIN, LOW); // LED off
delay(500);
}
Click
Upload.
Expected result
The upload reaches 100%, the board restarts, and the LED turns on for half a second, then off for half a second (one blink per second).
Common mistakes
| Problem |
Fix |
| No port appears |
Tip: try a different USB cable (some cables only charge) or a different USB socket |
| Upload fails to connect |
Hold BOOT, press reset (or replug), release BOOT, then upload again |
| Uploads but LED stays dark |
The LED is in backwards (flip it; at 3.3 V that’s within the 5 V reverse-voltage rating in the example datasheet, so it’s usually not damaged), or the pin number in the code doesn’t match the wire |
| Wrong board selected |
Pick your exact board model in Tools |
Next step
Change both delay(500) values to delay(100) and upload again. You just wrote your first change!
Questions? The forum (ESP32 & MCUs) is coming soon.
Sources
- Arduino IDE download: https://www.arduino.cc/en/software
- Espressif, Arduino-ESP32 installing guide (board URL, Boards Manager): https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html
- Espressif, Arduino-ESP32 GPIO API (pinMode, digitalWrite): https://docs.espressif.com/projects/arduino-esp32/en/latest/api/gpio.html
- Espressif, ESP32 datasheet Table 3-1 (strapping pins): https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
- Espressif, ESP32-C6 datasheet Table 3-1 (strapping pins): https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf
- Espressif, Boot mode selection: https://docs.espressif.com/projects/esptool/en/latest/esp32c6/advanced-topics/boot-mode-selection.html
- Espressif Arduino-ESP32 boards list (ESP32 Dev Module, ESP32C6 Dev Module): https://github.com/espressif/arduino-esp32/blob/master/boards.txt
- Kingbright, WP7113ID LED datasheet (package drawing, Vf, 5 V reverse voltage) (example max DC forward current, 30 mA): https://www.kingbrightusa.com/images/catalog/SPEC/WP7113ID.pdf