Getting Started Internet of Thing (IoT) Using NodeMcu | IoT Tutorial


We are, to begin with going to see getting Started Internet of Thing(IoT) Using NodeMcu for your IoT project. There are many IoT modules accessible within the market and it is very simple to induce misplaced with all the choices available.

The first one that you simply have likely listened of is the little ESP8266 Serial Wireless Transceiver module:

This module is the foremost popular one because it is truly little and as it cost $6. However, the number of open GPIO pins (input/output pins) is very constrained. It is also difficult to plug it into a standard breadboard. If you select this module, you won’t be able to do the projects using analog sensors, as the analog input isn’t available.

You’ll discover more data almost this module at 266_Specifications_English.pdf

For some limitation in the ESP8266 Serial Wireless Transceiver module,, we can use NodeMcu development kit

The NodeMCU ESP8266 development board comes with the ESP-12E module containing ESP8266 chip having Tensilica Xtensa 32-bit LX106 RISC microprocessor. This microprocessor underpins RTOS and works at 80MHz to 160 MHz movable clock recurrence.

ESP8266 has 128 KB Ram and 4MB of Flash memory to store information and programs. Its tall preparing power with in-built Wi-Fi / Bluetooth and Profound Rest Working highlights make it perfect internet of Thing NodeMcu projects. NodeMCU can be fueled utilizingMiniaturized scale USB jack and VIN Pin (Outside Supply Pin). It underpins UART, SPI, and I2C interface. The NodeMCU Development Board can be easily modified with Arduino IDE since it is easy to use.

NodeMCU ESP8266 Specifications & Features

Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106
Operating Voltage: 3.3V
Input Voltage: 7-12V
Digital I/O Pins (DIO): 16
Analog Input Pins (ADC): 1
UARTs: 1
SPIs: 1
I2Cs: 1
Flash Memory: 4 MB
Clock Speed: 80 MHz
USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
PCB Antenna
Small Sized module to fit smartly inside your Internet of Thing NodeMcu projects

NodeMCU ESP8266 Pinout

Nodemcu GPIO API:

This GPIO(General Reason Input/Output) permits us to get to pins of ESP8266, all the pins of ESP8266 gotten to utilizing the command GPIO, all the get to is based on the I/O index number on the NoddMCU dev units, not the inside GPIO pin, for the case, the pin ‘D7’ on the NodeMCU dev kit is mapped to the internal GPIO pin 13, in the event that you need to turn ‘High’ or ‘Low’ that particular pin you would like to call the pin number ‘7’ no the internal GPIO of the Pin. After you are programming with generic ESP8266 this confusion will arise which pin should be called amid programming, on the off chance that you’ reutilizing NodeMCU dev kit, it has come prepared for working with Lua translator which can easily program by looking the pin names related on the Lua board. If you’re utilizing non-specific ESP8266 gadgets or any other merchant sheets it would be ideal if you allude to the table underneath to know which IO list is related to the inside GPIO of ESP8266.

D0 or GPIO16 can be used only as a read and write pin, no other options like PWM/I2C are supported by this pin.

gpio.mode() :

This command will initialize the GPIO mode and also used for setting the input/output direction of the pin
Syntax : gpio.mode(pin, mode)
Pin: select any of the available gpio pins
Mode: set the selected pin mode to input or output.
Example: gpio.mode(7, gpio.OUTPUT)

This command will read the Pin value, whether the Pin is in High state or Low state will be returned when utilizing this command.

 On the work sort the Pin number to read, this will return a number based on the High or Low on the Pin side, in the event that the Pin is in the tall state this will return 1 and in case it is moo state this will return 0.


This command will make the Pin to go High or Low, we utilize this command to set a Pin to go High or Lowin the event that you need to turn on and off a Driven this command can be utilized in such situations.

Syntax: gpio.write(pin, state)
 Pin: enter the Pin that you simply need to change the state to high or Low State: High or Low, gpio.HIGH or gpio.LOW
 pin = 7
 gpio.mode(pin, gpio.OUTPUT)
 gpio.write(pin, gpio.HIGH)
 above program will set the D7 pin of Nodemcu to go High, on the primary line Pin is assigned to variable 7, and on the moment line ‘D7’ Pin as set to Output and on the third line ‘D7’ Pin has made to HIGH which is able type in esteem 1 to the Pinwhich can make to to gleam in the event that you interface a Led to the Pin ‘D7’,

