Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

LAB MANUAL

Internet of Things Lab (7CS4-21)


RAJASTHAN TECHNICAL UNIVERSITY, KOTA
Syllabus

IV Year-VD Semester: B.Tech. Computer Science and Engineering 7CS4-21:


Internet of Things Lab
Credit: 2 Max. Marks: lOO(IA:60, ETE:40)
OL+OT+4P End Tenn Exam: 2 Hours

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.

RESHU GROVER(IOT LAB EXPERIMENTS) Page2


9. Design a Flowchart of interfacing 80 cm Infrared Proximity Sensor.
IO. To measure distance using Ultrasonic Sensor.
11. Design a system using Arduino where you can monitor Temperature and Humidity of a place on
an IDE/LCD.
12. Design a system using Arduino where you can monitor Soil Moisture of a plant on an IDE. If soil
moisture is less, then LED should glow.
13. Design a system using Arduino that blinks an LED when you detect a motion in an area on an
IDE.
14. Motion detection and blinking the light when the light intensity is low using Arduino.
15. Flash an LED at a given on time and off time cycle, where the two times are taken from a

16. Flash an LED based on cron output (acts as an alarm).

17. Switch on a relay at a given time using cron, where the relay's contact terminals are
connected to a load.

RESHU GROVER(IOT LAB EXPERIMENTS)


Page3
Experiment - l

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.

Use command line terminal of linux operating system, preferably Raspberry Pi


operating system.

Submit a brief description of each command and its function.

Linux Commands:

l. ls: It lists directory contents of files and directories.

- Display All Information About Files/Directories Using$ ls -1

- Open Last Edited File Using ls -t

- Display File Size in Human Readable Format Using ls -lh

2. cd: cd command in linux known as change directory command. It is used to


change current working directory.

Syntax:
$ cd [directory]
- cd /: this command is used to change directory to the root directory

- cd (Jir_l /dir_2/dir_3: This command is used to move inside a directory from a


directory
- cd .. : this command is used to move to the parent directory of current
directory, or the directory one level up from the current directory.

- cd "dir name": This command is used to navigate to a directory with white


spaces.

RESHU GROVER(IOT LAB EXPERIMENTS) Pages


3. touch: Used to create, change and modify timestamps of a file. It is used to
create a file without any content.

Touch command Syntax to create a new file:

touch file name

Touch command to create multiple files:

touch File l _name File2_name File3_name

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.

It has two distinct functions:


- It rename a file or folder.
- It moves group of files to different directory.

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)...

7. mkdir: mkdir command in Linux allows the user to create directories

Syntax:
$man [OPTION]... [COMMAND NAME]...

RESHU GROVER(IOT LAB EXPERIMENTS) Page6


8. rmdir: nndir command in Linux allows the user to create directories

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]

10.gzip: gzip command compresses files.

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.

RESHU GROVER(IOT LAB EXPERIMENTS) Page7


• [+linenum]: use the line number from where you want to start displaying the text
content.
· fjile_name}: name of the file containing the text that you want to display on the
screen.

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.

16. lcron: automates the scheduled task at a predetermined time. It is a daemon


process, which runs as a background process.

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.

RESHU GROVER(IOT LAB EXPERIMENTS) Page8


Syntax:
Chgrp [OPTION]... GROUP FILE...
Schgrp [OPTION]... -reference=RFILE FILE...

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]

RESHU GROVER(IOT LAB EXPERIMENTS) Page9


26. Free: command which displays the total amount of free space available along
with the amount of memory used and swap memory in the system, and also the
buffers used by the kernel.

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]

28. Kill: command in Linux (located in /bin/kill), is a built-in command which is


used to terminate processes manually. kill command sends a signal to a process
which terminates the process.

RESHU GROVER(IOT LAB EXPERIMENTS) Page 10


Experiment - 2
Aim: Run some python programs on Pi like:
a) Read your name and print Hello message with name.

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 11


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: 1
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

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

c) Word and character count of a given string.

Python Program:
word_count= 0
char_count = 0

RESHU GROVER(IOT LAB EXPERIMENTS)


Page 12
usr_input = input("Enter a string : ")
split_string = usr _ input.split()
word_count = len(split_string)
for word in split_string:
char_count += len(word)
print("Total words : {}".format(word_count))
print("Total characters : {}".format(char_count))

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:

