🛠 Faire clignoter une LED avec l'ESP8266-ESP-12E
Objectives
Discover the ESP8266-ESP-12E board by making an LED blink. This first setup helps you understand the 3.3 V power supply requirement only (never 5 V on this board!), the role of the CH_PD pin (or the module's VCC) which must be connected to 3.3 V for the module to start, and the principle of the GPIO2 pin: it must remain high at startup, which is the case with an LED and its resistor connected to ground. The module has only one Xtensa core: the entire program runs sequentially.
Materials
- 1 ESP8266-ESP-12E module (or ESP-12E development board with 3.3 V regulator)
- 1 LED
- 1 resistor of 220 Ω to 330 Ω
- 1 stable 3.3 V power supply (capable of providing approximately 250 mA peak)
- Connecting wires, breadboard
Complete code
// Clignotement LED sur GPIO2 (broche D4 sur cartes NodeMCU)
const uint8_t LED_PIN = 2;
void setup {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // LED éteinte au repos
}
void loop {
digitalWrite(LED_PIN, HIGH); // LED allumée
delay(500);
digitalWrite(LED_PIN, LOW); // LED éteinte
delay(500);
}
Expected verification
The LED blinks once per second (500 ms on, 500 ms off). On most ESP-12E modules, the onboard LED is indeed on GPIO2: the setup therefore works even without an external LED. If the module does not start at all (silent serial port, no boot message), first check that CH_PD is properly connected to 3.3 V.
Common errors
- Powering the module with 5 V: the ESP8266 operates exclusively at 3.3 V, 5 V can destroy it.
- Forgetting to connect CH_PD to 3.3 V: the module remains off, no message on the console.
- Placing the LED on GPIO0 with a low resistance: GPIO0 must remain high at startup, otherwise the module enters flash mode and the program does not start.
- Forgetting the series resistor with the LED, which overloads the pin.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht11.inoArduinoluxmetre.inoArduinoserveur-web.inoArduino