IoT Lab Manual
IoT Lab Manual
IoT Lab Manual
_________________________________________________________________________________
Experiment No 1
Built-in LED Blinking using Node MCU
The NodeMCU ESP8266 board has two of those LEDs. One on the NodeMCU PCB and
another on the ESP-12 module’s PCB.
In this tutorial, we are going to learn built-in command of Arduino IDE which will help to blink
LED using ESP8266 NodeMCU.
Program Code:
//the setup function runs once when you press reset or power the board
void setup()
{
//initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
//the loop function runs over and over again forever
void loop ()
{
digitalWrite (LED_BUILTIN, HIGH); // turn the LED offby making the voltage level High
delay (1000); // wait for one second
digitalWrite (LED_BUILTIN, LOW); // turn the LED onby making the voltage level Low
delay (2000); //wait for two seconds
}
Note: pinMode (pin number, OUTPUT): pinMode is name of function. Pin number and
OUTPUT are arguments of the function. For example, we have connected pin 7 and 8 with two
LEDs and want to use pin 7, 8 as an output to blink LEDs.
Outcome/Result:
The onboard LED blink as per the delay
Experiment No 2
External Two LED On/Off using NodeMCU
Software Required:
• Arduino IDE (version 1.8.19)
Theory:
In this experiment, we will learn to use digital output pins of NodeMCU by blinking two LED
lights. GPIO pins (general-purpose input-output pins) of NodeMCU as digital output pins.
After conducting this experiment, we will be able to interface other output devices with
NodeMCU with two LED lights (led1 and led2).
Interfacing Diagram:
Outcome/Result:
The onboard led1 and led2 blinks as per the delay
There are different colours in traffic lights. Each light has a meaning, and these lights tell
drivers what to do.
Interfacing Diagram:
ESP8266 NodeMCU, Bread board, MicroUSB, Computer/ Laptop, LED, Switch, patch
Jumper wires.
Software Required: Arduino IDE
Theory:
In the era full of technologies, we are in search of technologies that we have full control of. So,
we require a gadget that is a semi-automatic (for example: Interface NodeMCU with Switch
which works like a remote control device),i.e., which is controlled manually as well as
automatically. One component that is used to make our device controlled manually at just one
click is a switch.
In the previous experiment, we have learned how to control the LED blink for every second,
now we will control the LED by using a button .When pressed the button, the LED was lighten
and turn off when released i.e switch button is a passive device that is used to switch between
the active high and active low states.
Interfacing Diagram:
Software Required:
Arduino IDE
Theory:
NodeMCU is an open-source platform based on ESP8266 which can connect objects and
enables data transfer using the Wi-Fi protocol. It has some important features of
microcontrollers such as GPIO, PWM, ADC etc. It can also act as a Web Server and allow
client to connect to it.
A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol) and other
protocols to respond to client requests made over the World Wide Web.
Interfacing Diagram:
Program Code:
#include<ESP8266WiFi.h>
WiFiClient client;
WiFiServer server(80);
#define led 13
void setup() // put your setup code here, to run once
{
Serial.begin (115200);
WiFi.begin("RVITM","rvitm@123"); //user name and password of wifi connection.
while(WiFi.status()!= WL_CONNECTED) //if wifi not connected wait delay
{
delay (200);
Serial.print(" ..");
Experiment No 7
Title: NodeMCU ESP8266 as a WiFI Access point ( Hot spot)
We can set SSID and Password for AP mode which will be used to authenticate other devices
while connecting to it.
NodeMCU has Station (STA) mode using which it can connect to the existing wi-fi network
and can act as an HTTP server with an IP address assigned by that network.
Example
Let’s write Arduino Sketch to enable NodeMCU as an HTTP server with Wi-Fi STA/AP mode
and control an LED connected at the server-side from the client-side.
Here we have connected LED to the pin no. 2 i.e. D2 pin on the NodeMCU board as shown in
the below figure.
As we are making an HTTP server for LED on/off functionality, we are going to make a simple
HTML page that will be visible at the client-side and able to take user input for LED on/off. It
is a user-friendly representation of button input that takes input from the user on click.
We need to write two HTML pages for LED ON and LED OFF state i.e. when a client clicks
the LED ON button, then in the next action, we need to provide options for LED OFF. Below
are the two HTML code snippets for LED ON and LED OFF state presentation. Following
figure gives the outline of the webpage design.
Interfacing Diagram:
Program Code:
#include<ESP8266WiFi.h>
#define greenLED 13
#define redLED 2
WiFiClient client;
WiFiServer server(80);
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin("RVITM", "rvitm@123");
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print("..");
delay(200);
}
Serial.println();
Serial.println("NodeMCU is connected to WiFi");
Serial.println(WiFi.localIP());
Outcome/Result:
1. Observe the LED ON/OFF in the hardware setup
2. Following output, you can see in the serial monitor:
Interfacing Diagram:
Program Code:
Graph:
Example
writing a C/C++ based Arduino sketch for NodeMCU as an HTTP Client and GET/POST the
data from to the Thingspeak server.
In this experiment, we are using the Thingspeak server for HTTP Client demo purposes.
Thingspeak is an open IOT platform where anyone can visualize and analyze live data from
their sensor devices. Also, we can perform data analysis on data posted by remote devices with
Matlab code in Thingspeak. To learn more about Thingspeak refer link:
https://thingspeak.com/pages/learn_more.
Just sign up and create a channel. We have below the example channel ID and write key on
Thingspeak for data send and receive.
• Channel ID is = 309236
• Write Key is = 1EYZIS5OCRJSKZHG
Note: Do not forget to tick the Make Public field in the channel setting option on your
Thingspeak channel.
Interfacing Diagram:
Interfacing Program:
3. Copy Channel ID
1. Head to the “Channel Settings” tab and copy the “Channel ID” (you will need
to input this ID in your code)