The Blink LED program is the first step for anyone learning micro controllers. With the ESP8266 Wi-Fi micro controller, it’s even more exciting because you can later control LEDs through Wi-Fi and IoT platforms.
In this tutorial, we’ll blink an external LED using ESP8266 and Arduino IDE as in the previous tutorial we explained how to blink onboard LED and . You’ll also get a line-by-line code explanation to make everything crystal clear.
// Blink External LED on ESP8266
int ledPin = D2; // External LED connected to D2 (GPIO4)
void setup() {
pinMode(ledPin, OUTPUT); // Set D2 as output
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn LED ON
delay(500); // Wait 0.5 second
digitalWrite(ledPin, LOW); // Turn LED OFF
delay(500); // Wait 0.5 second
}
int ledPin = D2;
void setup()
pinMode(ledPin, OUTPUT);
→ sets D2 as an output pin.void loop()
digitalWrite(ledPin, HIGH);
→ sends 3.3V to D2, turning the LED ON.delay(500);
→ keeps it ON for 500 milliseconds (0.5 seconds).digitalWrite(ledPin, LOW);
→ turns the LED OFF.delay(500);
→ keeps it OFF for 0.5 seconds before repeating.🔆 The external LED will now blink twice per second.
Blinking an LED with ESP8266 is the Hello World of IoT projects. You learned:
Now that you know how to control LEDs, you’re ready to move on to sensors, relays, and full IoT automation projects. 🚀
The onboard LED is wired with inverted logic. LOW
turns it ON, HIGH
turns it OFF.
No, ESP8266 works on 3.3V logic. Use resistors to protect LEDs.
Safe GPIOs for LEDs: D1, D2, D5, D6, D7 (avoid using D3, D4, D8 for critical tasks).