💡 Controlling an External LED with ESP32 and Arduino IDE
Mohamed Ahmed

Mohamed Ahmed @mohamed_ahmed_dev

About: Full-Stack Developer on a continuous learning journey. Exploring UI/UX with React, backends with Node.js, and diving into hardware with ESP32. Sharing insights and progress let’s learn together!

Location:
Nairobi, Kenya
Joined:
Sep 29, 2025

💡 Controlling an External LED with ESP32 and Arduino IDE

Publish Date: Oct 10
0 0

Introduction

Welcome back, makers! 👋
In the previous post we successfully uploaded our first program — the classic “Blink” — to make the built-in LED on the ESP32 blink.

Now, we’ll take it a step further by connecting and controlling an external LED.
This is your first step into hardware interaction — where your ESP32 begins to control real-world devices!

🧰 What You’ll Need

  1. - ESP32 development board (e.g., ESP32 DevKit C)
  2. - 1 × LED (any color)
  3. - 1 × 220 Ω resistor
  4. - Breadboard
  5. - Jumper wires
  6. - USB cable connected to your computer

⚙️ Step 1: Breadboard/circuit Connections

Component ESP32 pin Description
LED (long leg – anode) GPIO 4 Digital output pin
LED (short leg – cathode) GND Ground
Resistor (220 Ω) In series with LED Limits current to protect LED

You can use GPIO 5, 13, or 14 — just make sure to update the code accordingly.

💡 Tip: You can use GPIO 5, 13, or 14 instead — just update the code accordingly.
Always use a resistor in series with your LED to prevent burning it out!

💻 Step 2: Write the Code

In the Arduino IDE, open a new sketch and paste this:

// Control an external LED using ESP32
int ledPin = 4; // The GPIO pin connected to the LED

void setup() {
  pinMode(ledPin, OUTPUT); // Set the LED pin as output
  Serial.begin(115200);      // Start the Serial Monitor
  Serial.println("External LED Test Started");
}

void loop() {
  digitalWrite(ledPin, HIGH); // Turn LED on
  Serial.println("LED is ON");
  delay(1000);                // Wait 1 second

  digitalWrite(ledPin, LOW);  // Turn LED off
  Serial.println("LED is OFF");
  delay(1000);                // Wait 1 second
}

Enter fullscreen mode Exit fullscreen mode

🧠 Explanation:

  • pinMode(ledPin, OUTPUT) tells the ESP32 that GPIO 4 will send signals.
  • digitalWrite(ledPin, HIGH/LOW) turns the LED on and off.
  • The Serial Monitor prints real-time messages so you can see what the board is doing.

🖥️ Step 3: Upload and Monitor

  1. Connect your ESP32 to your computer.
  2. Select the correct board and port (as before).
  3. Click Upload.
  4. After uploading, open Tools → Serial Monitor.
  5. Set the baud rate to 115200. You should see messages like:

Your IDE should look like this
Your external LED should blink in sync! ✨
_
💡 Tip: On some boards, you may need to hold the BOOT button while uploading the code._

Your IDE should look like this

⚡ Troubleshooting

1.LED not lighting up?

  • Check your wiring (make sure anode and cathode aren’t reversed).
  • Try a different GPIO pin and update the code.
  • Verify that your resistor is not too large (220 Ω–330 Ω works best).

2.No Serial Output?

  • Ensure you opened the Serial Monitor at 115200 baud.
  • Make sure the code includes Serial.begin(115200);.

🎯 What’s Next
✅ You’ve now controlled an external LED with your ESP32!
In the next post, we’ll add a button so you can turn the LED on and off manually. 🕹️

Get ready to make your first interactive circuit!

💬 Your Turn!

Did your external LED blink? 🔴💡
Share your success (or any issues you faced) in the comments — I’d love to see your first working circuit!

Comments 0 total

    Add comment