0% found this document useful (0 votes)
142 views27 pages

Iot Labrecord 541

1) The document is an Internet of Things (IoT) laboratory record belonging to a student. It contains 7 experiments conducted using devices like ESP32, DHT11 sensor, ultrasonic sensor, and cloud services like ThingSpeak. 2) The experiments include blinking an LED, reading temperature and humidity using DHT11 and displaying on serial monitor, measuring distance using ultrasonic sensor, controlling lights via Bluetooth and WiFi, and retrieving and uploading data to ThingSpeak cloud. 3) The record contains circuit diagrams, code snippets, objectives, and outcomes for each experiment.

Uploaded by

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

Iot Labrecord 541

1) The document is an Internet of Things (IoT) laboratory record belonging to a student. It contains 7 experiments conducted using devices like ESP32, DHT11 sensor, ultrasonic sensor, and cloud services like ThingSpeak. 2) The experiments include blinking an LED, reading temperature and humidity using DHT11 and displaying on serial monitor, measuring distance using ultrasonic sensor, controlling lights via Bluetooth and WiFi, and retrieving and uploading data to ThingSpeak cloud. 3) The record contains circuit diagrams, code snippets, objectives, and outcomes for each experiment.

Uploaded by

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

S.R.K.

R ENGINEERING COLLEGE(A)
( Affiliated to JNTU, KAKINADA )
DEPARTMENT OF COMPUTER SCIENCE
ENGINEERING CHINAAMIRAM::BHIMAVARAM-534204
(2020-2021)

INTERNET OF THINGS
LABORATORY RECORD

Name : Velagaleti Poornima


Reg No : 18B95A0541
Year : IVth
Sem : Ist SEM
Branch : CSE

.
INDEX

S. NO TITLE PG. NO
1 Design an IOT System for LED blinking. 2

2 Read Temperature and Humidity using DHT11 Sensor and display it 4


on Serial Monitor using ESP32.
3 Read Distance in cm or meter using Ultrasonic Sensor and display it 6
on Serial Monitor using ESP32.
4 Design an IOT System and an App to ON/OFF lights using Bluetooth 8
technology.

5 Design an IOT System and an App to ON/OFF lights using WIFI 12


technology.
6 Design IOT System and an App to retrieve data (Temperature and 16
Humidity) from cloud (ThinkSpeak).

7 Design IOT System to Upload data (Temperature and Humidity) to 21


cloud (ThinkSpeak).

Signature of Lab Incharge

1
Experiment -1: Design an IOT System for LED blinking.

Aim: To study the applications and usage of ESP32 board for designing Internet of Things (IOT)
applications.
Objectives: Student should get the knowledge and usage of IOT devices such as ESP32 Board.
Outcomes: Student will be aware of the device connections and usage of IOT devices such as
ESP32 Board.
CODE:
const int ledpin1 =2;

cons tint ledpin2 = 4;


void setup() {
// setup pin 2 & 4 as a digital output pin
pinMode (ledPin1, OUTPUT);
pinMode (ledPin2, OUTPUT);
}
void loop()
{
digitalWrite (ledPin1, HIGH); // turn on the LED
delay(500); // wait for half a second or 500 milliseconds
digitalWrite (ledPin1, LOW); // turn off the LED
delay(500); // wait for half a second or 500 milliseconds
digitalWrite (ledPin2, HIGH); // turn on the LED
delay(500); // wait for half a second or 500 milliseconds
digitalWrite (ledPin2, LOW); // turn off the LED
delay(500); // wait for half a second or 500 milliseconds
}
Experiment -2: Read Temperature and Humidity using DHT11 Sensor and display
it on Serial Monitor using ESP32.

Aim: To study the applications and usage of ESP32 Board and DHT11 Sensor.
Objectives: Student should get the knowledge and usage of ESP32 Board and DHT11 Sensor.
Outcomes: Student will be aware of the device connections and usage of IOT devices such as
ESP32 and DHT11 Sensor.

Block Diagram:
Code :
#include "DHT.h"
#define DHTPIN 4 // Digital pin connected to the DHT
sensor #define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
}
Experiment -3: Read Distance in cm or meter using Ultrasonic Sensor and display
it on Serial Monitor using ESP32.

Aim: To study the applications and usage of ESP32 Board and UltraSonic Sensor.
Objectives: Student should get the knowledge and usage of ESP32 Board and UltraSonic Sensor.
Outcomes: Student will be aware of the device connections and usage of IOT devices such as
ESP32 and UltraSonic Sensor.

