Iot Lab Manual
Iot Lab Manual
Aim: Getting started with node MCU, Arduino with an esp8266 in Arduino IDE software.
Theories:
Node MCU:
NodeMCU is an open source platform based on ESP8266 which can connect objects and let
data transfer using the Wi-Fi protocol. In addition, by providing some of the most important
features of microcontrollers such as GPIO, PWM, ADC, and etc., it can solve many of the
project’s needs alone.
Easy to use
Programmability with Arduino IDE or IUA languages
Available as an access point or station
practicable in Event-driven API applications
Having an internal antenna
Containing 13 GPIO pins, 10 PWM channels, I2C, SPI, ADC, UART, and 1-Wire
Page 1
Installing Arduino IDE :
Step 2: open Arduino IDE the interface will look like as shown in the figure: -
Page 2
Installing esp8266 board:
Step 4: paste esp. 8266 library from Arduino IDE website as shown:-
Page 3
Step 5: now select on tools and click on board manager:-
Page 4
Step 7: again go to boards and you can see a board of node MCU: -
Conclusion:
In this practical we have learnt about node MCU and installed esp 8266 board in Arduino IDE
software.
Page 5
PRACTICAL 2
GPIO:
Stands for "General Purpose Input/output." GPIO is a type of pin found on an integrated
circuit that does not have a specific function.
They are also used by system-on-chip (SOC) circuits, which include a processor, memory,
and external interfaces all on a single chip.
A popular device that makes use of GPIO pins is the Raspberry Pi, a single-board computer
designed for hobbyists and educational purposes.
Arduino GPIO:
Arduino Uno board has various digital IO pins which can be used for input/output devices.
Arduino analog pins can also be used as digital input/output pins.
The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect
the Arduino sensors, actuators, and other ICs.
Page 6
Digital Output:
Arduino (ATmega) digital pins can be configured as output to drive output devices. We have to
configure these pins to use as output.
To configure these pins, pinMode () function is used which set direction of pin as input or
output.
pinMode(pin no, Mode)
This function is used to configure GPIO pin as input or output.
pin no number of pin whose mode we want to set.
Mode INPUT, OUTPUT or INPUT_PULLUP
E.g. pinMode (3, OUTPUT) //set pin 3 as output
These Arduino (ATmega) pins can source or sink current up to 40 mA which is sufficient to
drive led, LCD display but not sufficient for motors, relays, etc.
Note: While connecting devices to Arduino output pins use resistor. If any connected device to
Arduino withdraw current more than 40 mA from the Arduino then it will damage the Arduino
pin or IC.
These pin produce output in terms of HIGH (5 V or 3.3 V) or LOW (0 V). We can set output on
these pins using digitalWrite () function.
Fig.2 NodeMCU
Page 7
GIPO Pins Configuration with NodeMCU:
The GPIO’s shown in the blue box (1, 3, 9, 10) are not commonly used for GPIO purpose
on Dev Kit
ESP8266 is a system on a chip (SoC) design with components like the processor chip. The
processor has around 16 GPIO lines, some of which are used internally to interface with
other components of the SoC, like flash memory.
Since several lines are used internally within the ESP8266 SoC, we have about 11 GPIO
pins remaining for GPIO purposes.
2 pins out of 11 are generally reserved for RX and TX in order to communicate with a host
PC from which compiled object code is downloaded. Hence finally, this leaves just 9
general-purpose I/O pins i.e. D0 to D8.
As shown in the above figure of NodeMCU Dev Kit. We can see RX, TX, SD2, SD3 pins
are not commonly used as GPIOs since they are used for other internal processes. But we
can try with SD3 (D12) pin which mostly likes to respond for GPIO/PWM/interrupt like
functions.
Note that the D0/GPIO16 pin can be only used as GPIO read/write; no special functions
are supported on it.
Page 8
hardware requirements:
void setup ()
{
pinMode(13, OUTPUT);// sets the digital pin 13 as output
}
voidloop()
{
digitalWrite (13, HIGH); // sets the digital pin 13 on
delay (1000); // waits for a second
digitalWrite (13, LOW); // sets the digital pin 13 off
delay (1000); // waits for a second
}
Page 9
Output:
Conclusion:
We have successfully leant about GPIO interfacing and blinking led using Arduino ide software.
P a g e 10
PRACTICAL 3
1. IR sensor:
The active sensor consists of a receiver and a transmitter, the transmitter is nothing but an IR
LED or a simple LED source that produces light and, on the other hand, the receiver receives the
signals transmitted by the IR transmitter.
as you can see in the following image, the module has three output pins GND, VCC and signal.
Out of which GND and VCC are explicitly used to power the module and we get output at the
signal pin.
So, to get the output from the sensor, you have to power the module through an Arduino or
Raspberry Pi board and get the output on its output pin.
Hardware requirements:
1x NodeMCU ESP8266
1x Bread Board
1x IR sensor
Jumper Wires
P a g e 11
Sketch for IR sensor using node MCU:-
void setup()
{
Serial.begin(115200);
}
void loop()
{
if(digitalRead(5)==LOW)
{
Serial.println("Obstacle");
}
Else
{
Serial.println("Clear");
}
delay(100);
}
P a g e 12
Connection:
Output window:
P a g e 13
2. PIR sensor:
PIR sensor detects a human being moving around within approximately 10m from the
sensor. This is an average value, as the actual detection range is between 5m and 12m.PIR
are fundamentally made of a pyro electric sensor, which can detect levels of infrared
radiation. For numerous essential projects or items that need to discover when an individual
has left or entered the area. PIR sensors are incredible, they are flat control and minimal
effort, have a wide lens range, and are simple to interface with.
P a g e 14
Most PIR sensors have a 3-pin connection at the side or bottom. One pin will be ground, another
will be signal and the last pin will be power. Power is usually up to 5V. Sometimes bigger
modules don’t have direct output and instead just operate a relay which case there is ground,
power and the two switch associations. Interfacing PIR with microcontroller is very easy and
simple. The PIR acts as a digital output so all you need to do is listening for the pin to flip high
or low. The motion can be detected by checking for a high signal on a single I/O pin. Once the
sensor warms up the output will remain low until there is motion, at which time the output will
swing high for a couple of seconds, then return low. If motion continues the output will cycle in
this manner until the sensors line of sight of still again. The PIR sensor needs a warm-up time
with a specific end goal to capacity fittingly. This is because of the settling time included in
studying nature’s domain. This could be anyplace from 10-60 seconds.
Hardware Components:
NodeMCU
Breadboard
Jumper Wires
LED
Circuit connections:
P a g e 15
Connecting PIR sensors to a NodeMCU is really simple. The PIR acts as a digital output so all
you need to do is operate the pin to flip high (detected) or low (not detected). Check out the
images for more details.
Most PIR modules have a 3-pin connection at the side or bottom. The pinout may vary between
modules so check the pinout carefully! Power is usually 3-5v DC input.
The circuit connections are made as follows :
Vcc pin of the HC-SR501 is connected to +3v of the NodeMCU.
Output pin of the HC-SR501 is connected to Digital pin D7 of the NodeMCU.
GND pin of the HC-SR501 is connected to Ground pin (GND) of the NodeMCU.
In this example we'll connect Anode pin of the LED to Digital pin D6 and Cathode pin
to GND pin of NodeMCU.
Before you get started with coding you need Arduino IDE.To download Arduino IDE and for
NodeMCU setup, you can check my previous instructacle.
P a g e 16
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop() {
pirstatdigitalRead(pirpin);
if (pirStat == HIGH) {
digitalwrite(ledPin, HIGH);
Serial.println("Motion detect");
}
else
{
digitalwrite(ledPin, LOW);
Serial.println("Motion absent");
}
P a g e 17
Connections:
Output:
Conclusion:
We have successfully learned about Digital ON/OFF sensor (PIR and IR) interfacing
programming.
P a g e 18
PRACTICAL 4
Introduction:
This practical explains how to log weather data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor DHT11 will be used to measure temperature and humidity data.
Hardware required
Node MCU
DHT 11 temperature sensor
Jumper cables
Building Circuit
Make connection as mentioned ahead.
1. Vin VCC
2. GND GND
3. D3 Data Out
P a g e 19
Circuit Layout:
Procedure:
P a g e 20
2. create your new thingspeak account and enter necessary details.
P a g e 21
4. click on create new channel.
P a g e 22
6. after creating channel this window will pop up. Store this channel id for future reference.
7. for getting api key click on api keys. And save this api key.
P a g e 23
Sketch for DHT 11 using node MCU:-
#include <DHT.h>
#include <ESP8266WiFi.h>
String apiKey = "21HAIADU0ZJAFQER";
const char *ssid = "shikhar";
const char *pass = "0532269sv";
const char* server = "api.thingspeak.com";
#define DHTPIN 0 //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
P a g e 24
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
P a g e 25
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
delay(10000);
}
P a g e 26
P a g e 27
Connections:
Output:
1. On Arduino ide:
P a g e 28
2. On thingspeak:
Conclusion:
We have successfully learned about NodeMCU Temperature, Humidity data upload on
Thingspeak on Arduino IDE.
P a g e 29
PRACTICAL: 5
Introduction:
Blynk is a Platform with IOS and Android apps to control Arduino, Raspberry Pi and the
likes over the Internet. It’s a digital dashboard where you can build a graphic interface for
your project by simply dragging and dropping widgets.
How It Works:
#include <Blynk.h>
P a g e 30
if (led1.getValue()) {
led1.off();
Serial.println("LED on V1: off");
} else {
led1.on();
Serial.println("LED on V1: on");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, blinkLedWidget);
}
void loop()
{
Blynk.run();
timer.run();
}
P a g e 31
P a g e 32
Connection:
Output:
1. OFF in Blynk
P a g e 33
2. ON in Blynk
Conclusion:
We have successfully learned about Controlling devices remotely using Bluetooth link, Wi-
Fi link.
P a g e 34
PRACTICAL 6
Upload the code to node mcu and Power on the system. The node mcu asks us to place our
finger in the sensor and press the switch.
Place any finger (except the Thumb) in the sensor clip and push the switch (button). Based
on the data from the sensor, board calculates the heart rate and displays the heartbeat in bpm.
While the sensor is collecting the data, sit down and relax and do not shake the wire as it
might result in a faulty values.
P a g e 35
Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
// Assign this value to the "Signal" variable.
Serial.println(Signal); // Send the Signal value to Serial Plotter.
if(Signal > Threshold){ // If the signal is above "550", then "turn-on"
Arduino's on-Board LED.
digitalWrite(LED13,HIGH);
}
else {
digitalWrite(LED13,LOW); // Else, the sigal must be below "550", so "turn-
off" this LED.
}
delay(10);
}
P a g e 36
Connection diagram:
Output:
Conclusion:
We have successfully learned to write a program to monitor Heartbeat in node MCU.
P a g e 37
PRACTICAL:7
In agriculture IoT applications include farm vehicle tracking, livestock monitoring, storage
monitoring and other farm operations. The diagram on the right provides a visual of this
application.
In this IoT model, sensors can be deployed in the farm – to the ground, in water, in vehicles
etc. to collect data. The collected data is stored in the cloud system or server and accessed
by the farmer via the internet or their mobile phones.
Sketch:
1. Sensor:
P a g e 38
2. Code:
Connection:
P a g e 39
Output:
Conclusion:
We have successfully learned about experiments on Agriculture IOT (Soil moisture ,PH
monitor).
P a g e 40
PRACTICAL: 8
The Internet of Things (or commonly referred to as IoT) based Home Automation system,
as the name suggests aims to control all the devices of your smart home through internet
protocols or cloud based computing.
The IoT based Home Automation system offer a lot of flexibility over the wired systems s
it comes with various advantages like ease-of-use, ease-of-installation, avoid complexity of
running through wires or loose electrical connections, easy fault detection and triggering
and above and all it even offers easy mobility.
Sketch:
P a g e 41
Output of Blynk:
Conclusion:
P a g e 42
PRACTICAL: 9
AIM: Familiarization with Raspberry Pi and its architecture. Perform necessary software
installation.
It is a cheap, credit-card-sized device that uses a daily keyboard and mouse and joins to a TV or
computer monitor. It is a thin weighable computer that let every person of all ages to discover
programming and gain how to programme in variant languages like Python and Scratch.
SD card
We recommend a class 4 or class 10 microSD card of at least 8 GB. People can get a card which
is pre-existed with NOOBS or Raspberry Pi OS to save the time but it's easy to establish self-
card.
Any HDMI/DVI monitor or TV can work as a display for the Pi. Use a monitor with an HDMI
input for the best results; other link types are also available for older devices.
Any regular USB keyboard and mouse will work with Raspberry Pi. If already paired, wireless
keyboards and mice can run. For configuration options for keyboard configurations, see raspi-
config.
Power supply
P a g e 43
Like Model 4B, 2A at 5V for 3B and 3B+, or 700mA at 5V for the earlier, low-powered Pi
versions, we require good-quality power connection that can facilitate legit 3A at 5V. We suggest
that one must use the real Raspberry Pi power supply that is specifically made for Raspberry Pi.
Low-current power supplies can work for normal, but if it gets too much supply, it might cause
the Pi to restart. For work with the Pi 3 or 4, they are not comfortable.
Required only if we require wireless connectivity and operating an older model without wireless
qualities pre-installed.
Raspberry Pi Imager is the quick and easy way to install Raspberry Pi OS and
other operating systems to a microSD card, ready to use with your Raspberry
Pi. Watch our 45-second video to learn how to install an operating system
using Raspberry Pi Imager.
Prerequisites:
microSDHC card (with SD adapter)— at least 8GB although 32GB can be used which allows
for more software to be loaded.
Micro HDMI to HDMI cable — you can also use a Micro HDMI to HDMI adapter with a
regular HDMI cable.
P a g e 44
Keyboard
Mouse
Monitor
Once you meet all of the prerequisites you are ready to move on to installing Raspberry Pi OS.
The first step is to download the Raspberry Pi Imager from the official Raspberry Pi website. This
tool will allow you to choose an OS, have it downloaded automatically, and write it to the SD
card of your choice.
The imager tool is available on Windows, macOS, and Ubuntu. Images shown will be from a
Mac, but the tool will work the same across the supported platforms.
Download the Raspberry Pi Imager for your operating system and follow the installation
instructions.
Step 2: Choose OS
P a g e 45
Several operating systems are available for selection within the Raspberry Pi Imager, but we
will focus on Raspberry Pi OS.
There are 3 versions of Raspberry Pi OS available. We will briefly touch on each one but we
will be using Raspberry Pi OS (32-bit) for this guide.
Select CHOOSE OS
Raspberry Pi OS (32-bit) Lite: This version provides the bare essentials to get you up and running.
There is no Graphical User Interface (GUI) with this image and the size is around 0.4 GB.
Raspberry Pi OS (32-bit): This version includes a GUI and has basic software installed. The size
of this image is around 1.1 GB.
Raspberry Pi OS Full (32-bit): This version includes a GUI and more software installed than the
non-full version. The size of this image is around 2.5 GB
P a g e 46
OS Selected in Raspberry Pi Imager
You’ll now need your SD card connected to your computer to copy over the OS you chose.
Select CHOOSE SD CARD and select the SD card you have connected to your computer.
Select SD Card
P a g e 47
OS and SD Card selected
Step 4: Write to SD Card:- This step will write the selected OS to the SD card and run a
verification that the copy was successful.
The writing process will vary depending on the OS you selected. Typically, this will only take a
few minutes.
Verifying Write
P a g e 48
Write Successful
The OS has now been copied to your SD card. You are now ready to move on to booting your
Raspberry Pi.
Select CONTINUE
Insert your microSDHC card into your Raspberry Pi. Then, hook up your Raspberry Pi to power,
keyboard, mouse, and monitor.
Select Next
Welcome to Raspberry Pi
P a g e 49
Choose Your Country
Select the checkboxes if you are using the English language and an English keyboard
Click Next
Set Country
The next screen will prompt you to change your password. The default username is “pi” and the
default password is “raspberry”
Press Next
P a g e 50
Change Password
The next screen will ask you if there is a black border around the desktop. The desktop should
take up the entire screen. If it doesn’t, Raspberry Pi OS can make the adjustment to fill the black
space. This change will take effect when the Raspberry Pi is restarted.
Select the checkbox if the screen shows a black border around the desktop.
Press Next
Set Up Screen
The next screen will prompt you to connect the Raspberry Pi to a wireless network. If no internet
connection is available you can press the skip button to proceed past this step. If you have a wired
P a g e 51
Select a Wireless Network
Press Next
The next screen will prompt you to enter the wireless network password. You can uncheck “hide
characters” to see the characters you are typing.
Press Next
P a g e 52
The next screen will ask you if you’d like to have the operating system and applications checked
and updated if necessary. An internet connection is required to complete this step. Press “Skip” if
you’d like to continue without checking.
Update Software
A popup will indicate when your system is up to date.
System is up to date
The last screen will let you know that setup is complete and your Raspberry Pi is good to go.
Feel free to restart your Raspberry Pi for any system changes to take effect.
Setup complete.
Conclusion: we have successfully learned about familiarization with Raspberry Pi and its
architecture. Perform necessary software installation.
P a g e 53
PRACTICAL: 10
AIM: To interface LED with Raspberry Pi and write Python programming to turn ON/ OFF
LED using Raspberry Pi.
The features of the Raspberry Pi’s GPIO Pins before proceeding with the further step of
how to Blink an LED using Raspberry Pin and its GPIO Pins.
Components Required:
In order to Blink an LED using Raspberry Pi, we need to first connect the LED to the
Raspberry Pi. There are two ways you can connect your LED to the Raspberry Pi. I’ll show
both ways of connecting the LED.
Circuit 1
In the first circuit, the anode of the LED is connected to GPIO25 (Physical Pin 22) through
a 1KΩ current limiting resistor. The cathode of the LED is connected to the GND Pin.
In this circuit, the anode of the LED is connected to the 3.3V supply pin of the Raspberry
Pi through the 1KΩ resistor. The cathode of the LED is connected to GPIO25 (Physical Pin
22).
P a g e 54
NOTE: I’ll be concentrating on the first circuit, where the GPIO pin GPIO25 acts as the
source. The code explained in the further sections will be specific to this circuit. The code
can also be used for second circuit with slight or no modifications.
Sketch:
importRPi.GPIOas GPIO # Import Raspberry Pi GPIO library
fromtime import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin ,set initial
value to low (off)
whileTrue: # Run forever
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second
P a g e 55
Connection diagram:
Output of led:
Conclusion:
We have successfully about interface LED with Raspberry Pi and write Python
programming to turn ON/ OFF LED using Raspberry Pi.
P a g e 56