0% found this document useful (0 votes)
151 views45 pages

IoT Applications Lab Manual IT

Uploaded by

Awanit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views45 pages

IoT Applications Lab Manual IT

Uploaded by

Awanit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

IoT APPLICATIONS

Lab Manual

DBT STAR STATUS


Department of Information Technology

Published by

Coimbatore Institute of Information Technology


#156, 3rd Floor, Kalidas Road, Ramnagar,
Coimbatore – 641009, Tamil Nadu, India.
Website: www.ciitresearch.org
All Rights Reserved.
Original English Language Edition 2021 © Copyright by Coimbatore Institute of
Information Technology.

This book may not be duplicated in any way without the express written consent of the
publisher, except in the form of brief excerpts or quotations for the purpose of review.
The information contained herein is for the personal use of the reader and may not be
incorporated in any commercial programs, other books, database, or any kind of
software without written consent of the publisher. Making copies of this book or any
portion thereof for any purpose other than your own is a violation of copyright laws.

This edition has been published by Coimbatore Institute of Information


Technology, Coimbatore.

Limits of Liability/Disclaimer of Warranty: The author and publisher have used


their effort in preparing this IoT Applications book and author makes no
representation or warranties with respect to accuracy or completeness of the contents
of this book, and specifically disclaims any implied warranties of merchantability or
fitness for any particular purpose. There are no warranties which extend beyond the
descriptions contained in this paragraph. No warranty may be created or extended by
sales representatives or written sales materials. Neither CiiT nor author shall be liable
for any loss of profit or any other commercial damage, including but limited to special,
incidental, consequential, or other damages.

Trademarks: All brand names and product names used in this book are trademarks,
registered trademarks, or trade names of their respective holders.

ISBN 978-93-89105-56-8
This book is printed in 70 gsm papers.
Printed in India by Mahasagar Technologies.

Coimbatore Institute of Information Technology,


#156, 3rd Floor, Kalidas Road, Ramnagar,
Coimbatore – 641009, Tamil Nadu, India.
Phone: 0422 – 4377821
www.ciitresearch.org

ii
Authors

Mrs. G. Sophia Reena Mrs. J. Maria Shyla


Ms. S. Karpagam

iii
Notes
**********

iv
PREFACE

The Internet of Things (IoT) refers to physical and virtual


objects that have unique identities and are connected to the internet
to provide intelligent applications that make energy, logistics,
industrial control, retail, agriculture and many other domains
“smarter”. Internet of Things is a new revolution of the Internet that
is rapidly gathering momentum driven by the advancements in
sensor networks, mobile devices, wireless communications,
networking and cloud technologies.
This promises to make “things” including consumer electronic
devices or home appliances, such as medical devices, fridge,
cameras, and sensors, part of the Internet environment. This
concept opens the doors to new innovations that will build novel
type of interactions among things and humans, and enables the
realization of smart cities, infrastructures, and services for
enhancing the quality of life and utilization of resources.
IoT as an emerging paradigm supports integration, transfer,
and analytics of data generated by smart devices (eg, sensors). IoT
envisions a new world of connected devices and humans in which
the quality of life is enhanced. The objective of the manual is to
inculcate recent technologies on students to bring out their
innovative ideas as projects. The manual is structured with Arduino
tool and the programs were written in C Language. We have chosen
to use C Language for coding where the language is known for itself
as low level language. We hope that the experiments in this manual
will enhance the student’s understanding and skills in Internet of
Things (IoT). We would like to thank DBT Star College scheme for
providing support in bringing out this lab manual.

v
Notes
**********

vi
List of Experiments

S. No Programs Page No

01 Sense the Available Networks Using Arduino 1

Measure the Distance Using Ultrasonic Sensor


02 5
and Make Led Blink Using Arduino

03 Detect the Vibration of an Object Using Arduino 9

04 Connect with the Available Wi-Fi Using Arduino 13

Sense a Finger When it is Placed on Board Using


05 17
Arduino

06 Temperature Notification Using Arduino 21

