Blink an LED using an ESP32

Before we dive into the ESP32 tutorial series, let’s explore some of its key features:

  1. Dual-core Processor: The ESP32 has a dual-core processor, allowing it to handle multiple tasks simultaneously, improving performance in complex projects.
  2. Wi-Fi and Bluetooth Integration: It supports both Wi-Fi (802.11 b/g/n) and Bluetooth (Classic and BLE), making it ideal for IoT (Internet of Things) applications and wireless communication.
  3. Low Power Consumption: ESP32 has various power-saving modes, making it energy-efficient for battery-powered applications.
  4. High Performance: With clock speeds up to 240 MHz and 512 KB of RAM, it can handle demanding applications like real-time processing or machine learning.
  5. Rich Peripheral Support: It offers a wide range of interfaces, including UART, SPI, I2C, ADC, DAC, PWM, and more, providing flexibility for various sensor and actuator connections.
  6. Cost-Effective: The ESP32 is relatively inexpensive compared to other microcontrollers with similar capabilities, making it an affordable choice for prototyping.
  7. Large Community and Documentation: The ESP32 has a large developer community and extensive documentation, making it easy to find resources and troubleshoot issues.
  8. Advanced Security Features: It includes hardware-based encryption, secure boot, and flash encryption, which help protect data and ensure secure communication in applications.

These features make the ESP32 an excellent choice for embedded systems, IoT devices, robotics, and more.


To blink an LED using an ESP32, here’s a simple guide along with the wiring connection and code.

Wiring Connections:

  1. LED (Anode)GPIO Pin (e.g., GPIO 2)
  2. LED (Cathode)GND
  3. Resistor (220Ω)LED Cathode

Here’s how you can make an LED blink using the ESP32 in the Arduino IDE:

  1. Set up the Arduino IDE for ESP32 (if you haven’t already):
    • Go to File > Preferences.
    • In the Additional Boards Manager URLs field, add this URL: arduinoCopyhttps://dl.espressif.com/dl/package_esp32_index.json
    • Then go to Tools > Board > Boards Manager, search for ESP32 and click Install.

Code:

#define LED_PIN 2  // Pin where LED is connected

void setup() {
  pinMode(LED_PIN, OUTPUT);  // Set LED pin as output
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // Turn LED on
  delay(1000);                  // Wait for 1 second
  digitalWrite(LED_PIN, LOW);   // Turn LED off
  delay(1000);                  // Wait for 1 second
}

Steps:

  1. Connect the LED to GPIO 2 (or another pin of your choice).
  2. Use a 220Ω resistor in series with the LED to limit current.
  3. Upload the code to the ESP32 using the Arduino IDE.
  4. Once uploaded, the LED will blink on and off every second.

This simple setup will make the LED blink repeatedly.