width = float(input('Please Enter the Width of a Rectangle: '))


height = float(input('Please Enter the Height of a Rectangle:'))

# calculate the area


Area = width * height

# calculate the Perimeter


Perimeter = 2 * (width + height)
print("\n Area of a Rectangle is: %.2f' %Area)
print(" Perimeter of Rectangle is: %.2f' %Perimeter)

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

RESHU GROVER(IOT LAB EXPERIMENTS)


Page 13
a = float(input('Enter first side: '))
b = float(input('Enter second side:'))
c = float(input('Enter third side:'))

# calculate the semi-perimeter


s=(a+b+c)/2

# calculate the area


area= (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f %area)

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

print(" \n Diameter of a Circle = %.2f' %diameter)


print(" Circumference of a Circle = %.2f' %circumference)
print(" Area of a Circle = %.2f' %area)

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 14


Combined Python Program:

#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")

RESHU GROVER(IOT LAB EXPERIMENTS) Page 15


Experiment - 3
Aim: 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.

Python Program (Using For Loop):


i=l
print ("enter the name")
name=raw_inputO
print ("enter the no of time" )
num=raw_input()
#print (type(num))
num=int(num)
for i in range(l,num+1):
print (i , name)
i=i+l

Python Program (Using While Loop):


print ("enter the name")
name=raw_input()
print ("enter the no of time" )
num=raw_input()
print (type(num))
num=int(num)
i=l
while(i<=num):
print (name)
i=i+l

Python Program (Without Loop):


defname(n):
if n != 0:
name(n-1)
print("Name")
name(I0)

RESHU GROVER(IOT LAB EXPERIMENTS) Page 16


b) Handle Divided by Zero Exception.

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")

c) Print current time for 10 times with an interval of 10 seconds.

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)

RESHU GROVER(IOT LAB EXPERIMENTS) Page 17


Python Program:
#Current time 10 times
import datetime
import time
for i in range(O,10):
print(datetime.datetime.now().time())
time.sleep(lO) ·

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:

print ("print the line no=" , line , "and line is=" , i)


z=i.split()
print ("no of word in line =" , line ,"is = " , len(z))
line= line+ l

Python Program:
# read line by line from file

L = ["Welcome to India", "Delhi is the capital\n", "Have fun\n"]


filel = open('myfile.txt', 'w')
filel .writelines((L))
fileI.close()

filel = open('myfile.txt', 'r')


count = 0
while True:

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

Aim: LED bilking using Raspberry pi on Proteus using flowchart.

Components: Raspberry pi, LED, Button

Simulator: Proteus 8 Professional

Explanation:

In order to blink an LED,


We pass HIGH to tum it on
When the push button is switched on
We pass LOW to tum it off
When the push button is switched off

Perform the above instructions in a loop.

Circuit:

c Caph.r e X I "' Visual Designer X


.----- U1 _ _ _ _ _

I QF'!OI
OPIO.
3
;
::t
OP05
QPOi Qf'IQ4/Cff'IO OQ,K
GP0 1, 3A0:0.0

I <P011 o----:;;,...i CP012


GPlOtl
,, 0--'=--I Oft-Oil
o------; '61C
C ..01V3A O_GIN1
ef'lr02':"'>Gfl!O_
0 OIN!

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 19


Experiment - 5

Aim: LED bilking without push button using Raspberry pi on Proteus using
flowchart.

Components: Raspberry pi, LED, Button

Simulator: Proteus 8 Professional

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 20


Experiment - 6

Aim: Design a flowchart Temperature and Humidity sensor and display the result
using UART on tenninal.

Components: HYT27 l Precision Humidity and Temperature Sensor, Groove


Terminal (VTI) for UART

Simulator: Proteus 8 Professional

Explanation:

HYT27 l Humidity and Temperature Sensor:

• Excellent humidity/temperature accuracy and stability


• High chemical resistance
• Wide humidity and temperature range
• Very low drift
• I 2 C protocol (address 0x28 or alternative address)
• Very stable at high humidity
• Interchangeable without adjustments

Groove Terminal (VTl) for UART:

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.

RESHU GROVER(IOT LAB EXPERIMENTS) Page 21


U.AJI.J Mod u lo:

U5 8- Serib l COflft'ttet

RX TX
; TX RI(
G NO GNO

Flowchart:
USS&±
=z S::Z:Z:33.:::S.: £ LL SU

{ .·,.. ".:."...",r.. _,)

'ti-

'"':-ix-.&r.::
, ,t .'i ':.
ar·« :;;-11,,,

{.. ._..,_ )

RESHU GROVER(JOT LAB EXPERIMENTS) Page 22


Experiment - 7

Aim: Design a flowchart weather station with Arduino.

Components: Arduino Uno, Temperature, Pressure and Humidity Sensors

Simulator: Proteus 8 Professional

Explanation:

In order to develop a weather station, we require to read the values of


temperature, pressure and humidity by using the corresponding sensors.

RESHU GROVER(IOT LAB EXPERIMENTS) Page 23


Experiment - 8

Aim: Design a Flowchart Wi-Fi based Air Quality Monitoring System.

Components: Add Peripheral-> Internet of things-> VFP server (ESP8266 Wi-Fi


module)

Simulator: Proteus

Theory:

Grove Dust Sensor module:

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.

ESP8266 Wi-Fi module:

ESP8266 is Wi-Fi enabled system on chip (SoC) module developed by


Espressif system. It is mostly used for development of IoT (Internet of
Things) embedded applications.

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----------------

RESHU GROVER(IOT LAB EXPERIMENTS) Page 24


en

RESHU GROVER(IOT LAB EXPERIMENTS) Page 25


Experiment - 9
Aim: Design a flowchart of interfacing 80 cm Infrared Proximity Sensor.

Hardware Library: ARDUINO UNO

Simulator: Proteus

Components: Add Peripheral -> Groov -> 80cm Proximity sensor module

Explanation:

Grove - 80cm Infrared Proximity Sensor:


The 80cm Infrared Proximity Sensor is a General Purpose Type Distance
Measuring Sensor. This sensor SharpGP2Y0A21 YK, boasts a small package
and very low current consumption, takes a continuous distance reading and
returns a corresponding analog voltage with ·a range of 10cm (4") to 80 cm
(30"). It can be used in TVs, personal computers, cars and so on.
- - -7= ,--f P4rr .rx c v...;p c..;1 n ·:l o p 9 4 .-p. 1 0 , 1-' 1il'-.1 4. ----:--:,,--- ,u,:z
- - -8 -
.O
..;:;
P D 5 /T 1 l0 C0 8 .P' C I N T2 1 P 8 5 /S C K 'P C I 5
' C I N • 2 :::..PS 8 ,'T OS C 1 .-X T A L 1.'PCI ·IT o
P DB /,:..1t-:O.'O C O.-'-vP
t---;:-=-----{-, 10 13 I :;-:;
----1P
D
7.'.N
1
PCll
-
.T3 P •
8, TS
L
A
.
2
C
P Cl'T
7 LY
17
Grove I,
- .6.,;,---t .C..R E F P C0 / AOC0 •P C l,, S I- ; - -{ ""'} ADO
-----=--t A\./ ::::.C P c · ..-..:..o c , .-P c 1 , 1 .;,
2 1
,; 0 1
F C 2 I A D C 2 1P C I NT 1 O AD2
P C .3 t'A O C 3 ,P' C. I T 11 z-
23
AD3
P C 4 1A C C. 4..'S D A •P C I N T 1 2
P C-5 1A D C5 .'S C L' P C I NT 1 3
P C e-/ 'R E S E T, P C I N T 1 4-
!: A D -4
AD5
RE S E T

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

i8 8 .c° . --------- , r---


I r:::::> 0-e!-;--l •- 1

t- -c==::J•t----0 10 13
iiI

RESHU GROVER(IOT LAB EXPERIMENTS) Page 26


Experiment -10
Aim: To measure distance using Ultrasonic Sensor.

Hardware Library: ARDUINO UNO

Simulator: Proteus

Components: Add Peripheral -> Groov -> Ultrasonic Sensor

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;

const int echoPin = 12;

void setup() {

Serial.begin(96 00);} void loop()

long duration, inches, cm;

pinMode(trigPin, OUTPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

RESHU GROVER(IOT LAB EXPERIMENTS) Page 27


digitalWrite(trigPin, HIGH);

delayMicroseconds(lO);

digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseln(echoPin, HIGH);

inches= microsecondsTolnches(duration);

cm= microsecondsToCentimeters(duration);

Serial.print(inches);

Serial.print("in, ");

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(l 000);

long microsecondsTolnches(long microseconds)

{return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)

{return microseconds/ 29 / 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.

Hardware Library: ARDUINO UNO

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).

· DHTl 1 sensor uses resistive humidity measurement component, and NTC


temperature measurement component.

Explanation:
Physical Connections:-

In breadboard connect DHT11 sensor

Back side: oins of sensor:- ( in breadboard vertical connections( in between) are


there)

1) VCC to 5v in Arduino board


2) DATA to pin 4 of digital pin of Arduino
3) Gnd to Gnd of Arduino board
Connect USB from lappy to Arduino

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); }

RESHU GROVER(JOT LAB EXPERIMENTS) Page 30


Experiment- 12
Aim: Design a system using Arduino where you can monitor Soil Moisture of a
plant on an IDE.

If soil moisture is less, then LED should glow.

Send a screenshot of code, connections, and output.

Hardware Library: ARDUlNO UNO

Simulator: Proteus

Components: Soil Moisture Sensor, Arduino UNO, Jumping wires, LED

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 31


Connections:

'

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:

RESHU GROVER(IOT LAB EXPERIMENTS) Page 32


RESHU GROVER(IOT LAB EXPERIMENTS) Page 33
Experiment-13

Aim: Design a system using Arduino that blinks an LED when you detect a motion
in an area on an IDE.

Write working, connections, code and expected output.

Hardware Library: ARDUINO UNO

Components: PIR Sensor, Arduino UNO, Jumping wires, LED

Theory:

"Passive Infra-Red" sensor is a "Pyroelectric IR Sensor" which generates energy


when exposed to heat. Everything emits some low level of radiation, the hotter the
object is, the more radiation is emitted. When a human or an animal (with IR
radiation wavelength of9.4 µMeter) approaches the sensors range the sensor
detects the heat in the form of infrared radiation.

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,

· Connect the VCC of the PIR sensor to the 5v pin of Arduino.

· Then connect the output pin to D13

· GND to the Ground pin of the Arduino.

· Connect the LED to the 02 pin of the Arduino.

RESHU GROVER(IOT LAB EXPERIMENTS) Page 34


· Now upload the code and test

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

RESHU GROVER(IOT LAB EXPERIMENTS) Page 35


Experiment- 14 . . . . .
Aim: Motion detection and blinking the light when the hght 1ntens1ty ts low using
Arduino.

Write working, connections, code and expected output.

Hardware Library: ARDUINO UNO

Components: PIR Sensor, LDR Sensor, Arduino UNO, Jumping wires, LED

Theory:

PIR Sensor

"Passive Infra-Red" sensor is a "Pyroelectric IR Sensor" which generates energy


when exposed to heat. Everything emits some low level of radiation, the hotter the
object is, the more radiation is emitted. When a human or an animal (with IR
radiation wavelength of 9.4µMeter) approaches the sensors range the sensor
detects the heat in the form of infrared radiation.
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.

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.

RESHU GROVER(IOT LAB EXPERIMENTS)


Page 36
Connections:
With Arduino,
· Connect the VCC of the PIR and LDR Sensor to the 5v pin of Arduino.
· Then connect the output pin of PIR to Dl3
· And connect the output pin ofLDR to D4
· Connect the GND of PIR and LDR Sensor to the GND pin of the Arduino.
· Connect the LED to the D2 pin of the Arduino.
· Now upload the code and test

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:

RESHU GROVER(IOT LAB EXPERIMENTS) Page 37


Motion detected!
Motion detected!
Motion detected!
Blinking LED since Dark
Motion detected!
Blinking LED since Dark
Motion stopped!
Motion stopped!
Motion detected!
Motion detected!
Blinking LED since Dark
Motion detected!
Motion stopped

RESHU GROVER(IOT LAB EXPERIMENTS) Page 38


Experiment - 15
Aim: Flash an LED at a given on time and off time cycle, where the two times are
taken from a
file.

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.

RESHU GROVER(IOT LAB EXPERIMENTS) Page 39

You might also like