Utility Bar

ESP32 LED Blink Tutorial for Beginners

ESP32 LED Blink Tutorial for Beginners

Ethan Zaitchik |

Table of Contents

    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

    LED polarity

    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.

    LED with 220 ohm 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

    1. Place the LED into the breadboard so each leg is in a different row
    2. Connect one end of the 220Ω resistor to GPIO 5 on the ESP32. It will commonly be labelled D5.
    3. Connect the other end of the resistor to the long leg of the LED
    4. Connect the short leg of the LED to a GND pin on the ESP32

    Double check all connections before continuing.

    ESP32 LED Blink wiring diagram

    Step 4 - Open the Arduino IDE

    1. Open the Arduino IDE
    2. Confirm the correct ESP32 board is selected under the Tools menu
    3. 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

    Lesson complete / Next lesson

    You have successfully controlled a physical output using your ESP32.

    Next lesson: ESP32 Passive Buzzer Tutorial

    Leave a comment

    Please note: comments must be approved before they are published.

    // Table of contents