- 22 -
Blink + PWM + Serial sketch examples
Blink sketch example
There is a blink sketch example that comes with the ESP8266 board library. To
open it, go to: Files > Examples > ESP8266 > Blink
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN
}
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on
// Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active LOW on the ESP
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off
// by making the voltage HIGH
delay(2000); // Wait for two seconds
}
For the D1 Mini module, LED_BUILTIN is equal to a number 2, which means that
on-board LED is connected to the GPIO2 pin. To turn ON the LED the GPIO2
pin has to be put in the LOW state, and to turn it OFF the GPIO2 pin has to be
put in the HIGH state.