In this tutorial, We are going to learn how to use Arduino IDE to program NodeMCU.
What is NodeMCU?
NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module. The term “NodeMCU” by default refers to the firmware rather than the development kits. The firmware uses the Lua scripting language. Wikipedia
Operating system:XTOS Yes, by default NodeMCU uses Lua scripting language to program NodeMCU, here We are going to learn how to program NodeMCU using Arduino C++ language.
-- Pin definition
local pin = 7 -- GPIO 13
local status = gpio.LOW
local duration = 1000 -- 1 second duration for timer
-- Initialising pin
-- Create an interval
tmr.alarm(0, duration, 1, function ()
if status == gpio.LOW then
status = gpio.HIGH
status = gpio.LOW
The above is a sample Lua script to blink an LED connected to the 7th pin ie GPIO 13 of NodeMCU.As you can see here the physical pin and the GPIO pin numbers are different in NodeMCU, below is a chart of the pin assignments,
NodeMCU V 1.0 Pinout
NodeMCU v0.9 Pinout
Coding in Arduino IDE
Note: When you use the NodeMCU with the Arduino IDE, it will write directly to the firmware, of NodeMCU erasing the original firmware, So if you want back the Lua SDK, use the “flasher” to re-install the firmware. You can download the flasher from their Github page https://github.com/nodemcu/nodemcu-flasher.
Step 1: Connect the NodeMCU with your PC or laptop with a micro USB cable.
Step 3: Open Your Arduino IDE, then open preference from the file menu, then copy this link http://arduino.esp8266.com/stable/package_esp8266com_index.json to additional board manager URLs, as shown below in the screenshot, then click ok.
Step 4: Installing Board, Open board manager from tools -> board -> board manager.
and search from “nodemcu”
Then select the latest version from the dropdown menu and click install and restart the Arduino IDE.
If everything is installed properly then you should be able to see the newly installed boards under tools -> board menu. As shown in the screenshot,
Now let’s test our setup by running a blink sketch in our NodeMCU.
Step 1: Open the example blink program from the “example for NodeMCU 1.0” section inside the example menu,
Step 2: Connect the NodeMCU with your computer using the micro USB cable.
Step 3: Select and Board and Port and upload the program, that’s it, now the builtin LED should start blinking.
If your program uploaded properly and the LED is still not blinking then in the blinking sketch change “LED_BUILTIN” to “D4“. like as shown below,