Chat freely about anything...

User avatar
By Halfshellher0
#48557 Hello guys,

I'm new to ESP, trying to run the blink example. It seems to flash OK and I can receive the Serial prints back on the serial monitor, I don't have any LEDs lying around to truly test this, but it doesn't appear like GPIO2 is changing voltage at all.

Here's the code I'm running:
Code: Select all#include <ESP8266WiFi.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  Serial.begin(115200);
  delay(10);
}

// the loop function runs over and over again forever
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 acive low on the ESP-01)
  Serial.print("Light is on.");     
  Serial.println();
 
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  Serial.print("Light is off.");     
  Serial.println();
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}


Does anyone know why that might be happening?
User avatar
By krzychb
#48571 Hello @Halfshellher0,

Specific GPIO pin number hidden under LED_BUILTIN depends on what board you select in your IDE.

For instance, for "Generic" broad LED_BUILTIN maps to GPIO1 as defined here.

If you like to blink specifically GPIO2, and not sure what is behind LED_BUILTIN, just replace in your sketch all occurrences of LED_BUILTIN with number 2 and load it again to your ESP module.

Krzysztof