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.
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
-
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.
- Go to File > Preferences (Ctrl + ,)
- Copy this JSON url [ http://arduino.esp8266.com/stable/package_esp8266com_index.json ] and paste it on the test box Additional Boards Manager URLS.
- Click OK to close the preferences window.
- Go to Tools > Board > Board Manager
- Search for ESP8266 and click on "ESP8266 by ESP community" and Install. This will take few minutes.
- Once the installation done, restart the Arduino IDE.
- Go again to Tools > Board and Select "NodeMCU 1.0 ( ESP-12EModule)"
- Now your Arduino IDE is ready to connect with NodeMCU.
- 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
- Make sure you select the correct port from the Tools > Port Menu
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.
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
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.