gpio.trig() :

This command act as interrupt work during programming, utilizing this command can cause the program to execute certain work when the specific Pin is triggered, this work will not be accessible on the off chance that GPIO_INTERRPUT_ENABLE was undefined at the time of compile.
Syntax: gpio.trig(pin, type [, function(level)]) Choose Pin 1 to 12, as the Pin D0 or GPIO16 isn’t back interrupt or any other function.
Type: “up”, “down”, “both”, “low”, “high” which speak to rising edge, falling edge, both edge, low level, high-level trigger mode, in the event that you need to select the interrupt to occur when the Pin goes low, you ought to select low as typewhich implies the Pin will be actively tall when the Pin goes to low state it ought to halt the work and call the function to execute amid interrupt.
Function(level) callback work when triggered.
local Pin = 5 function pinValue () print(‘The Pin value’ end
gpio.mode(pin, gpio.INT)
gpio.trig(pin, ‘HIGH’, pinValue) :

samples the ADC.
Syntax :
There is only one channel available with esp devices so always choose 0, may in future devices we can expect more ADC with ESP chips. This will return the sampled value in
Example : val =
This function allows to open any file in the system for editing or creating a new file, this function access to all the existing files in the system if we want to create any new file using this function can only be done, for creating a new file, we need to open a file in write mode. All the function must be closed with the file. close function.
Syntax:, mode)
Filename, the file to be opened. There are different modes available to work on the files.
“r”: read mode (default mode in the file access)
“w”: write mode
“a”: append mode ( adding data to existing file)
“r+”: update mode. All previous data are preserved
“w+”: update mode, all previous data is erased
“a+”: append update mode, previous data is preserved, writing is only allowed at the end of the file.
Example“init.lua”, “r”)


Very imperative API’s available with NodeMCU firmware, this permits NodeMCU dev kit or ESP8266 chips to connect with other devices and get to data from web and allow a client to control a device from any part of the world, on-chip Wi-Fi SoC is what made the ESP most popular among specialist and it develops to the marvelous rate at this time. wifi.getchannel()
This work gets the current wifi channel that’s as of now associated. When this function called in the program this will return the wifi channel name.
 Syntax: wifi.getchannel()
 Example: print(wifi.getchannel())


Pulse Width Modulation API allows us to use any of the I/O pin as a PWM pin except the D0 pin of NodeMCU DEV KIT, this API will be very useful when controlling LED’s, Motors and many more devices which require PWM functions to do crazy things.
pwm.setup() This function allows setting a pin to PWM mode, only 6 pins can be set to PWM mode at the most case.
Syntax: pwm.setup(pin, clock, duty)
Pins from 1 to 12 can be chosen for PWM
Clock frequency should be set between 1- 1000, PWM frequency.
Duty cycle should be between 0-1023, max is 1023(10bit)
Example: pwm.setup(1, 100, 512) this example set the ‘D1’ pin as pwm output and frequency is 100 hz and duty cycle is 512.
This function starts the PWM, the waveform is applied to the GPIO pin.
Syntax: pwm.start(pin)
This function pause the output of the PWM waveform.
Syntax: pwm.stop(pin)
This function allows to set the duty cycle for a pin.
Syntax: pwm.setduty(pin, duty)
pwm.setup(1, 500, 512)
pwm.setup(2, 500, 512)
pwm.setup(3, 500, 512)
function led(r, g, b)
pwm.setduty(1, g)
pwm.setduty(2, b)
pwm.setduty(3, r)
led(512, 0, 0) — set led to red
led(0, 0, 512) — set led to blue.
Today we have discussed these issues for this important Internet of Thing NodeMcu Project Making. If you want more Project internet of Thing NodeMcu, you must learn more from the internet in addition to the above. There are several Internet of Thing NodeMcu ideas given in this link  From here you can get ideas about the Internet of Thing NodeMcu.

That book helped me create this tutorial

Visit to get more tutorials on IoT project


 619 total views,  3 views today