Lab Manual: Internet of Things Lab (7CS4-21)
Lab Manual: Internet of Things Lab (7CS4-21)
Lab Manual: Internet of Things Lab (7CS4-21)
List of Experiments
I . Start Raspberry Pi and try various Linux commands in command terminal window: ls, cd, touch,
mv, rm, man, mkdir, rmdir, tar, gzip, cat, more, less, ps, sudo, cron, chown, chgrp, ping etc.
2. Write Run some python programs on Pi like:
a) Read your name and print Hello message with name.
b) Read two numbers and print their sum, difference, product and division.
c) Word and character count of a given string .
d) Area of a given shape (rectangle, triangle and circle) reading shape and appropriate values from
standard input.
3. Run some python programs on Pi like:
a) Print a name 'n' times, where name and n are read from standard input, using for and while loops.
b) Handle Divided by Zero Exception.
c) Print current time for IO times with an interval of IO seconds.
d) Read a file line by line and print the word count of each line.
4. LED bilking using Raspberry pi on Proteus using Flowchart.
5. LED bilking without push button using Raspberry pi on Proteus using Flowchart.
6. Design a Flowchart Temperature and Humidity sensor and display the result using UART on
terminal.
7. Design a Flowchart Weather Station with Arduino.
8. Design a Flowchart Wi-Fi based Air Quality Monitoring System.
17. Switch on a relay at a given time using cron, where the relay's contact terminals are
connected to a load.
Aim: Start Raspberry Pi and try various Linux commands in command tenninal
window:
Is , cd , touch, mv, rm, man, mkdir, nndir, tar, gzip, cat, more, less, ps, sudo,cron,
chown, chgrp, ping, chmod, curl, echo, exit, find, finger, free, grep, kill etc.
Linux Commands:
Syntax:
$ cd [directory]
- cd /: this command is used to change directory to the root directory
4. mv: mv stands for move. mv is used to move one or more files or directories
from one place to another in file system.
Syntax:
mv [Option] source destination
5. rm: rm stands for remove here. rm command is used to remove objects such
as files, directories, symbolic links and so on from the file system .
Syntax:
rm [OPTION]... FILE...
6. man: man command in Linux is used to display the user manual of any
command
Syntax:
$man [OPTION]... [COMMAND NAME)...
Syntax:
$man [OPTION]... [COMMAND NAME]...
Syntax: . .
rmdir [-p] [-v I -verbose] [-ignore-fail-on-non-empty] directories ...
9. tar: The Linux 'tar' stands for tape archive, is used to create Archive and
extract the Archive files.
Syntax:
tar [options] [archive-file] [file or directory to be archived]
Syntax:
gzip [Options] [filenames]
Example:
$ gzip mydoc.txt]
11. cat: It reads data from the file and gives their content as output. It helps us to
create, view, concatenate files.
Command:
$cat filename
12. more: more command is used to view the text files in the command prompt,
displaying one screen at a time in case the file is large (For example log
files). The more command also allows the user do scroll up and down
through the page.
Syntax:
more [-options] f-num] [+/pattern] [+linenum] {file_name]
· [-options]: any option that you want to use in order to change the way the file is
displayed. Choose any one from the followings: (-d, -1, -f, -p, -c, - s, -u)
· [-num]: type the number of lines that you want to display per screen.•
[+/pattern]: replace the pattern with any string that you want to find in the text
file.
13. Less: less command is linux utility which can be used to read contents of
text file one page (one screen) per time. It has faster access because if file is
large, it don't access complete file, but access it page by page.
syntax:
less filename
14. ps: ps for viewing information related with the processes on a system which
stands as abbreviation for "Process Status"
Syntax- ps
[options]
15. sudo: sudo (Super User DO) command in Linux is generally used as a prefix
of some command that only superuser are allowed to run.
Syntax:
cron [-fl [-l] [-L loglevel]
17. chown: chown command is used to change the file Owner or group.
Whenever you want to change ownership you can use chown command.
Syntax:
chown [OPTION]... [OWNER][: [GROUP]] FILE...
chown [OPTION]... - reference RFILE FILE...
18. chgrp: chgrp command in Linux is used to change the group ownership of a
file or directory.
19. ping: PING (Packet Internet Groper) command is used to check the network
connectivity between host and server/host.
20. chmod: the chmod command is used to change the access mode of a file.
The name is an abbreviation of change mode.
Syntax:
1. chmod [reference][operator][mode] file...
21. curl: curl is a command line tool to transfer data to or from a server, using any
of the supported protocols
Syntax:
curl [options] [URL...]
22. echo: echo command in linux is used to display line of text/string that are
passed as an argument .
Syntax:
echo [option] [string]
23. exit: exit command in linux is used to exit the shell where it is currently
running. It takes one more parameter as [NJ and exits the shell with a return of
status N.
Syntax:
exit [n]
24. find: It can be used to find files and directories and perform subsequent
operations on them. It supports searching by file, folder, name, creation date,
modification date, owner and permissions.
Syntax:
$ find [where to start searching from]
[expression determines what to find] [-options] [what to find]
25. Finger: command is a user information lookup command which gives details
of all the users logged in
Syntax:
$fmger[usemame]
Syntax:
$free [OPTION]
27. Grep: The grep filter searches a file for a particular pattern of characters, and
displays all lines that contain that pattern.
Syntax:
grep [options] pattern [files]
Python Program:
name = input('What is your name?\n')
print ('Hello %s.' % name)
Output:
What is your name?
Mrs. Reshu Grover
Hello Mrs. Reshu Grover
b) Read twq numbers and print their sum, difference, product and division.
Python Program:
numl = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
print("Enter which operation would you like to perform?")
ch= input("Enter any of these char for specific operation+,-,*,/:")
result= 0
if ch='+':
result = num I + num2
elif ch='-':
result = num1 - num2
elif ch='*':
result = num1 * num2
elif ch='/':
result = num1 / num2
else:
print("lnput character is not recognized!")
print(numl, ch, num2, ":", result)
Output 1: Addition
Enter First Number: 100
Enter Second Number: 5
Enter which operation would you like to perform?
Enter any of these char for specific operation+,-,*,/:+
100 + 5: 105
Output 2: Subtraction
Enter First Number: 8
Enter Second Number: 7
Enter which operation would you like to perform?
Enter any of these char for specific operation+,-,*,/: -
8 - 7: I
Output 3: Multiplication
Enter First Number: 6
Enter Second Number: 8
Enter which operation would you like to perform?
Enter any of these char for specific operation+,-,*,/: *
6 * 8: 48
Output 4: Division
Enter First Number: 20
Enter Second Number: 5
Enter which operation would you like to perform?
Enter any of these char for specific operation+,-,*,/:/
20 5: 4.0
Python Program:
word_count= 0
char_count = 0
Output:
Enter a string : Hello, How are You?
Total words : 4
Total characters : 16
d) Area of a given shape (rectangle, triangle and circle) reading shape and
appropriate values from standard input.
Python Program:
Output:
Please Enter the Width of a Rectangle: 22
Please Enter the Height of a Rectangle: 5
Area of a Rectangle is: 110.00
Perimeter of Rectangle is: 54.00
Python Program:
# Python Program to find the area of triangle
# 1bree sides of the triangle a, b and c are provided by the user
Output:
Enter first side: 3
Enter second side: 4
Enter third side: 5
The area of the triangle is 6.00
Python Program:
# Python Program to find Diameter, Circumference, and Area of a Circle
PI= 3.14
radius = float(input(' Please Enter the radius of a circle: '))
diameter = 2 * radius
circumference = 2 * PI * radius
area = PI * radius * radius
Output:
Please Enter the radius of a circle: 5
Diameter of a Circle= 10.00
Circumference of a Circle = 31.40
Area of a Circle = 78.50
#Area
print("Select one of the following:")
print("1. Rectangle\n2. Triangle\n3. Circle")
s=input("Enter your choice: ")
if s='l':
x int(input("Enter length:"))
y=int(input("Enter breadth:"))
print("Area {}".format(x*y))
elif s='2':
x=int(input("Enter base:"))
y=int(input("Enter height:"))
print("Area {}".format(0.5*x*y))
elif s='3':
x-i nt(input("Enter radius:"))
print("Area {}".format(3.14*x*x))
else:
print("Enter a valid choice")
a) Print a name 'n' times, where name and n are read from standard
input, using for and while loops.
Python Program:
print ("enter two no n1 and n2")
nl =raw_input()
n2=raw_input()
nl=int(nl)
n2=int(n2)
try:
div=nl/n2
print (div)
except ZeroDivisionError:
print ("zero division is handled")
print ("out of try catch block")
Output:
Enter nl:10
Enter n2:0
zero division is handled
#DivideByZero Exception
x=int(input("First No:"))
y=int(input("Second No:"))
try:
print("x/y={}".format(x/y))
except Exception:
print("DivideByZero Exception")
Python Program:
import time
for i in range(l,11):
zz=time.asctime(time.localtime(time.time()))
zz=zz[l 1:19]
print (zz)
print (time.asctime(time.localtime(time.time())))
time.sleep(!0)
d) Read a file line by line and print the word count of each line.
Python Program:
file=open("eee.txt","r")
line=l
for i in file:
Python Program:
# read line by line from file
count+=l
line = filel .readline()
if not line:
break
print("Word Count in Line{}: {}".format(count,
len(line.split())))
filel .closeQ
RESHU GROVER(IOT LAB EXPERIMENTS) Page 18
Experiment - 4
Explanation:
Circuit:
I QF'!OI
OPIO.
3
;
::t
OP05
QPOi Qf'IQ4/Cff'IO OQ,K
GP0 1, 3A0:0.0
I Of8-01! 0-
(_ - --
,_
-' CP01t
-4-4 Ofl0m
<ro.a
QPOlllQPIO:
OftrOl'10fllO_OINI,
cw oa,o,,o_a..
, r ., ,;=-, OPO: ,
lt
I Ul::VIC..ES II TXD ,I
1
0
OP ' O t .vncco
cP-OtSIRXOO
Ofll010
Gflt09'Ml80
Gfll-1
ON GPICXI
!!"
lLUE
I -- Cr--
OflO l l'I0 ', 1
'ICl.1
QPI0'1,• W
l h _1
Aim: LED bilking without push button using Raspberry pi on Proteus using
flowchart.
Explanation:
In order to blink an LED,
We pass HIGH to tum it on
Give some delay
We pass LOW to tum it off
Give some delay
Perform the above instructions in a loop.
--- U1 ------------------------------------------------------------
GI ◄• GP IO G C L K
7
GP 1O 4
7
I
,-----
==
)5 GP1O5
:>O .o, ---- 1 GPIC:>!5 GP l0 1 7 • GP IO- G E; 0 t-- ----<:>
12 GP I0 12 GPl0 18•GP IO- G: '111
GPIO,1
GP I O 1 8 I Ci.l.a. --- (j
13
,e
GP 1O 13
GP I O 1e
GP l :::>2 7 • '3" P-1
GP l◊ ll • GP I O- G:
0- G : 2
:;
GP 1O2 7
G?IO.22 I I 1 GP 0 4
30
10 GP l 0 2 l , O l='IO= C.E , -' O FII0 2::;
20
20
GP1O10
GPI0 20
GP I0 20
◄
GP 1O 2 •GP 1O Ge
G F' l0 2 !>•G P IO : GE
o
0 t-- -- - ---<:>
GP 1O2
GP 1O 2.5
◄ I
21 GP l0 2 1
:0 0 - - -t GP l O 1,4 T X D :>
G ? l0
1
GP 1o g 1>-11so
:: ::: ::g 1,1.1 s o I I
1 0, t.lO S I ...... M O S.I
tO -0- - - --f G S:,10 1 t5•RX C>:, G, 10 t , CLK CLK
GP i OSIS P I CEO
)A <:>- -
"""!---f GP IO 2.r S OA 1
: .C)o--------t GPI0 31S::L 1
:L
OP t O ,7 S P 1_c e 1 I
CS
0Pt07
RL--P- 1 3- - - - - - - - - - - - -- -- --
I Ra•pbetr,- :::> 3 I
Aim: Design a flowchart Temperature and Humidity sensor and display the result
using UART on tenninal.
Explanation:
A Virtual terminal is used to send and receive the data through the port. Data
can be sent through the keyboard and received data is displayed on the
virtual terminal.
The designer can interface any of the UART based modules through the
virtual ports in Proteus software.
U5 8- Serib l COflft'ttet
RX TX
; TX RI(
G NO GNO
Flowchart:
USS&±
=z S::Z:Z:33.:::S.: £ LL SU
'ti-
'"':-ix-.&r.::
, ,t .'i ':.
ar·« :;;-11,,,
{.. ._..,_ )
Explanation:
Simulator: Proteus
Theory:
This Dust Sensor gives a good indication of the air quality in an environment
by measuring the dust concentration. The Particulate Matter level (PM level)
in the air is measured by counting the Low Pulse Occupancy time (LPO
time) in given time unit. LPO time is proportional to PM concentration. This
sensor can provide reliable data for air purifier systems; it is responsive to
PM of diameter 1µm.
Circuit:
PC5i'ADC,!5
r S C UP C INT t -3 ----
P C.l R ES E T /P C IN T 14 ----
10108 A
R0
1I O
8-
1 .' O
SS 100 8 8 RXD
0
101 8
t ·11
2 ----
-I ·
8 M0SI 10 1
M IS O
-------. TX
1013 · · SCK
10140----
10150----
1016 r'l-------,1n A.D2
10 17 AD3
1018 AD-4
1019 AD5
L-+--<l SDA
L..---(, SCL
L----------------
Simulator: Proteus
Components: Add Peripheral -> Groov -> 80cm Proximity sensor module
Explanation:
l I OQ
f-- - -
A R D U QN O
- ----O1Q
UN O
ss O S- I 110010
M =C) ==E:::3=== ::□
Q Q RT XX DD
t- -c==::J•t----0 10 13
iiI
Simulator: Proteus
Explanation:
Physical Connections:-
In breadboard connect ultrasonic sensor
Back side pins of sensor:- ( in breadboard vertical connections( in between) are
there)
1) VCC to Sv in Arduino board
2) Trig to pin 13 of digital pin of Arduino
3) Echo to pin 12 of digital pin of Arduino
4) Gnd to Gnd of Arduino board
Connect USB from lappy to Arduin
Code:
const int trigPin = 13;
void setup() {
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
delayMicroseconds(lO);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
inches= microsecondsTolnches(duration);
cm= microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(l 000);
{return microseconds / 74 / 2;
Verify your code in Arduino IDE that is sketch. Upload your code in Arduino IDE
After connecting, all done. Press Ctrl + shift + M. You can see output window
RESHU GROVER(IOT LAB EXPERIMENTS) Page 28
Experiment - 11
Aim: Design a system using Arduino where you can monitor Temperature and
Humidity of a place on an IDE/LCD.
Simulator: Proteus
Components: Add Peripheral -> Groov -> Temp. And Humidity Sensor
Theory:
DHTll Sensor:
The DHT11 is a basic, low cost digital temperature and humidity sensor.
· DHTl 1 is a single wire digital humidity and temperature sensor, which provides
humidity and temperature values serially with one-wire protocol.
· DHTl 1 sensor provides relative humidity value in percentage (20 to 90% RH)
and temperature values in degree Celsius (0 to 50 °C).
Explanation:
Physical Connections:-
Code:
#include <dhtl l.h>
#define DHT11PIN 4
RESHU GROVER(IOT LAB EXPERIMENTS) Page 29
dhtl I DHTI I;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHTl I.read(DHTI I PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHTl I.humidity, 2);
Serial.print("Temperature (C): "); Serial.println((float)DHTI I.temperature, 2);
delay(2 000); }
Simulator: Proteus
Theory:
Soil moisture sensors measure the volumetric water content in soil. Since the direct
gravimetric measurement of free soil moisture requires removing, drying, and
weighing of a sample, soil moisture sensors measure the volumetric water content
indirectly by using some other property of the soil, such as electrical resistance,
dielectric constant, or interaction with neutrons, as a proxy for the moisture content
'
Code:
int sensorPin = AO;
int sensorValue;
int limit = 300;
void setupO {
Serial.begin(9600);
pinMode{l3, OUTPUT);
}
void loopO {
sensorValue = analogRead(sensorPin);
Serial.println("Analog Value : ");
Serial.println(sensorValue);
if (sensorValue<limit) {
digita1Write(l3, IIlGH);
}
else {
digitalWrite(13, LOW);
}
delay(1000);
}
Output:
Aim: Design a system using Arduino that blinks an LED when you detect a motion
in an area on an IDE.
Theory:
The sensor only detects the energy emitted by other objects and don't produce any,
that's why the sensor is called a PIR or "Passive Infra-Red" sensor. These sensors
are small, cheap, rugged, low power and very easy to use.
Connections:
With Arduino,
Code:
int LED= 13; II the pin that the LED is attached to int PIR = 2; II the pin that the
sensor is attached to
void setup() {
pinMode(LED, OUTPUT); II initialize LED as an output
pinMode(PIR, INPUT); II initialize sensor as an input Serial.begin(9600); II
initialize serial
}
void loop(){
if (digitalRead(PIR) = IDGH) { II check if the sensor is IDGH digitalWrite(LED,
IDGH); II tum LED ON
Serial.println("Motion detected!");
• delay(100); II delay 100 milliseconds }
else {
digitalWrite(LED, LOW); II tum LED OFF
Serial.println("Motion stopped!");
delay(100); // delay 100 milliseconds }
}
Output:
Motion detected
Motion detected
Motion detected
Motion detected
Motion stopped
Motion stopped
Motion detected
Motion detected
Motion detected
Motion stopped
Components: PIR Sensor, LDR Sensor, Arduino UNO, Jumping wires, LED
Theory:
PIR Sensor
LDRSensor
The LOR Sensor Module is sed_to detect the presen e of lig t / measuring the intensity of light. The
output o h module oes high • the presence of light and 1t becomes low in the absence of light.
The sens1tiv1ty of the signal detection can be adjusted using potentiometer.
Code:
#define LED 2 // The pin that the LED is attached to
#define LDR 4 // The pin that the LOR Sensor is attached to
#define PIR 13 // The pin that the PIR sensor is attached to
void setupQ {
pinMode(LED, OUTPUT);// initalize LED as an output
pinMode(PIR, INPUT);// initialize PIR sensor as an input
pinMode(LDR, INPUT);// initialize LOR sensor as an input
Serial.begin(9600); II initialize serial
}
void loopQ{
if(digitalRead(PIR) = 1-IlGH)
{
Serial.println("Motion detected!");
delay(100); // delay I00 milliseconds
if(digita1Read(LDR)<512) //for dark condition!
{
Serial.println("Blinking LED since Dark");
digitalWrite(LED , I-IlGH);
delay(500);
digitalWrite(LED, LOW);
}
}
else
{
Serial.println("Motion stopped!");
delay( I 00); II delay I 00 milliseconds
}
}
Output:
Python Program:
To start, you need to make sure that your Raspberry Pi is connected to the internet.
This is needed to track time. Then type in this code:
import RPi.GPIO as GPIO
import datetime
import time
pin = your_output_pin_here
GPIO.setup(pin, GPIO.OUT)
while True:
time = datetime.datet ime.now().strftime("%H:%M")
if time = "12:00":
GPIO.output(pin, True)
time.sleep(number_of_seconds _for_led_to_be_on_here)
GPIO.output(pin, False)
time.sleep(0.030)
Replace things like 12:00 and your_output_pin_here with your own values. Every
30 milliseconds, it checks whether it is 12:00. If it is, it turns on the LED. It then
waits a number of seconds, then turns it back off.