LDR to Vary the Light Intensity of LED Using


07 25
Arduino

08 MySQL Database Installation in Raspberry Pi 29

SQL Queries by Fetching Data from Database in


09 33
Raspberry Pi

Switch Light On and Off Based on the Input of


10 35
User Using Raspberry Pi

vii
Notes
**********

viii
IoT Applications

1. SENSE THE AVAILABLE NETWORKS USING ARDUINO

AIM:
To write a program to sense the available networks using
Arduino.
COMPONENTS REQUIRED:
1. WiFi Module or ESP 8266 Module.
2. Connecting cable or USB cable.
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start ->Arduino IDE -1.8.8
STEP 3: Then enter the coding in Arduino Software.
STEP 4: Compile the coding in Arduino Software.
STEP 5: Connect the USB cable to WiFi module.
STEP 6: Select tools -> select board -> Module node Mch.0.9CE ESP
1.2 modules -> select port.
STEP 7: Upload the coding in ESP Module node Mch.0.9CE and
open serial monitor to view the available networks.
STEP 8: Stop the process.
BLOCK MODULE:

Department of Information Technology 1


IoT Applications

CODING:
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
}
void loop() {
Serial.println("scan start");
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " :
"*");
delay(10);
}
}
Serial.println("");
delay(5000);
}

Department of Information Technology 2


IoT Applications

OUTPUT:

RESULT:
Thus the output for sensing the available networks using
Arduino has successfully executed.

Department of Information Technology 3


IoT Applications

Notes
**********

Department of Information Technology 4


IoT Applications

2. MEASURE THE DISTANCE USING ULTRASONIC SENSOR AND


MAKE LED BLINK USING ARDUINO
AIM:
To write a program to measure the distance using ultrasonic
sensor and make LED blink using Arduino.
COMPONENTS REQUIRED:
1. Ultra sonic sensor.
2. Jumper wires.
3. Connecting cable or USB cable.
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start ->Arduino IDE -1.8.8
STEP 3: Then enter the coding in Arduino Software.
STEP 4: Compile the coding in Arduino Software.
STEP 5: In Arduino board, connect VCC to power supply 5V and
connect to ground as in
PIN gnd and connect trig to trigpio =9, connect echo to echopin=10
using jumper wires.
STEP 6: Connect the Arduino board with USB cable to the system.
STEP 7: Select tools -> select board ->Arduino Nano -> select
processor -> AT Mega 328 p and the select port.
STEP 8: Upload the coding in Arduino board and now for the LED
to blink.
STEP 9: Then, the output will be displayed in the serial monitor.
STEP 10: Stop the process.

Department of Information Technology 5


IoT Applications

BLOCK MODULE:

CODING:
const int trigPin = 9;
const int techoPin = 10;
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop()
{
digitalWrite(trigPin, LOW);// Clears the trigPin
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);// Sets the trigPin on HIGH state for 10
micro seconds
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // distance= (Time x Speed of
Sound in Air (340 m/s))/2

Department of Information Technology 6


IoT Applications

Serial.println(distance);
delay(1000);
}
OUTPUT:

RESULT:
Thus the output for measuring the distance using ultrasonic
sensor and LED blink using Arduino has successfully executed.

Department of Information Technology 7


IoT Applications

Notes
**********

Department of Information Technology 8


IoT Applications

3. DETECT THE VIBRATION OF AN OBJECT USING


ARDUINO

AIM:
To write a program to detects the vibration of an object with
sensor using Arduino.
COMPONENTS REQUIRED:
1. Vibration sensor
2. Jumper wires
3. USB cable

ALGORITHM:
STEP 1: Start the process.
STEP 2: StartArduino.1.8.8.
STEP 3: Then enter the coding in Arduino software.
STEP 4: In Arduino board, connect vcc to power supply 5V and
connect do to analog pin A0 and connect gnd to ground gnd using
jumper wires.
STEP 5: Connect the arduino board with the USB cable to the
system.
STEP 6: Select toolsSelect boardArduino Nano gndSelect
processor AT mega 823p and then select the port.
STEP 7: Upload the coding to the Arduino board.
STEP 8: Then the output will be displayed in the serial monitor.
STEP 9: Stop the process.

