iot lab
iot lab
No : 01
Date : To Study various IoT Protocols – 6LowPAN, IPv4/IPv6,
Wifi , Bluetooth, MQTT
AIM:
6LowPAN:
6LoWPAN stands for IPv6 over Low-power Wireless Personal Area Networks. It is a
standard protocol for realizing IPv6 communication on wireless networks composed of low power
wireless modules. 6LoWPAN specification contains packet compression and other optimization
mechanisms to enable the efficient transmission of IPv6 packets on a network with limited power
resources and reliability, which makes efficient IPv6 communication over low-power wireless
networks possible.
IPv4 / IPv6:
IPv4 :
The IPv4 address is a 32-bit number that uniquely identifies a network interface on a machine.
An IPv4 address is typically written in decimal digits, formatted as fou8-bit fields that are separated by
periods. Each 8-bit field represents a byte of the IPv4 address.
IPv6 :
IP v6 was developed by Internet Engineering Task Force(IETF)to deal with the problem of IP
v4 exhaustion. IP v6 is a 128-bits address having an address space of 2^128, which is way bigger than
IPv4. In IPv6 we use Colon-Hexa representation. There are 8 groups and each group represents 2
Bytes.
WiFi:
Wi-Fi is a wireless technology used to connect computers, tablets, smartphone and other
devices to the internet. Wi-Fi is the radio signal sent from a wire router to a nearby device, which
translates the signal into data you can see and use. The device transmits a radio signal back to the
router, which connects to the internet by wire or cable.
Bluetooth:
RESULT:
AIM :
To develop IoT Application Using sensors and actuators (temperature sensor, light sensor,
infrared sensor)
REQUIREMENTS:
2. Temperature sensor
CONNECTION:
• Power to 5V
• Vout to A1
• GND to GND
PROCEDURE:
STEP 1: Set up the Arduino and temperature sensor, light sensor, infrared sensor
STEP 3: Next select correct board and port set the band rate (9600).
STEP 4: Finally compile your code and upload the code into Arduino board.
float temp;
int tempPin = 0;
void setup() {
Serial.begin(9600);
void loop() {
temp = analogRead(tempPin);
Serial.print("TEMPERATURE = ");
Serial.print("*C");
Serial.println();
delay(1000);
}
DIAGRAM:
OUTPUT :
LIGHT SENSOR :
REQUIREMENT :
2. Light sensor
CONNECTION :
• VCC - 5v
• GND – GND
• OUT – Digital or analog pin
PROGRAM :
void setup() {
Serial.begin(9600);
void loop() {
Serial.println(" - Dark");
Serial.println(" - Dim");
Serial.println(" - Light");
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
delay(500);
DIAGRAM :
OUTPUT :
INFRARED SENSOR:
REQUIREMENT :
2. Infrared sensor
CONNECTION :
• VCC - 5v
• GND – GND
PROGRAM :
void setup() {
void loop() {
Serial.println("Motion Ended!");
}
else{
Serial.println("Motion Detected!");
DIAGRAM :
OUTPUT :
RESULT:
AIM:
REQUIREMENT :
2. LED light
3. Resistor
CONNECTION :
PROCEDURE :
STEP 1: Set up the Arduino and LED connect pin followed by the respective connections.
STEP 3: Next select correct board and port set the band rate (9600).
STEP 4: Finally compile your code and upload the code into Arduino board.
pinMode(2, OUTPUT);
void loop() {
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
}
DIAGRAM :
RESULT:
AIM :
To develop an application to send and receive data with Arduino using HTTP request
REQUIREMENT :
1. ESP32 Board
REQUIRED LIBRARIES :
• WiFi
• HttpClient
PROCEDURE :
STEP 1: Start the program and connected the ESP32 via USB cable into the system.
STEP 3: Run the POST method program and you will post your detail into the
respective/repository.
STEP 4: While upload the program long press the boot button on ESP32.
STEP 5: Run the GET method program and you will get the respect the id value
details.
#include <WiFi.h>
#include <HTTPClient.h>
// Wi-Fi credentials
void setup() {
Serial.begin(115200);
delay(4000);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
delay(1000);
Serial.print(".");
Serial.println("\nConnected to WiFi");
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (httpResponseCode > 0) {
} else {
http.begin(client, serverNamePOST); // Specify the client and URL for POST request
if (httpResponseCode > 0) {
} else {
}
OUTPUT :
RESULT :
To develop an application that measures the room temperature and posts the temperature value
on the cloud platform.
HARDWARE REQUIRED:
2. DHT11 Sensor
3. Connecting Wires
SOFTWARE REQUIRED:
1. Google Firebase
2. Arduino IDE
CONNECTIONS:
• Gnd – gnd
• Data – D14
• Vcc – 3v3
REQUIRED LIBRARIES :
PROCEDURE :
STEP 1: get up the ESP32 and DHT11 connect to the correct pins followed by the
respective connections.
STEP 2: Create database on Google Firebase and connect the firebase with the board using
Firebase host and Firebase authentication key.
STEP 3: Now run the program, You can see the output in serial monitor and also in google
firebase Cloud.
FIREBASE CLOUD INSTRUCTIONS :
• You will be redirected to a new web page with the welcome message. Click the button
‘Create a Project’
• Write the name of your project. Remember to tick the Firebase term agreement. Now click
‘Continue’.
• Go to the settings icon and click ‘Project Settings’., Now, go to ‘Service Accounts’ and click
‘Generate new private key’. copy it then paste it in code.
• Next, Under the Build tab go to ‘Realtime Database.’ Then click ‘Create Database.’after that
you will see the host link, then copy that then paste it in code.
PROGRAM :
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#include <DHT.h>
// WiFi credentials
// Firebase setup
FirebaseData firebaseData;
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;
// DHT Sensor setup
void setup() {
Serial.begin(115200);
delay(4000);
dht.begin();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
delay(1000);
Serial.println("Connecting to WiFi...");
Serial.println("Connected to WiFi");
// Set up Firebase
firebaseConfig.database_url = FIREBASE_HOST;
firebaseAuth.token.uid = FIREBASE_AUTH;
Firebase.begin(&firebaseConfig, &firebaseAuth);
Serial.println("Firebase initialized");
void loop() {
if (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Reconnecting to WiFi...");
Serial.println("Reconnected to WiFi");
if (isnan(temperature) || isnan(humidity)) {
return;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(humidity);
Serial.println(" %");
} else {
} else {
DIAGRAM :
OUTPUT :
AIM :
To develop an application that measures the moisture of soil and post the sensed data over
Google firebase cloud platform.
REQUIREMENTS:
● ESP32 Board
● Cables
CONECTION:
● Vcc – 5v
● Gnd – gnd
● A0 – A0
● D0 - (SKIP THIS)
REQUIRED LIBRARIES :
• FirebaseESP8266
• ESP8266WiFi
PROCEDURE :
STEP 1 : get up the ESP32 and soil moisture sensor and connect to the correct pins followed by
the respective connections.
STEP 2 : Create database on Google Firebase and connect the firebase with the board using
Firebase host and Firebase authentication key
STEP 3 : Now run the program, You can see the output in serial monitor and also in google
firebase Cloud.
PROGRAM :
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
FirebaseData firebaseData;
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
delay(500);
Serial.print(".");
Serial.println("Connected!");
// Start Firebase
Serial.println("Firebase initialized.");
void loop() {
Serial.println(soilMoistureValue);
} else {
Serial.println(firebaseData.errorReason());
delay(1000);
}
DIAGRAM :
OUTPUT :
To develop an application for measuring the distance using ultrasonic sensor and post
REQUIREMENT:
1. ESP32
2. Ultrasonic sensor
CONNECTIONS:
• Vcc – vin
• Trig – d5
• Echo d18
• Gnd – gnd
REQUIRED LIBRARIES :
• ESP8266WiFi
• FirebaseArduino
PROCEDURE:
STEP 1 : get up the ESP8266 and Ultrasonic sensor and connect to the correct pins
STEP 2 : Create database on Google Firebase and connect the firebase with the board
STEP 3 : Now run the program, You can see the output in serial monitor and also in
#include <FirebaseESP8266.h>
#include <ESP8266WiFi.h>
// Firebase configuration
FirebaseData firebaseData;
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;
void setup() {
Serial.begin(115200);
// Wi-Fi connection
WiFi.begin("BARANI", "barani123");
delay(1000);
Serial.println("Connecting to WiFi...");
Serial.println("Connected to WiFi");
// Firebase configuration
firebaseConfig.database_url = FIREBASE_HOST;
Firebase.begin(&firebaseConfig, &firebaseAuth);
Serial.println("Firebase initialized");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
} else {
void loop() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
delay(1000);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
} else {
}
DIAGRAM :
OUTPUT :
GOOGLE FIREBASE OUTPUT :
RESULT :
AIM :
REQUIREMENTS:
1. Arduino UNO.
2. Bread board.
3. Ultrasonic sensor.
4. Bluetooth module(HC05).
PROCEDURE :
STEP 1 : Download the app using the link and install the app in your mobile.
https://drive.google.com/file/d/1balZJrsXkquxb7OoNgbUSdCWFh47muoH/view?usp
=share_link
STEP 3 : Now run and upload the program into arduino then open your mobile and
open the Bluetooth and click the HC05 and enter 1234 as a password.
STEP 4 : Open the app in your mobile and click the click to connect and now select
STEP 5 : That’s it connected this is message was showed in your app now you put the
object infront of ultrasonic sensor the sensor give a correct distance in cm.
PROGRAM :
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
distance= duration*0.034/2;
Serial.print("Distance in cm : ");
Serial.println(distance);
}
OUTPUT :
RESULT :
HARDWARE REQUIRED:
2. DHT11 Sensor
3. Connecting Wires
SOFTWARE REQUIRED:
1. Google Firebase
2. Arduino IDE
CONNECTIONS:
• Gnd – gnd
• Data – D14
• Vcc – 3v3
REQUIRED LIBRARIES :
In Arduino IDE ,Open the library manager then install the following libraries ,
2. FirebaseESP32.h
PROCEDURE :
STEP 1 : First create Arduino file and install the required libraries
STEP 2 : And type the code in the file and select correct board name and port
‘Service Accounts’ and click ‘Database Secrets’ .copy it then paste it in code.
STEP 6 : Next, Under the Build tab go to ‘Realtime Database.’ Then click ‘Create
Database.’after that you will see the host link,then copy that then paste it in code.
1. urls.py
2. views.py
3. Home.py
• Goto project settings in firebase and scroll down you will see the lot of codes and
choose and copy the config block and paste it into views.py config block.
• Finally create the local host server ,this open to get the humidity and temperature
value.
• First create a database into firebase and next click the following icon(</>)
• Give a nickname to your Web Project and Click On Register App
• Now you will see the configuration of your App like this. Copy this Code
following comments
virtualenv env_site
cd env_site
• open pycharm or vscode and open the correct folder where your Django files contain like this
• Create a views.py file in your project directly. The Structure should be like this .
• Next edit only urls.py no need to create it the file and type this code.
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
• Next create views.py into projectname folder it and types this code.
from django.shortcuts import render
import pyrebase
config={
"apiKey": "AIzaSyAC6MeF1tqIOEQwwLptWtFCg8t2Z4reB0o",
"authDomain": "dht11-f5b71.firebaseapp.com",
"databaseURL": "https://dht11-f5b71-default-rtdb.firebaseio.com",
"projectId": "dht11-f5b71",
"storageBucket": "dht11-f5b71.appspot.com",
"messagingSenderId": "550162327226",
"appId": "1:550162327226:web:b8a4593bc436431a350483",
"measurementId": "G-THS4J3Y3PD"
firebase=pyrebase.initialize_app(config)
authe = firebase.auth()
database=firebase.database()
def home(request):
HUMIDITY=database.child('ESP32_APP').child('HUMIDITY').get().val()
TEMPERATURE=database.child('ESP32_APP').child('TEMPERATURE').get().val()
return
render(request,"Home.html",{"HUMIDITY":HUMIDITY,"TEMPERATURE":TEMP
ERATURE})
• Here change the config section as per your firebase config file.
C:\Users\rohit\env_site\project_name
Like this
• Next create Home.html file inside the templates folder and type this code into it
HOME.HTML
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<H1>
<meta charset="UTF-8">
<title>Sample Project</title>
</H1>
<br/>
<h2>
</h2>
<br>
</body>
</html>
• Next open setting.py and do a one edit into it first goto 79th line in
setting.py file and copy the NAME field value and paste into 57th line
• Now everything is ready lets run the server Now move to your project directory
• It will give the localhost address and copy the webaddress and paste into browser
you will get the output this take the value from firebase.
OUTPUT :
RESULT :
Thus the program has been verified and output is executed successfully.