This ESP32 LED blink tutorial is designed for beginners who are getting started with ESP32 development. In this lesson, you’ll learn how to connect an LED to an ESP32, choose a GPIO pin, and write your first program using the Arduino IDE.
This lesson is part of our ESP32 tutorials series, where we walk through ESP32 projects step by step for beginners.
What you will need
Step 1 - Understand the LED and resistor

An LED or Light Emitting Diode allows current to flow in one direction only. The longer leg is the positive side and the shorter leg is the negative side.
A resistor is required to limit the current flowing through the LED. Without a resistor the LED may be damaged.
A 220Ω resistor is suitable for most standard LEDs used with ESP32 boards.
We’ll be connecting the positive side of the LED to the resistor.

Step 2 - Choose a GPIO pin
The ESP32 has many GPIO pins that can be used as outputs. In this lesson you will use GPIO 5.
GPIO pins can be changed in software later if needed.
Step 3 - Wire the LED
- Place the LED into the breadboard so each leg is in a different row
- Connect one end of the 220Ω resistor to GPIO 5 on the ESP32. It will commonly be labelled D5.
- Connect the other end of the resistor to the long leg of the LED
- Connect the short leg of the LED to a GND pin on the ESP32
Double check all connections before continuing.

Step 4 - Open the Arduino IDE
- Open the Arduino IDE
- Confirm the correct ESP32 board is selected under the Tools menu
- Confirm the correct port is selected
If you are unsure review Lesson 1.
Step 5 - Upload the LED blink sketch
Copy and upload the following code.
const int ledPin = 5; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); }
Click Upload and wait for the upload to complete.
How the Code Works
This simple program, often called the "Blink" sketch, is the "Hello World" of microcontroller programming. It shows you the two most important functions that exist in every Arduino/ESP32 program: setup() and loop().
Explanation:
const int ledPin = 5;Creates a constant number that stores which GPIO pin we’re using (pin 5). Using a constant makes the code easier to read and change later.
void setup() { ... }This function runs once when the ESP32 starts or resets.
pinMode(ledPin, OUTPUT);Tells the ESP32 that GPIO 5 should be an output (we want to control it).
void loop() { ... }This function runs forever, over and over again.
- digitalWrite(ledPin, HIGH); → Turns the pin on (3.3V) → LED lights up
- delay(1000); → Wait 1 second (1000 milliseconds) while LED is on
- digitalWrite(ledPin, LOW); → Turns the pin off (0V) → LED turns off
- delay(1000); → Wait 1 second while LED is off
The cycle repeats endlessly, creating the classic blinking effect!
Quick fact: The ESP32 uses 3.3V logic when a pin is HIGH (not 5V like some older Arduino boards).
With just these few lines of code, you have made something physical happen in the real world, congratulations on your first hardware program!
Step 6 - Observe the LED
Once the upload finishes the LED should turn on for one second and off for one second repeatedly.
- If the LED does not light up
- Check the LED orientation
- Check the resistor connection
- Confirm the correct GPIO pin is used
- Try pressing the reset button on the ESP32
ESP32 LED Blink FAQ
Which GPIO pins can I use to blink an LED on ESP32?
Most GPIO pins can be used as outputs, but GPIO 5 is a safe and commonly used option for beginners.
Why do I need a resistor with an LED?
A resistor limits current to prevent the LED from being damaged. A 220Ω resistor is suitable for most ESP32 LED projects.
Is ESP32 3.3V or 5V?
ESP32 GPIO pins operate at 3.3V logic, not 5V.
ESP32 Lessons
- ESP32 Tutorials Hub
- Lesson 1: ESP32 Setup using Arduino IDE
- Lesson 2: ESP32 Libraries and Using the Serial Monitor
- Lesson 3: LED Blink
- Lesson 4: ESP32 Using a Passive Buzzer Tutorial
Lesson complete / Next lesson
You have successfully controlled a physical output using your ESP32.
Next lesson: ESP32 Passive Buzzer Tutorial