Article & guide
Read the full article
# ESP32: Your First LED Project A little code. One blinking light. Your first step towards useful electronics. In this project, you will build a simple LED circuit and control it from an ESP32. You will practise reading board pin labels, placing components on a breadboard and uploading a program. ## What you will build An external LED that turns on and off repeatedly. You can then change the timing to create your own signal pattern. ## Components - One classic ESP32 development board based on ESP32-WROOM-32, with GPIO23 exposed - One standard red LED - One 330-ohm resistor - Breadboard and jumper wires - USB data cable and a computer with Arduino IDE and the Espressif ESP32 board package This guide uses GPIO23 on a classic ESP32. Other ESP32 variants may not have that pin; check your exact board pinout before following the wiring. Use an external LED rather than assuming the board has an onboard LED on a particular pin. ## Before you start Unplug USB while changing wires. Keep the resistor in series with the LED. This is a low-voltage USB-powered project; no mains connections are needed. ## Learning checklist By the end, you should be able to identify GPIO and ground, connect an LED with a current-limiting resistor, upload a sketch and adjust its timing. ## References Espressif GPIO documentation: https://docs.espressif.com/projects/arduino-esp32/en/latest/api/gpio.html Espressif Arduino-ESP32 documentation: https://docs.espressif.com/projects/arduino-esp32/en/latest/ Draft teaching example for LearnWithRich. The circuit and sketch have not been physically tested as part of preparing this guide.
1. 1. Wire your LED
With USB disconnected, connect the pin labelled 23 or GPIO23 to one end of the 330-ohm resistor. Connect the other end to the LED anode (usually the longer leg). Connect the LED cathode (usually the shorter leg, on the flat side of the package) to GND. Put the two LED legs in separate breadboard rows so they are not shorted together. Check the board labels: GPIO23 means the labelled signal, not the 23rd physical header pin.
2. 2. Prepare your board
Connect the ESP32 with a USB data cable. In Arduino IDE, select the board entry that matches your development board and choose its serial port. If ESP32 boards are missing, follow the installation guide in Espressif's Arduino-ESP32 documentation. Open a new sketch.
3. 3. Upload the code
Paste this sketch, verify it and upload it: ```cpp const int ledPin = 23; const unsigned long blinkDelayMs = 1000; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); } void loop() { digitalWrite(ledPin, HIGH); delay(blinkDelayMs); digitalWrite(ledPin, LOW); delay(blinkDelayMs); } ``` Expected result: the LED stays on for one second, then off for one second, repeatedly.
4. 4. Understand and experiment
pinMode configures the selected pin as an output. digitalWrite changes its digital level. delay pauses the sketch for a duration in milliseconds. Try changing blinkDelayMs from 1000 to 250, then upload again. The LED should blink faster. Challenge: give the HIGH and LOW states different delays to make a short flash followed by a longer pause. This simple blocking timing is useful for a first experiment; more complex projects can use millis() so other tasks keep running.
5. 5. Troubleshoot and finish
No light? Disconnect USB, check LED polarity, resistor connections, breadboard rows and the GND wire. Confirm that your wire is connected to GPIO23. No serial port? Try a known data-capable USB cable and the USB driver recommended by your board manufacturer. Upload fails? Confirm the board and port selections, then follow your board's documented boot/upload procedure. Keep the resistor fitted when experimenting. When your circuit works, take a photo and note the timing values you used.