Jul 20

Blink the internal LED - ESP8266

Category: Design,electronics   — Published by goeszen on July 20, 2017 at 2:23 pm

Just a note: The internal / soldered-on blue LED on most NodeMCU boards is on Pin1, it's on pin 2 on some, and on mine, it is addressable via Pin 4.

That means, writing in lua:

gpio.write(4, gpio.LOW)

will turn it ON.

Pin 1, pin 2, pin 4? There's a bit of a confusion, also because some cheap boards have non-canonical wiring. My impression is that everyone referring to the LED being on pin 1 or 2 are actually talking about the LED being on GPIO pin 1 or 2. And a look at the pinout schematic explains why we here are using Pin4 - because the NodeMCU dev board has GPIO pin 2 broken out as pin "D4".

The other thing: LOW is on?? Well yes, because:

the LED is active low (connected to Vcc and sinks through the chip to ground) so setting a logical value of 0 will light it up

...thank you, community wiki.

Try it yourself, upload this script as init.lua (via, via, similar):

-- Config
local pin = 4            --> GPIO2
local value = gpio.HIGH
local duration = 100    --> 1 second

-- Function toggles LED state
function toggleLED ()
   if value == gpio.LOW
        value = gpio.HIGH
       value = gpio.LOW

    gpio.write(pin, value)

-- Initialise the pin
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, value)

-- Create an interval
tmr.alarm(0, duration, 1, toggleLED)

From here:
If you'd like to expand on this, try the Toggle LED on/off by pressing a button experiment in a follow-up post.


This post is part of a series: check out the next post: Recover from PANIC - ESP8266

I'm tinkering here with a NodeMCU ESP8266 board.
I'm using the ESP8266 Java IDE ESPlorer.
The firmware is version 0.9.6 build 20150704 powered by Lua 5.1.4

Leave a Reply