◆Smart Home Ideas Journal

ESP32 LED Blink: Simple & Easy Example

By

Wondering how to make your ESP32 module blink an LED? You're at the right place! This guide walks you through a simple yet effective ESP32 LED blink example, perfect for beginners looking to get started with this powerful microcontroller. Let's dive in!

Before we begin, ensure you have the following: an ESP32 development board, an LED, and some jumper wires. Don't forget to install the ESP32 board package in your Arduino IDE, if you haven't already.

ESP32 LED Blink Circuit Setup

First, let's set up the circuit. Connect the positive leg (anode) of your LED to one of the ESP32's GPIO pins, say GPIO2. Then, connect the negative leg (cathode) to a ground pin (GND).

ESP32 GPIO with ESP-IDF with LED Blinking example
ESP32 GPIO with ESP-IDF with LED Blinking example
ESP32 and ESP8266 GPIO Programming with MicroPython - LED Blinking
ESP32 and ESP8266 GPIO Programming with MicroPython - LED Blinking
ESP32 - Blink multiple LED | ESP32 Tutorial
ESP32 - Blink multiple LED | ESP32 Tutorial

Resistors aren't necessary for this simple setup, but using one between the LED and GPIO pin can protect your ESP32 from voltage spikes.

Understanding LED Polarity

LEDs have two legs: the longer one is positive (anode), and the shorter one is negative (cathode). Be sure to connect them correctly to make the LED light up.

How to Blink An LED Bulb Using ESP32 Board
How to Blink An LED Bulb Using ESP32 Board
ESP-IDF: ESP32 Blink LED Example (VS Code) | Random Nerd Tutorials
ESP-IDF: ESP32 Blink LED Example (VS Code) | Random Nerd Tutorials
How to Use ESP32 to Control LED With Blynk Via WiFi
How to Use ESP32 to Control LED With Blynk Via WiFi

Choosing the right ESP32 pin

ESP32 has multiple GPIO pins you can use. For this example, we'll use GPIO2. You can experiment with different pins, but keep in mind that some pins have special functions or are used for specific purposes.

ESP32 LED Blink Example Code

Now, let's write the code to make the LED blink. Open the Arduino IDE and create a new sketch.

Here's a simple ESP32 LED blink example. Copy and paste this code into your sketch:

ESP32 Simulator - Arduino Core - LED Blink Example - How to use ESP32 Wokwi Simulator
ESP32 Simulator - Arduino Core - LED Blink Example - How to use ESP32 Wokwi Simulator
10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
ESP32 LED Blink in Proteus8 Simulation - Complete Beginner Guide
ESP32 LED Blink in Proteus8 Simulation - Complete Beginner Guide
ESP32 CYD with LVGL: Display Image on the Screen | Random Nerd Tutorials
ESP32 CYD with LVGL: Display Image on the Screen | Random Nerd Tutorials
ESP32 LED Blink Simulation Project for Students
ESP32 LED Blink Simulation Project for Students
ESP32 RGB LED Controller Web Server - Remote Color Picker
ESP32 RGB LED Controller Web Server - Remote Color Picker
```cpp #define LED_PIN 2 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); } ```

Setting up the LED pin

The code defines the LED pin (GPIO2) using the `#define` directive, making it easier to change if needed. In the `setup()` function, we set the pin mode to `OUTPUT`.

The blink loop

In the `loop()` function, we toggle the LED on and off with a 1-second (1000 ms) delay. Adjust the delay values to change the blinking speed.

Upload the sketch to your ESP32 board, and watch your LED blink on and off! This simple example serves as a foundation for more complex ESP32 and LED projects. Happy innovating!

💡 ESP32 LED Control Web Server – Toggle LEDs from Your Browser!
💡 ESP32 LED Control Web Server – Toggle LEDs from Your Browser!
ESP32 GPIO Pins Programming in Arduino IDE - LED Blinking Example
ESP32 GPIO Pins Programming in Arduino IDE - LED Blinking Example
WLED ON XIAO ESP32
WLED ON XIAO ESP32
Introduction to ESP32 Simulation: LED Blink in Proteus 8
Introduction to ESP32 Simulation: LED Blink in Proteus 8
ESP32 LED Blink Proteus Simulation - Free Files Included
ESP32 LED Blink Proteus Simulation - Free Files Included
ESP32 PWM with Arduino IDE (Analog Output) | Random Nerd Tutorials
ESP32 PWM with Arduino IDE (Analog Output) | Random Nerd Tutorials
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
5 Must-Try ESP32 Projects for Beginners (2025 Edition)
5 Must-Try ESP32 Projects for Beginners (2025 Edition)
Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial
Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial
How to send SMS using ESP32
How to send SMS using ESP32
ESP32 - LED Matrix | ESP32 Tutorial
ESP32 - LED Matrix | ESP32 Tutorial
Anatomy esp32
Anatomy esp32
ESP32 Explained: The Powerful IoT Board
ESP32 Explained: The Powerful IoT Board
Arduino Nano ESP32 How to Blink an LED Using Visuino Visual Programming
Arduino Nano ESP32 How to Blink an LED Using Visuino Visual Programming