Department of Information Technology 9


IoT Applications

BLOCK DIAGRAM:

CODING:
Int ledPin = 13;
Int vib=A0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(vib, INPUT); //set EP input for measurement
Serial.begin(9600); //init serial 9600
}
void loop()
{
long measurement=pulseIn (vib, HIGH);
delayMicroseconds(50);
Serial.print("VIB:v001:hertz: " );
Serial.println(measurement);
}

Department of Information Technology 10


IoT Applications

OUTPUT:

RESULT:
Thus the output for detecting the vibrations of an object with
vibration sensor using Arduino has been successfully executed.

Department of Information Technology 11


IoT Applications

Notes
**********

Department of Information Technology 12


IoT Applications

4. CONNECT WITH THE AVAILABLE WI-FI USING ARDUINO


AIM:
To write a program to connect with the available Wi-Fi using
Arduino
COMPONENTS REQUIRED:
1. ESP 8266 module or Wi-Fi module
2. Connecting cables or USB cables
ALGORITHM:
STEP1: Start the process.
STEP2: StartArduino IDE 1.8.8.
STEP3: Include the file directory ESP 8266 in Arduino.
STEP4: Then enter the coding to Wi-Fi module or ESP 8266 module.
STEP5: Then enter the coding in Arduino software.
STEP6: Connect the USB cable to the Wi-Fi module and the
Arduino connected system with available network.
STEP7: Select toolsSelect boardNode MCU 0.9C ESP-12 module
and then SelectPort.
STEP8: Upload the coding to ESP 8266 module and open serial
monitor to View the available network connects IP address.
STEP9: Stop the process.
BLOCK DIAGRAM:

Department of Information Technology 13


IoT Applications

CODING:
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "Error"; // The SSID (name) of the Wi-Fi network
you want to connect to
const char* password = "networkerror"; // The password of the Wi-
Fi network
void setup() {
Serial.begin(115200); // Start the Serial communication to send
messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.print(“...")
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to
connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
void loop() {
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266
to the computer
}
}

Department of Information Technology 14


IoT Applications

OUTPUT:

RESULT:
Thus the output for connecting with the available Wi-Fi using
Arduino has been successfully executed.

Department of Information Technology 15


IoT Applications

Notes
**********

Department of Information Technology 16


IoT Applications

5. SENSE A FINGER WHEN IT IS PLACED ON BOARD USING


ARDUINO
AIM:
To write a program to sense a finger when it is placed on the
board Arduino.
COMPONENTS REQUIRED:
1. Touch Sensor
2. Jumper wire
3. USB cable
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start Arduino 1.8.8
STEP 3: Then enter the coding in arduino software.
STEP 4: Compile the coding in the arduino software.
STEP 5: In arduino board, connect VCC to power supply 5v and
connect SIG to Electrical signal DT and connect to ground and wing
jumper wires.
STEP 6: Connect the arduino board with USB cable to the system.
STEP 7: Select tools Select processor board and port.
STEP 8: Upload the coding to arduino board. Then the output will
be displayed in the serial monitor.
STEP 9: Stop the process.

Department of Information Technology 17


IoT Applications

BLOCK DIAGRAM:

CODING:
int Led = 13 ; // define LED Interface
int buttonpin = 7; // define Metal Touch Sensor Interface
int val ; // define numeric variables val
void setup ()
{
Serial.begin(9600);
pinMode (Led, OUTPUT) ; // define LED as output interface
pinMode (buttonpin, INPUT) ; // define metal touch sensor output
interface
}
void loop ()
{
val = digitalRead (buttonpin) ;
//Serial.println(val);
if (val == 1) // When the metal touch sensor detects a signal, LED
flashes

Department of Information Technology 18


IoT Applications

{
digitalWrite (Led, HIGH);
Serial.println(val);
delay(1000);
}
else
{
digitalWrite(Led,LOW);
Serial.println(val);
delay(1000);
}
}
OUTPUT:

RESULT:
Thus the output for sensing a finger when it is placed in board
Arduino has been successfully executed.

Department of Information Technology 19


IoT Applications

Notes
**********

Department of Information Technology 20


IoT Applications

6. TEMPERATURE NOTIFICATION USING ARDUINO


AIM:
To write a program to get temperature notification using
Arduino.
COMPONENTS REQUIRED:
1. Temperature and humidity sensor.
2. Jumper wires
3. Connectivity cable or USB cable.
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start Arduino 1.8.8
STEP 3: Include the DHT library to the Arduino software.
STEP 4: Then enter the coding in Arduino software.
STEP 5: Complete the coding in Arduino.
STEP 6: In Arduino board connect VCC to the power supply 5V and
connect SIG to digital signal DT and connect SND to ground GND
using jumper wires.
STEP 7: Connect the arduino board with USB cable to the system.
STEP 8: Select tools  Selected.
STEP 9: Upload the coding to arduino board. Then the output will
be displayed in the serial monitor.
STEP 10: Stop the process.

Department of Information Technology 21


IoT Applications

BLOCK DIAGRAM:

CODING:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
delay(500);
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);
}
void loop()
{
DHT.read11(dht_apin);
Serial.print("THS:th01:None:");
Serial.print(DHT.humidity);
Serial.print("%,");

Department of Information Technology 22


IoT Applications

//Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("degC");
delay(2000);//Wait 5 seconds before accessing sensor again.
}