Hardware Recommended:
s. no Devices/Sensors Qty, No
1 ESP32 Board 1
2 Basic Shield 1
3 Ultrasonic Sensor 1
4 Connecting Wires 10

Block Diagram:
Code:
#include "NewPing.h" // include NewPing library
// for ESP32 microcontroller
int trigPin = 4; // trigger pin
int echoPin = 0; // echo pin
NewPing sonar(trigPin, echoPin);
void setup()
{
Serial.begin(9600);
}
void loop()
{
float distance = sonar.ping_median(5);
if(distance>400 || distance<2)
Serial.println("Out of range");
else{ Serial.print("Distanc
e: ");
Serial.print(distance, 1);
Serial.println(" cm");
}
delay(50);
}
Experiment -4: Design an IOT System and an App to ON/OFF lights using
Bluetooth technology.

Aim: To study the applications of Bluetooth in Internet of Things (IoT) where to


connect the Bluetooth to devices for authentication and send the commands to operate
the appliances as per the requirements and the state of Bluetooth is enabled by
programming.

Objectives: Student should get the knowledge of Bluetooth communication devices by


designing Mobile App.

Outcomes: Student will be aware of communication by the Bluetooth background


devices by using Mobile App.

Hardware Recommended:

S.No. Devices/Sensors Qty, Nos.


1 ESP32 Development Kit 1
2 Basic Shield of SB 1
3 Connecting wires 10

Block Diagram:
Bluetooth App design: (MIT APP INVENTOR TOOL)
Code:
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String state;
void setup()
{ pinMode(2,
OUTPUT); pinMode(4,
OUTPUT);
Serial.begin(115200);
SerialBT.begin("chandu"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
if (Serial.available())
{
SerialBT.write(Serial.read());
Serial.println("hello");
}
if (SerialBT.available()) {
state=SerialBT.read();
Serial.print("State :");
Serial.println(state);
if (state.equals("55"))
{ digitalWrite(2, HIGH);
Serial.println("Light On");
}
// if the state is 'LED1OFF' the led1 will turn off
else if (state.equals("49")){
digitalWrite(2, LOW);
Serial.println("Light Off");
}
// if the state is 'LED2ON' the Led2 will turn on
else if (state.equals("57")){
digitalWrite(4, HIGH);
Serial.println("AC On");
}
}
state="";
delay(200);
}
Experiment -5: Design an IOT System and an App to ON/OFF lights using WIFI
technology.

Aim: To study the various applications of Wireless Fidelity (Wi-Fi) in Internet of Things (IoT)
by fetching the data from sensors and relay kit where such in a case by using HTTP protocol the
information is being transferred within the devices and the devices are operated automatically.
Objectives: Student should get the knowledge of Wi-Fi communication devices by Designing
Mobile App to ON or OFF light.
Outcomes: Student will be aware of communication using Wi-Fi background devices buy using
Mobile App.

Hardware Recommended:

S.No. Devices/Sensors Qty, Nos.


1 ESP32 Hardware Development 1
Board
2 Basic Shield of SB 1
3 Connecting wires 15
4 2 channel Relay Board 1

Block Diagram:
WiFi App design(using MIT App inventor Tool):
Code:
#include <ThingSpeak.h>
#include <WiFi.h>
WiFiClient client;
const char* ssid = "ONLYCSE";//Enter the ssid of your router
const char* password = "keepsmile";//Enter the password of your router
const char* host = "api.thingspeak.com";
const char* privateKey = "UOZ3XFFHY6J345IO";//read key
const char* privateKey1 = "9HO22G0EY0D8XYD4";//write key
void setup() {
Serial.begin(115200);
ThingSpeak.begin(client);
delay(10);
Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED){ delay(500);
Serial.print(".");
Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
float h= ThingSpeak.readFloatField( 626040,2); int d= ThingSpeak.readIntField( 626082,1);
Serial.print(d);
if(d==1)
{ digitalWrite(4,HIGH);
Serial.print("LED ON");
Serial.println("");
}
if(d==0)
{ digitalWrite(4,LOW);
Serial.print("LED OFF");
Serial.println("");
}
delay(1000);
}
Experiment -6: Design IOT System and an App to retrieve data (Temperature and
Humidity) from cloud (ThinkSpeak).

Aim: To study the various applications of Wireless Fidelity (Wi-Fi) in Internet of


Things (IoT)by fetching the data from sensors and relay kit where such in a case by
using HTTP protocol, the information is being transferred within the devices and the
devices are operated automatically.

Objectives: Student should get the knowledge of Wi-Fi communication devices by


Designing Mobile App.

Outcomes: Student will be aware of communication using Wi-Fi background devices buy
using Mobile App
Hardware Recommended:

S.No. Devices/Sensors Qty, Nos.


1 ESP32 Hardware Development 1
Board
2 Basic Shield of SB 1
3 Connecting wires 15

Block Diagram:
App designing (using MIT inventor Tool): To display temperature and humidity
Code:
#include <WiFi.h>
#include "DHT.h"
#define DHTPIN 4 // what pin we're connected to
#define DHTTYPE DHT11 // define type of sensor DHT 11
DHT dht (DHTPIN, DHTTYPE);
const char* ssid = "JioFi4_134EAC";//Enter the ssid of your router
const char* password = "cp19qexyh5";//Enter the password of your router
const char* host = "api.thingspeak.com";
const char* privateKey = "SYANE5W2LLUBYMGT";//read key
const char* privateKey1 = "TUEKQN0T47U4KA15";//write key
String line,line1;
float h,t;
void setup()
{ Serial.begin(115200);
pinMode(light, OUTPUT);//setting led as output
pinMode(fan, OUTPUT);//setting led as output
dht.begin();
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{ delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop(){
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print("temperature:");
Serial.println(t);
Serial.print("Humidity:");
Serial.println(h);
delay(10000);
retrieve_from_Cloud();
delay(10000);
}
void retrieve_from_Cloud()
{ Serial.print("connecting to ");
Serial.println(host); // Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}// We now create a URI for the request
String url1 = "/channels/539141";
url1 += "/fields/3/last?";
url1 += "api_key=";
url1 += privateKey;
Serial.print("Requesting URL: ");
Serial.println(url1); // This will send the request to the server
client.print(String("GET ") + url1 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1000);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
if(client.find("@")){
line = client.readString();
Serial.print(line);
}
}
Serial.println();
Serial.println("closing connection");
}
Experiment -7: Design IOT System and an App to upload data (Temperature and
Humidity) from cloud (ThinkSpeak).

Aim: To study the various applications of Wireless Fidelity (Wi-Fi) in Internet of


Things (IoT)by fetching the data from sensors and relay kit where such in a case by
using HTTP protocol, the information is being transferred within the devices and the
devices are operated automatically.

Objectives: Student should get the knowledge of Wi-Fi communication devices by


Designing Mobile App.

Outcomes: Student will be aware of communication using Wi-Fi background devices buy
using Mobile App
Hardware Recommended:

S.No. Devices/Sensors Qty, Nos.


1 ESP32 Hardware Development 1
Board
2 Basic Shield of SB 1
3 Connecting wires 15

Block Diagram:
App designing (using MIT inventor Tool): To display temperature and humidity
Code:
#include <WiFi.h>
#include "DHT.h"
#define DHTPIN 4 // what pin we're connected to
#define DHTTYPE DHT11 // define type of sensor DHT 11
DHT dht (DHTPIN, DHTTYPE);
const char* ssid = "JioFi4_134EAC";//Enter the ssid of your router
const char* password = "cp19qexyh5";//Enter the password of your router
const char* host = "api.thingspeak.com";
const char* privateKey = "SYANE5W2LLUBYMGT";//read key
const char* privateKey1 = "TUEKQN0T47U4KA15";//write key
String line,line1;
float h,t;
void setup()
{ Serial.begin(115200);
pinMode(light, OUTPUT);//setting led as output
pinMode(fan, OUTPUT);//setting led as output
dht.begin();
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{ delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop(){
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print("temperature:");
Serial.println(t);
Serial.print("Humidity:");
Serial.println(h);
delay(10000);
retrieve_from_Cloud();
delay(10000);
}

void upload()
{ Serial.print("connecting to ");
Serial.println(host); // Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort))
{ Serial.println("connection failed");
return;
}// We now create a URI for the request
String url = "/update";
url += "?api_key=";
url += privateKey1;
url += "&field1=";
url += t;
url += "&field2=";
url += h;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1000);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line1 = client.readStringUntil('\r');
Serial.print(line1);
}
Serial.println("closing connection");
}

You might also like