NodeMCU Onboard LED Access Via Web Server

Introduction: NodeMCU Onboard LED Access Via Web Server

About: The eternal noob DIYer is something I would call myself. Understanding everything in the most layman terms and trying to explain the same to others is my job.

The ESP8266 is THE device in the DIY market. It has brought a nice big storm in the Hobbyist community. Coupled with GPIOs , an ADC , SPI interface, UART interface (and of course the WiFi part) has all the features required to make a full blown standalone application without any extra piece of hardware .

Step 1: Some Basics on Programming the THING

Programming this brilliant THING is generally done by

  • Arduino IDE (C++ implementation)
  • ESPlorer IDE (LUA programming language)

This tutorial is about controlling the LED present on the ESP Development board using the ESPlorer IDE.

Step 2: Setting Up the Firmware and Tools

For the NodeMCU to understand our LUA program , a firmware needs to be flashed on it first before uploading the actual LUA code. So the following steps need to be followed.

  1. Download the binary files (firmware needed onboard the esp12e) from here
  2. You will need some tool to flash the binary (firmware). You could either use esptool or nodemcu-flasher (only windows).For the esptool , unzip it, run "python install" inside extracted folder,and finally

    "sudo python --port /dev/ttyUSB0 write_flash 0x00000 your_downloaded_binary_in_first_step"

  3. The "/dev/ttyUSB0" is the port on which the device is connected. Check here and here for more info on esptool. For the nodemcu-flasher follow the instructions on wiki

  4. Download the ESPlorer IDE for flashing our LUA program here (Hit download button on the page).

Note - Make sure NodeMCU is connected to the PC by checking inside device manager (for windows,you will find your device under Ports as "Silabs CP201x...." )

Step 3: Programming the NodeMCU

Well most of it is done.All you need is the LUA code to turn your ESP12E into a web AP as well as Web server. Here you will find the code. Just copy the code in the left Window of your ESPlorer IDE and save as "init.lua" (this is the first script that runs on the NodeMCU after reset).The ESPlorer automatically saves the code on your NodeMCU code memory.

Once all is done , search for WiFi networks on your device (phone or PC). You will find something like this "ESP8266_" .

  • Connect to this WiFi network with password as "12345678" (without quotes).
  • Fire up a web browser and write the following in the URL bar "".
  • You will find "on","off" and "blink" button . you go.

Step 4: A Look Into the Code

You can get a better understanding at NodeMCU-docs and here.

The code flow is as follows

  • The init.lua code first configures the ESP modules into a WiFi access point.
cfg.ssid = "ESP8266_"..ssidTemp
...more code upto...
  • GPIO button 0 is configured as OUTPUT

  • A Server is created and the status of the buttons on the HTML page are checked each time the status of either changes
..more code upto...

So that is a basic html page to control on board LED using LUA code. Happy Hacking!!

Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020