Lab Manual of IoT 2023-24
Lab Manual of IoT 2023-24
Class: TE(IT)
Internet of Things
(314448D)
LABORATORY MANUAL
INSTITUTE To impart value added technological education through pursuit of academic excellence,
VISION research and entrepreneurial attitude.
M1: To achieve academic excellence through innovative teaching and learning process.
INSTITUTE
MISSION M2: To imbibe the research culture for addressing industry and societal needs.
M4: To produce competent and socially responsible professionals with core human values.
M4: To incorporate social and ethical awareness among the students to make them
conscientious professionals.
Department
Program Educational Objectives(PEOs)
PEO1: To Impart fundamentals in science, mathematics and engineering to cater the needs
of society and Industries.
Prerequisite Courses:
• Programming Skill Development Lab
Course Objectives:
1. To learn interfacing of sensor and actuators using Arduino Uno/Raspberry Pi.
2. To learn and understand IoT platforms and its significance for real time
applications
3. To learn and understand the steps involved in python programming for IoT
applications
Course Outcomes:
On completion of the course, student will be able to-
List of Assignments
TITLE
Group A
1. Design and implement IoT system using Arduino Uno/ Raspberry Pi using 'Ultrasonic sensor
and Servo motor' such as 'Door opener in home automation'.
2. Design and implement parameter monitoring IoT system keeping records on Cloud such as
'environment humidity and temperature monitoring'.
3. Design and implement real time monitoring system using android phone (Blynk App.) such as
'soil parameter monitoring'.
4. Design and implement IoT system for one of the applications like: Traffic Application,
Medical/Health application, Social Application etc.
IoT Practical 1
Aim : Design and implement IoT system using Arduino Uno/ Raspberry Pi using 'Ultrasonic sensor
and Servo motor' such as 'Door opener in home automation'
Objective : To connect and implement Raspberry Pi, Ultrasonic Sensor using Servo Motor used as a
Door Opener System.
Theory :
Raspberry Pi:-
You are going to take a first look at Raspberry Pi! You should have a Raspberry Pi
computerin front of you for this. The computer shouldn’t be connected to anything yet.
o Look at your Raspberry Pi. Can you find all the things labelled on the diagram?
USB ports — these are used to connect a mouse and keyboard. You can also
connectother components, such as a USB drive.
SD card slot — you can slot the SD card in here. This is where the operating
systemsoftware and your files are stored.
Ethernet port — this is used to connect Raspberry Pi to a network with a
cable.Raspberry Pi can also connect to a network via wireless LAN.
Audio jack — you can connect headphones or speakers here.
HDMI port — this is where you connect the monitor (or projector) that you are
usingto display the output from the Raspberry Pi. If your monitor has speakers, you
can alsouse them to hear sound.
Micro USB power connector — this is where you connect a power supply. You
shouldalways do this last, after you have connected all your other components.
GPIO ports — these allow you to connect electronic components such as LEDs and
buttons to Raspberry Pi.
Set up your SD card
If you have an SD card that doesn’t have the Raspberry Pi OS operating system on it yet,
or if you want to reset your Raspberry Pi, you can easily install Raspberry Pi OS yourself.
To do so, you need a computer that has an SD card port — most laptop and desktop
computers haveone.
The Raspberry Pi OS operating system via the Raspberry Pi Imager
Using the Raspberry Pi Imager is the easiest way to install Raspberry Pi OS on your SD
card. Note: More advanced users looking to install a particular operating system should
use this guide to installing operating system images.
Download and launch the Raspberry Pi Imager
o Visit the Raspberry Pi downloads page
o Click on the link for the Raspberry Pi Imager that matches your operating system
If this pops up, click on More info and then Run anyway
Follow the instructions to install and run the Raspberry Pi Imager
Insert your SD card into the computer or laptop SD card slot
In the Raspberry Pi Imager, select the OS that you want to install and the SD card
youwould like to install it on
Note: You will need to be connected to the internet the first time for the the Raspberry Pi
Imager to download the OS that you choose. That OS will then be stored for future offline
use. Being online for later uses means that the Raspberry Pi imager will always give you
the latest version.
NOOBS).
Note: Many microSD cards come inside a larger adapter — you can slide the smaller card
outusing the lip at the bottom.
o Find the USB connector end of your mouse’s cable, and connect the mouse to a USB
porton your Raspberry Pi (it doesn’t matter which port you use).
o Make sure your screen is plugged into a wall socket and switched on.
o Look at the HDMI port(s) on your Raspberry Pi — notice that they have a flat side on top.
o Use a cable to connect the screen to the Raspberry Pi’s HDMI port — use an adapter if
necessary.
Raspberry Pi 4
Connect your screen to the first of Raspberry Pi 4’s HDMI ports, labelled HDMI0.
Raspberry Pi 1, 2, 3
Connect your screen to the single HDMI port.
Note: nothing will display on the screen, because the Raspberry Pi is not running yet.
o If you want to connect the Pi to the internet via Ethernet, use an Ethernet cable to
connect the Ethernet port on the Raspberry Pi to an Ethernet socket on the wall or on
your internet router. You don’t need to do this if you want to use wireless connectivity,
or if you don’t want to connect to the internet.
o If your screen has speakers, your Raspberry Pi can play sound through these. Or you
couldconnect headphones or speakers to the audio port.
Your Raspberry Pi doesn’t have a power switch. As soon as you connect it to a power
outlet, it will turn on.
o Plug the power supply into a socket and connect it to your Raspberry Pi’s power port.
You should see a red LED light up on the Raspberry Pi, which indicates that Raspberry Pi
is connected to power. As it starts up (this is also called booting), you will see raspberries
appear in the top left-hand corner of your screen.
When you start your Raspberry Pi for the first time, the Welcome to Raspberry Pi
applicationwill pop up and guide you through the initial setup.
o Connect to your WiFi network by selecting its name, entering the password,
andclicking Next.
Note: if your Raspberry Pi model doesn’t have wireless connectivity, you won’t see
thisscreen.
o Click Next let the wizard check for updates to Raspbian and install them (this might
take alittle while).
A tour of Raspberry Pi
Click on File, then choose Save, and then click on Desktop and save the file as
You might want to connect your Raspberry Pi to the internet. If you didn’t plug in an
ethernetcable or connect to a WiFi network during the setup, then you can connect now.
o Click the icon with red crosses in the top right-hand corner of the screen, and select
your network from the drop-down menu. You may need to ask an adult which network
you should choose.
o Type in the password for your wireless network, or ask an adult to type it for you,
thenclick OK.
o When your Pi is connected to the internet, you will see a wireless LAN symbol
instead ofthe red crosses.
You can control most of your Raspberry Pi’s settings, such as the password,
throughthe Raspberry Pi Configuration application found in Preferences on the menu.
System
In this tab you can change basic system settings of your Raspberry Pi.
Password — set the password of the pi user (it is a good idea to change the
passwordfrom the factory default ‘raspberry’)
Boot — select to show the Desktop or CLI (command line interface) when your
Raspberry Pi starts
Auto Login — enabling this option will make the Raspberry Pi automatically
log inwhenever it starts
Network at Boot — selecting this option will cause your Raspberry Pi to wait
until anetwork connection is available before starting
Splash Screen — choose whether or not to show the splash (startup) screen when
yourRaspberry Pi boots
Interfaces
You can link devices and components to your Raspberry Pi using a lot of different types
of connections. The Interfaces tab is where you turn these different connections on or
off, so that your Raspberry Pi recognises that you’ve linked something to it via a
particular type of connection.
Performance
If you need to do so for a particular project you want to work on, you can change
theperformance settings of your Raspberry Pi in this tab.
Warning: Changing your Raspberry Pi’s performance settings may result in it behaving
erratically or not working.
This tab allows you to change your Raspberry Pi settings to be specific to a country
orlocation.
Locale — set the language, country, and character set used by your Raspberry Pi
Timezone — set the time zone
Keyboard — change your keyboard layout
WiFi Country — set the WiFi country code
Code
# Setup GPIO
GPIO.setwarnings(False)
TRIG = 11
ECHO = 8
servoPIN = 18
GPIO.setmode(GPIO.BCM)
try:
while True:
GPIO.output(TRIG, False)
time.sleep(0.000002)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
startTime = time.time()
stopTime = time.time()
while GPIO.input(ECHO) == 0:
startTime = time.time()
while GPIO.input(ECHO) == 1:
stopTime = time.time()
GPIO.output(TRIG, True)
except KeyboardInterrupt:
servo.stop()
GPIO.cleanup()
Hardware Connection: -
Output:
IoT PRACTICAL 2
Aim : Design and implement parameter monitoring IoT system keeping records on Cloud such as
'environment humidity and temperature monitoring'.
Theory :
we are using the DHT11 sensor for sending Temperature and Humidity data to Thingspeak using
Arduino and ESP8266. By this method, we can monitor our DHT11 sensor’s temperature and humidity
data over the internet using the ThingSpeak IoT server. And we can view the logged data and graph
overtime on the Thingspeak website.
Components Required
Arduino Uno
ESP8266 WiFi Module
DHT11 Sensor
Breadboard
Jumper Wires
For creating your channel on Thingspeak, you first need to Sign up on Thingspeak. In case if you
already have an account on Thingspeak, just sign in using your id and password.
Click on Sing up if you don’t have account and if you already have an account, then click on sign
in.After clicking on signup, fill in your details.
Once you Sign in after your account verification, Create a new channel by clicking “New
Channel” button.
After clicking on “New Channel”, enter the Name and Description of the data you want to upload
on this channel. For example, I am sending my DHT11 sensor data, so I named it DHT11 data.
Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2. If you want to use
more Fields, you can check the box next to Field option and enter the name and description of
your data.
After this, click on the save channel button to save your details.
To send data to Thingspeak, we need a unique API key, which we will use later in our code to
upload our sensor data to Thingspeak Website.
Click on “API Keys” button to get your unique API key for uploading your sensor data.
Now copy your “Write API Key”. We will use this API key in our code.
To program Arduino, open Arduino IDE and choose the correct board and port from the ‘tool’
menu.
Upload it in Arduino UNO. If you successfully upload your program, Serial monitor will look like
this:
After this navigate to your Thingspeak page and open your channel at Thingspeak and output will
be shown as below:
Hence, we have successfully monitored Temperature and Humidity data over ThingSpeak using
Arudino and ESP32.
Code:
#include <stdlib.h>
#include <DHT.h>
String msg = "GET /update?key=Your API Key"; //change it with your key...
float temp;
int hum;
String tempC;
int error;
void setup()
Serial.println("AT");
delay(5000);
if(Serial.find("OK")){
connectWiFi();
void loop(){
start:
error=0;
temp = dht.readTemperature();
hum = dht.readHumidity();
char buffer[10];
updateTemp();
if (error==1){
goto start;
delay(5000);
void updateTemp(){
cmd += IP;
cmd += "\",80";
Serial.println(cmd);
delay(2000);
if(Serial.find("Error")){
return;
cmd = msg ;
cmd += "&field1=";
cmd += tempC;
cmd += "&field2=";
cmd += String(hum);
cmd += "\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">")){
Serial.print(cmd);
else{
Serial.println("AT+CIPCLOSE");
//Resend...
error=1;
boolean connectWiFi(){
Serial.println("AT+CWMODE=1");
delay(2000);
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
Serial.println(cmd);
delay(5000);
if(Serial.find("OK")){
return true;
}else{
return false;
Conclusion:
IoT Practical 3
Aim: Design and implement real time monitoring system using android phone (Blynk App.)
such as 'soil-parameter monitoring'.
Objective: Real Time Monitoring of Temperature on Android Phone using Soil Parameter.
Theory:
Agriculture has been the most important practice from very beginning of the human
civilization. It has seen many iterations of development in technology with time. A good
agricultural practice is still an art.
In last few decades changing weather condition, increase in global temperature and
pollution, has led to abnormal environmental conditions like raining. Traditional way of
farming is unable to cope with these environmental changes.
Good control over Environmental parameters like temperature, humidity, and moisture
plays important role in growth of the plant. Temperature affects many of plant activities
such as pollination, germination etc.
It is observed that, at higher temperature, respiration rate increases that result in reduction
of sugar contents of fruits and vegetables. At lower temperatures photosynthesis activity is
slowed down. Till date many methods have come into existence where water can be
limitedly consumed.
A method where monitoring water status and based on status of water whether it is high or
low irrigation is scheduled which is based on canopy temperature of plant, which was
captured with thermal imaging. Another method is making use of information on
volumetric water content of soil, using dielectric moisture sensors to control actuators and
save water, instead of the scheduled irrigation at a particular time of day and supplying
water only for a specific duration. This above method just opens the valve and supply
water to bedding plants when volumetric content of soil will drop below threshold value.
In this paper a use of the second method where sensors are placed and based on that water
is supplied to the field and intimated to the farmer using software application.
Wireless sensor networks is also called as wireless sensors and actor network, are
distributed spatially autonomous sensors to monitor physical or environmental conditions
as temperature, pressure sound, moisture etc. and it co-operatively passes these data via
network to the main location.
Code
Hardware Diagram:
Output:
IoT Practical 4
Aim: Design and implement IoT system for one of the applications like: Traffic Application,
Medical/Health application, Social Application etc.
Diagram:
Circuit Diagram:
Theory:
To get started, you’ll need to place all the components on the breadboard and connect them to the
appropriate GPIO pins on the Raspberry Pi.
Each component requires its own individual GPIO pin, but components can share a ground pin.
We will use the breadboard to enable this.
Place the components on the breadboard and connect them to the Raspberry Pi GPIO pins,
according to the above diagram:
Code:
Y.on()
time.sleep(2)
Y.off()
G.on()
time.sleep(3)
G.off()
Output:
Conclusion:
Thus we have executed successfully the Traffic Signal Using Raspberry Pi.