IoT Applications Lab Manual IT
IoT Applications Lab Manual IT
Lab Manual
Published by
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.
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.
ii
Authors
iii
Notes
**********
iv
PREFACE
v
Notes
**********
vi
List of Experiments
S. No Programs Page No
vii
Notes
**********
viii
IoT Applications
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:
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);
}
OUTPUT:
RESULT:
Thus the output for sensing the available networks using
Arduino has successfully executed.
Notes
**********
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
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.
Notes
**********
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: StartArduino.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 toolsSelect boardArduino Nano gndSelect
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.
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);
}
OUTPUT:
RESULT:
Thus the output for detecting the vibrations of an object with
vibration sensor using Arduino has been successfully executed.
Notes
**********
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
}
}
OUTPUT:
RESULT:
Thus the output for connecting with the available Wi-Fi using
Arduino has been successfully executed.
Notes
**********
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
{
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.
Notes
**********
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("%,");
//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.
Notes
**********
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:
LED OUTPUT:
LED OFF
LED ON
RESULT:
Thus the output for LDR to vary the light intensity of LED using
Arduino has successfully executed.
Notes
**********
RESULT:
Thus the output to install MySQL database in Raspberry pi has
successfully executed.
Notes
**********
‘Leo Tolstoy’);
SELECT * FROM Books;
+----+---------------+-------------+
| 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.
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:
RESULT:
Thus the output to switch light ON/OFF using Raspberry pi has
been successfully executed.