NodeMCU LED Blink Tutorial

Author : Dinesh Kumar Wickramasinghe

Introduction

Hope you all read my Introduction to NodeMCU article and here we are going to execute your first NodeMCU project. Yes it is a simple LED blink.

NodeMCU LED Blink

Some of you may have already used the arduino IDE for Arduino Programming stuff. Fortunately we can use the Arduino for NodeMCU programming as well.

But you need to add some features to your arduino IDE to add the capability of NodeMCU Programming. Here I am explaining them step by step.


Setting up Arduino IDE for NodeMCU Programming
  1. Download and install the latest version of Arduino IDE of you have not done yet. If you have an old version, please uninstall it and install the latest version.
  2. Go to File > Preferences (Ctrl + ,)
    NodeMCU Arduino IDE Preferences Menu
  3. Copy this JSON url [ http://arduino.esp8266.com/stable/package_esp8266com_index.json ] and paste it on the test box Additional Boards Manager URLS.
    NodeMCU Arduino IDE Setup JSON URL
  4. Click OK to close the preferences window.
  5. Go to Tools > Board > Board Manager
    NodeMCU Arduino IDE Board Select Menu
  6. Search for ESP8266 and click on "ESP8266 by ESP community" and Install. This will take few minutes.
    NodeMCU Arduino IDE Board Install
  7. Once the installation done, restart the Arduino IDE.
  8. Go again to Tools > Board and Select "NodeMCU 1.0 ( ESP-12EModule)"
    NodeMCU Arduino IDE Board Select
  9. Now your Arduino IDE is ready to connect with NodeMCU.
  10. Now connect your NoceMCU Module via the Micro USB Cable. Please note that if your Windows operating system could not install the drivers for your NodeMCU board automatically, Here is the drivers download link : Download Drivers
  11. Make sure you select the correct port from the Tools > Port Menu
    NodeMCU Arduino IDE Port Select
    If you are not sure what the correct port number is, Go to windows device manager and check the list of COM ports, Please see the screenshot below.
    NodeMCU Port Select Device Manager

Note :

If you want to program again Arduino UNO, then go to Boards menu and select Arduino/Genuino Uno

If you are going to use the serial monitor with NodeMCU, make sure you change the data rate to 115200 (Arduino UNO uses 9600)

Source Code

Source code for this tutorial is available in the Examples section. Go to File > Examples > ESP8266 > Blink

NodeMCU blink example code

Here is the source code for you


/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 The blue LED on the ESP-01 module is connected to GPIO1 
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)
 
 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

    // 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)
    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 (to demonstrate the active low LED)
}
                        

Please note that the LED on when the voltage level is low and wise verse.

Click the upload button to compile and upload the code. Please note that the NodeMCU upload process takes more time than the Arduino UNO upload time. So be patient.

Once the code successfully uploaded, you will see the LED is blinking. Woooh! You have successfully done your first NodeMCU experiment.

If you face any difficulties or errors, please comment. I will try my best to solve them.

Comments Area
Add your questions and comments here. Comments will be published after the admin approval

 

Similar Projects

Go Top