OUTPUT:

RESULT:
Thus the output to get temperature notification using Arduino
has successfully executed.

Department of Information Technology 23


IoT Applications

Notes
**********

Department of Information Technology 24


IoT Applications

7. LDR TO VARY THE LIGHT INTENSITY OF LED USING


ARDUINO
AIM:
To write a program for LDR to vary the light intensity of LED
using Arduino.
ALGORITHM:
STEP1: Start the program.
STEP2: Start →Arduino 1.88[IDE].
STEP3: Enter the coding in Arduino software.
STEP4: Compile the coding in the Arduino software.
STEP5: From LDR light sensor module, connect VCC to power
supply 5V and connect to digital pin D3 and connect GND to
ground gnd using jumper wires to arduino board.
STEP6: For LED, connect D to digital pin D2 and connect GND to
ground GND using jumper wires to arduino board.
STEP7: Show the variance of lights intensity in LED we use LDR
light sensor module.
STEP8: Stop the process.

Department of Information Technology 25


IoT Applications

CODING:
const int ldr_pin = 3;
const int led_pin = 2;
void setup() {
pinMode(ldr_pin, INPUT);
pinMode(led_pin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if ( digitalRead( ldr_pin ) == 1) {
digitalWrite(led_pin, HIGH);
}
else {
digitalWrite(led_pin , LOW);
}
Serial.println(digitalRead( ldr_pin ));
delay(100);
}
OUTPUT:

Department of Information Technology 26


IoT Applications

LED OUTPUT:
LED OFF

LED ON

RESULT:
Thus the output for LDR to vary the light intensity of LED using
Arduino has successfully executed.

Department of Information Technology 27


IoT Applications

Notes
**********

Department of Information Technology 28


IoT Applications

8. MYSQL DATABASE INSTALLATION IN RASPBERRY PI


AIM:
To write a program to install MySQL database in Raspberry pi.
COMPONENTS REQUIRED:
1. Raspberrypi
2. HDMI
3. Micro USB power input
ALGORITHM:
STEP1: Start the process
STEP2: Connect micro USB power input to Raspberry pi.
STEP3: Connect HDMI to the system to act as monitor for
Raspberry pi.
STEP4: Connect USB port to mouse and keyboard.
STEP5: then enter the coding in terminal for installing MySQL to
Raspberry pi.
STEP6: stop the process.
CODING:
sudo apt-get install mysql-server
sudo apt update
sudo apt upgrade
sudo apt install mariadb-server
sudomysql_secure_installation
sudomysql -u root –p
OUTPUT:

Department of Information Technology 29


IoT Applications

Department of Information Technology 30


IoT Applications

RESULT:
Thus the output to install MySQL database in Raspberry pi has
successfully executed.

Department of Information Technology 31


IoT Applications

Notes
**********

Department of Information Technology 32


IoT Applications

9. SQL QUERIES BY FETCHING DATA FROM DATABASE IN


RASPBERRY PI
AIM:
To write a program to work with basic MySQL queries by
fetching data from database in Raspberry pi.
COMPONENTS REQUIRED:
1. Raspberry pi
2. HDMI
3. Micro USB power input
ALGORITHM:
STEP1: Start the process.
STEP2: Connect micro USB power input to Raspberry pi.
STEP3: Connect HDMI to the system to act as monitor for
Raspberry pi.
STEP4: Connect USB port 2.0 to mouse and keyboard.
STEP5: When enter the coding in the terminal to update and
upgrade package using commands.
STEP6: Create database in MySQL and basic SQL queries by
fetching data from database by using insert, update and delete
queries.
STEP7: Stop the process.
CODING:
sudomysql -u root –p
CREATE DATABASE exampledb;
CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY
'pimylifeup';
CREATE TABLE Books(Id INTEGER PRIMARY KEY, Title
VARCHAR(100),
Author VARCHAR(60));

INSERT INTO Books(Title, Author) VALUES (1,‘War and Peace’,

Department of Information Technology 33


IoT Applications

‘Leo Tolstoy’);
SELECT * FROM Books;

UPDATE Books SET Author='Lev Nikolayevich Tolstoy'


WHERE Id=1;

DELETE FROM Books2 WHERE Id=1;


OUTPUT:
| Id | Title | Author |
+----+---------------+-------------+
+----+---------------+-------------+

+----+---------------+-------------+
| Id | Title | Author |
+----+---------------+-------------+
| 1 | War and Peace | Leo Tolstoy |
+----+---------------+-------------+

+----+---------------+--------------------------+
| Id | Title | Author |
+----+---------------+--------------------------+
| 1 | War and Peace | Lev Nikolayevich Tolstoy |
+----+---------------+--------------------------+

| Id | Title | Author |
+----+---------------+-------------+
+----+---------------+-------------+

RESULT:
The output to fetch data from database using SQL queries in
Raspberry pi has successfully executed.

Department of Information Technology 34


IoT Applications

10. SWITCH LIGHT ON AND OFF BASED ON THE INPUT OF


USER USING RASPBERRY PI
AIM:
To write a program to switch light on when the input is 1 and
switch the light off when the input is 0 using Raspberry pi.
COMPONENTS REQUIRED:
1. Raspberry pi
2. Breadboard
3. Jumperwires
4. Resistor
5. LED
ALGORITHM:
STEP1: Start the process.
STEP2: Connect micro USB power input to Raspberry pi
STEP3: Connect HDMI to the system to act as monitor for
Raspberry pi.
STEP4: Connect USB port 2.0 to mouse and keyboard.
STEP5: Enter the coding in the terminal for installing python and
GPTO.
STEP6: Open notepa →enter coding →save as →file extension
python or py.
STEP7: Copy file location → open terminal → paste file location in
terminal → press enter.
STEP8: In the terminal window to get output enter 0 or 1, to switch
light ON when the input is 1 and switch light OFF when the input is
0 in breadboard using Raspberry pi.
STEP9: Stop the process.
CODING:
sudo apt-get install python-pip
sudo apt-get install python-dev
sudo pip install RPi.GPIO

Department of Information Technology 35


IoT Applications

sudo –i
#python
importRPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
ip=int(input("enter the value: "))
ifip==1:
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
elifip==0:
print "LED off"
GPIO.output(18,GPIO.LOW)
time.sleep(1)
OUTPUT:

Department of Information Technology 36


IoT Applications

RESULT:
Thus the output to switch light ON/OFF using Raspberry pi has
been successfully executed.

Department of Information Technology 37

You might also like