0% found this document useful (0 votes)
12 views

IOT Manual 2025

The document is a lab manual for the IoT Lab using Raspberry Pi at Dayananda Sagar Academy of Technology and Management for the academic year 2024-2025. It outlines the department's vision, mission, program educational objectives, and program outcomes, as well as providing detailed instructions for various experiments involving interfacing components like LEDs, buttons, sensors, and displays with Arduino/Raspberry Pi. Additionally, it includes guidelines for laboratory conduct, record maintenance, and troubleshooting code issues.

Uploaded by

siddhsiddh312
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)
12 views

IOT Manual 2025

The document is a lab manual for the IoT Lab using Raspberry Pi at Dayananda Sagar Academy of Technology and Management for the academic year 2024-2025. It outlines the department's vision, mission, program educational objectives, and program outcomes, as well as providing detailed instructions for various experiments involving interfacing components like LEDs, buttons, sensors, and displays with Arduino/Raspberry Pi. Additionally, it includes guidelines for laboratory conduct, record maintenance, and troubleshooting code issues.

Uploaded by

siddhsiddh312
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/ 41

DAYANANDA SAGAR ACADEMY OF TECHNOLOGY &

MANAGEMENT
Udaypura, Kanakpura Road, Opp: Art of Living, Bengaluru- 560082

NAAC Accredited with A+ Grade

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
(Accredited by NBA, New Delhi)

LAB MANUAL

IoT (Internet of Things) Lab Using Raspberry Pi

Academic Year: 2024-2025

Lab In charge:

Mrs. Deepthi V Assistant Professor


Ms. Kavyashri G Assistant Professor
Ms. Sindhu K Assistant Professor
Dr. Saranya S N Assistant Professor
Dayananda Sagar Academy of Technology and Management,
Bangalore
Department of Electronics and Communication Engineering
Academic Year 2024-2025

Vision of the Department


To impart quality education in the field of Electronics and Communication Engineering by
establishing research and learning environment to meet global needs and industrial standards.

Mission of the Department


M1: To provide quality and contemporary knowledge on latest technologies.

M2: To develop innovation and creativity among students enabling leadership and
entrepreneurship skills with ethical values.

M3: To empower faculty with the knowledge in emerging areas of research.


M4: To ensure industry ready professionals with a research outlook.

M5: To establish center of excellence with industry and university collaborations

Program Educational Objectives


PEO1: To ensure graduates with strong foundation in engineering, science and technology for
successful career in Electronics and Communication Engineering.

PEO2: Graduates shall be technically competent with ability to analyze, design, develop,
optimize and implement Electronics and Communication systems to meet global needs.

PEO3: Graduates shall build leadership and entrepreneurship qualities with


professional ethicsfor the development of emerging technologies.

i
Dayananda Sagar Academy of Technology and Management,
Bangalore

VISION OF THE INSTITUTE


To strive at creating the institution a center of highest caliber of learning, so as to create an overall
intellectual atmosphere with each deriving strength from the other to be the best of engineers,
scientists with management and design skills.

MISSION OF THE INSTITUTE

M1: To serve its region, state, the nation and globally by preparing students to make meaningful
contributions in an increasing complex global society challenge.
M2: To encourage reflection on and evaluation of emerging needs and priorities with state of art
infrastructure at institution.
M3: To support research and services establishing enhancements in technical, economic, human
and cultural development.
M4: To establish inter disciplinary center of excellence, supporting/promoting students
implementation.
M5: To increase the number of doctorate holders to promote research culture on campus.
M6: To establish IIPC, IPR, EDC innovation cells with functional MOU’s supporting student’s
quality growth.

PROGRAM OUTCOMES (POs)

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.

ii
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research


methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.

9. Individual and teamwork: Function effectively as an individual, and as a member or leader in


diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
independent and life-long learning in the broadest context of technological change.

iii
Instruction to Students
1. Students keep their bags in the rack.
2. Students must take care of their valuable things.
3. Students must bring Observation book, record and manual along with pen, pencil, and
eraser Etc., no borrowing from others.
4. Students must handle the computers carefully, as they areexpensive.
5. Before entering to lab, must prepare for Viva for which they are going to conduct
experiment.
6. After execution of the program, students must show the programs to one of the faculties
or instructors.
7. Before leaving the lab, should check whether they have closed the specific software
application and keep their chairs properly.

DO’s and DON’Ts


1. Be regular to Lab
2. Do not come late to Lab
3. Wear your college ID card and do not operate the computers without permission
4. Avoid unnecessary talking while doing the experiment
5. Do not interchange the computer parts such as mouse and keyboard on your own will
6. Handle the systems properly
7. Do not panic if you do not get the output
8. Keep your work area clean after completing the experiment
9. After completion of the experiment, close the application software properly
10. Arrange your chairs and tables before leaving

iv
Rules for maintaining Laboratory Records
1. Put your name, USN and subject on the outside front cover of the record. Put that same
information on the first page inside.
2. Update Table of Contents every time you start each new experiment or topic.
3. Always use pen and write neatly and clearly.
4. Start each new topic (experiment, notes, calculation, etc.) on a right-side (odd numbered)
page.
5. Obvious care should be taken to make it readable even if you have bad handwriting.
6. The date should be written on every page in the top right corner.
7. On each right-side page
➢ Title of the experiment.
➢ Aim/Objectives
➢ Software Required
➢ Theory
➢ Program code
➢ Result
8. On each left side page
➢ Program output
9. Use labels and captions for figures and tables
10. Attach printouts of program output as needed. Stick printouts (A4 size) on the right side of
the lab record.
11. Strictly follow the instructions given by the Lab In-charge/ Lab Instructor.

v
Code Troubleshooting Hints
➢ Check syntax carefully. Look for missing semicolons, parentheses, or curly braces.
➢ Watch for uninitialized variables. Ensure both variables are declared and initialized before use.
➢ Check array boundaries. Ensure that you’re not accessing array elements beyond the declared
size.
➢ Verify that the pointers are correctly initialized and pointing to valid memory.
➢ If the program compiles but does not give the desired output, review the logic of the code.
➢ Avoid infinite loops. Make sure loops have appropriate exit conditions.
➢ Don’t ignore compiler warnings. They often provide useful hints about potential errors.
➢ Finally, ask your Lab Instructor.

vi
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 1
To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to ‘turn ON’ LED for
1 sec after every 2 seconds.

AIM: Write a program to turn ON LED/ Buzzer for 1 sec after every 2 seconds with

Raspberry Pi.

COMPONENTS REQUIRED:

1. Arduino UNO/ Raspberry Pi.


2. LED/ Buzzer.
3. Resistor (220Ω)
4. Connecting cable or USB cable.
5. Breadboard.
6. Jumper wires.

CONNECTION DIAGRAM:

(a) LED (b) Buzzer

(c) LED interfacing with Arduino

Department of ECE, DSATM 1


DSATM
IoT (Internet of Things) Lab 23CECE48

(d) LED interfacing with Raspberry Pi

CODING:

const int buzzer=13; //led or


buzzer void setup()
{
// initialize digital pin 13 as an output.
pinMode(buzzer, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(buzzer, HIGH); // turn the buzzer on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(buzzer, LOW); // turn the buzzer off by making the voltage
LOW delay(2000); // wait for a two seconds
}

RESULT: LED/Buzzer is successfully controlled by Arduino UNO/ Raspberry Pi Board.

Department of ECE, DSATM 2


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 2
To interface Push button/LDR with Arduino/Raspberry Pi and write a program to ‘turn ON’ LED
when push button is pressed or at sensor detection.

AIM: Write a program to turn ON LED when push button is pressed using Arduino UNO.

COMPONENTS REQUIRED:

1. Arduino UNO/ Raspberry Pi.


2. Push Button.
3. LED.
4. Resistor (10KΩ)
5. Connecting cable or USB cable.
6. Breadboard.
7. Jumper wires.

CONNECTION DIAGRAM:

CODING:

(a) Push button interfacing with Arduino

CODING:

const int buttonPin = 4; // the number of the pushbutton pin


const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

Department of ECE, DSATM 3


DSATM
IoT (Internet of Things) Lab 23CECE48

void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH: if
(buttonState == HIGH)
{
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

RESULT: Controlling LED by pressing push button using Arduino UNO has successfully
executed.

Department of ECE, DSATM 4


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 3
To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to print temperature
and humidity readings.

AIM: Write a program to interface DHT11 with Arduino/Raspberry Pi to print temperature


and humidity readings.

COMPONENTS REQUIRED:

1. Arduino UNO/ Raspberry Pi.


2. DHT11.
3. Connecting cable or USB cable.
4. Jumper wires.

CONNECTION DIAGRAM:

(a) DHT11 sensor

(b) DHT11 interfacing with Arduino

Department of ECE, DSATM 5


DSATM
IoT (Internet of Things) Lab 23CECE48

(c) DHT11 interfacing with Raspberry pi

Step 1: Install the library for DHT in Arduino IDE.

• Open Arduino IDE and navigate to Sketch > Include Library > Manage Libraries.
• Search for “DHTlib” and install the “DHTlib” library in the Arduino IDE.

CODING:

// Use the Adafruit DHT sensor library


// this also requires the Adafruit Unified sensor library
#include "DHT.h"

// Arduino pin connected to the DHT-11's data pin


#define DHTPIN 2

// Type of DHT sensor


#define DHTTYPE DHT11

// Initialize DHT sensor


DHT dht(DHTPIN, DHTTYPE);

void setup() {
// We'll use the serial monitor to display readings
Serial.begin(9600);
Serial.println("Humidity and temperature");

// Start the sensor

Department of ECE, DSATM 6


DSATM
IoT (Internet of Things) Lab 23CECE48

dht.begin();
}

void loop() {
// Wait a few seconds between measurements
delay(2000);

//Read humidity
float h = dht.readHumidity();

//Read temperature as Celsius(the default)


float t = dht.readTemperature();

// Send data to serial monitor for display


Serial.print("humidity: ");
Serial.print(h);
Serial.print("% Temperature: ");
Serial.print(t);
Serial.println("C ");
}

RESULT: Interfacing of DHT11 with Arduino UNO to print temperature and humidity
readings has successfully executed.

Department of ECE, DSATM 7


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 4
To interface OLED with Arduino/Raspberry Pi and write a program to print temperature and
humidity readings on it.

AIM: Write a program to interface OLED with Arduino to print temperature and humidity
readings.

COMPONENTS REQUIRED:

1. Arduino UNO/ Raspberry Pi.


2. DHT11.
3. OLED Display Module.
4. Connecting cable or USB cable.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) I2C OLED interfacing with Arduino UNO


Steps to interface I2C OLED with Arduino:
Step 1: Install the library for OLED display in Arduino IDE.

• Open Arduino IDE and navigate to Sketch > Include Library > Manage Libraries.
• Search for “SSD1306” and install the “SSD1306” library from Adafruit in the
Arduino IDE.

Department of ECE, DSATM 8


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 5
To interface motor using relay with Arduino/Raspberry Pi and write a program to ‘turn ON’
motor when push button is pressed.

EXPERIMENT – 6
To interface Bluetooth with Arduino/Raspberry Pi and write a program to send sensor data to
smartphone using Bluetooth.

EXPERIMENT – 7
To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED ON/OFF
when '1'/'0' is received from smartphone using Bluetooth.

Step 2: Import “Adafruit_GFX.h” & “Adafruit_SSD1306.h” header files in the code. Define
header file in the code

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

Step 3: Connect I2C OLED display device to Arduino as per the circuit diagram.

Initially run I2C scanner which will find the address of I2C module that is connected to
Arduino. In this case address of I2C OLED module is 0x3C.

CODING:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"

#define SCREEN_WIDTH 132 // OLED display width, in pixels


#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT);
#define DHTPIN 2 // Digital pin connected to the DHT sensor

#define BLUE 0x001F

Department of ECE, DSATM 9


DSATM
IoT (Internet of Things) Lab 23CECE48

// Uncomment the type of sensor in use:


#define DHTTYPE DHT11
//#define DHTTYPE DHT22
//#define DHTTYPE DHT21

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
dht.begin();
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
//display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
//display.setTextColor(BLUE);
}

void loop() {
delay(2000);

//read temperature and humidity


float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t) ) {
Serial.println("Failed to read from DHT sensor!");
}
Serial.println(t);
Serial.println(h);
//clear display
display.clearDisplay();

// display temperature
display.setTextSize(1);
display.setCursor(0, 7);
// display.setTextColor(BLUE);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0, 12);
display.print(t);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");

Department of ECE, DSATM 10


DSATM
IoT (Internet of Things) Lab 23CECE48

// display humidity
display.setTextSize(1);
display.setCursor(0, 37);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 50);
display.print(h);
display.print(" % ");

display.display();
}

(c) Displaying Temperature and Humidity values on I2C OLED using Arduino UNO

RESULT: Interfacing of OLED and DHT11 with Arduino UNO to print temperature and
humidity readings has successfully executed.

Department of ECE, DSATM 11


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 5
To interface motor using relay with Arduino/Raspberry Pi and write a program to
turn ON motor when push button is pressed.

AIM: Write a program to turn ON motor when push button is pressed using relay with
Arduino UNO.

COMPONENTS REQUIRED:

1. Arduino UNO.
2. Relay.
3. Resistor (10kΩ).
4. Motor.
5. Connecting cable or USB cable.
6. Breadboard.
7. Jumper wires.

CONNECTION DIAGRAM:

(a) Push button interfacing with Arduino

(b) Interfacing motor with relay using Arduino

Department of ECE, DSATM 12


DSATM
IoT (Internet of Things) Lab 23CECE48

CODING:

int motor=9;
int button=4;
void setup() {
pinMode(motor, OUTPUT);
pinMode(button,INPUT);
}

void loop() {
if (digitalRead(button) == HIGH) {
digitalWrite(motor,HIGH);
}
else {
digitalWrite(motor, LOW);
}
}

© Interfacing motor with relay and push button using Arduino

RESULT: Motor turn ON/OFF operation when push button is pressed using relay with
Arduino UNO has successfully executed.

Department of ECE, DSATM 13


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 6
To interface Bluetooth with Arduino/Raspberry Pi and write a program to send
sensor data to smartphone using Bluetooth.

AIM: Write a program on ESP32 to send temperature value using DHT11 sensor to
smartphone using Bluetooth.

COMPONENTS REQUIRED:

1. ESP32.
2. DHT11.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with ESP32

CODING:

// Use the Adafruit DHT sensor library


// this also requires the Adafruit Unified sensor library
#include<SoftwareSerial.h>
#include "DHT.h"
SoftwareSerial B(10,11); //10-TX, 11-RX
// Arduino pin connected to the DHT-11's data pin
#define DHTPIN 2
// Type of DHT sensor
#define DHTTYPE DHT11

Department of ECE, DSATM 14


DSATM
IoT (Internet of Things) Lab 23CECE48

// Initialize DHT sensor


DHT dht(DHTPIN, DHTTYPE);
void setup() {
// We'll use the serial monitor to display readings
B.begin(9600);
B.println("Humidity and temperature");

// Start the sensor


dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
//Read humidity
float h = dht.readHumidity();
//Read temperature as Celsius(the default)
float t = dht.readTemperature();
// Send data to serial monitor for display
B.print("humidity: ");
B.print(h);
B.print("% Temperature: ");
B.print(t);
B.println("C ");
delay(20);
}

(b) Receiving Temperature data on bluetooth terminal of smart phone

RESULT: Sending Temperature data using DHT11 sensor to smartphone using Bluetooth
with ESP32 has successfully executed.

Department of ECE, DSATM 15


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 7

To interface Bluetooth with Arduino and write a program to turn LED ON/OFF
when '1'/'0' is received from smartphone using Bluetooth.

AIM: Write a program on ESP32 to turn LED ON/OFF from smartphone using Bluetooth
when '1'/'0' is received

COMPONENTS REQUIRED:

1. ESP32.
2. LED.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing LED with ESP32

CODING:

int led = 13;


int data;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);

Department of ECE, DSATM 16


DSATM
IoT (Internet of Things) Lab 23CECE48

void loop() {
while(Serial.available()>0)
{
data = Serial.read();
Serial.println(data);
if(data == '1')
{
digitalWrite(13, HIGH);
}
if(data == '0')
{
digitalWrite(13, LOW);
}
}
}

(b) Turning LED ON/OFF operation in ESP32 though smartphone using Bluetooth.

(c) Connecting smartphone to ESP32 using Bluetooth.


(d) Controlling LED Turn ON (1)/ OFF (0) through smartphone.

RESULT: LED ON/OFF from smartphone using Bluetooth based on received '1'/'0' data

Department of ECE, DSATM 17


DSATM
IoT (Internet of Things) Lab 23CECE48

with ESP32 has successfully executed.


EXPERIMENT – 8
Write a program on Arduino/Raspberry Pi to upload temperature and humidity data to
thingspeak cloud.

AIM: Write a program on ESP32 to upload temperature and humidity value using DHT11
sensor to Thingspeak cloud.

COMPONENTS REQUIRED:

1. ESP32.
2. DHT11.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with ESP32

CODING:
#include <DHT.h>
#include <WiFi.h> // library allows an pi pico w board to connect to the
internet
#include <WiFiClient.h>
#include <ThingSpeak.h>
#include <Adafruit_Sensor.h>
#define DHTPIN 16 // what digital pin we're connected to in our case digital
pin 16

Department of ECE, DSATM 18


DSATM
IoT (Internet of Things) Lab 23CECE48

#define DHTTYPE DHT11 // you need to define the DHT sensor type you're using.
In our example we're using the DHT11.
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "Sindu";
const char* password = "24kvsssin";
WiFiClient client;
unsigned long myChannelNumber = 2420596;
const char * myWriteAPIKey = "VJ0IWAGE4TVIWJ0P";
uint8_t temperature, humidity;

void setup()
{
Serial.begin(9600);
dht.begin();
delay(10);
// connect to Wifi network
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");
// Print the IP address
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}

void loop()
{

temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print("Temperature Value is :");
Serial.print(temperature);
Serial.println("C");
Serial.print("Humidity Value is :");
Serial.print(humidity);
Serial.println("%");
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to
store up to 8 different
//pieces of information in a channel. Here, we write to field 1 and 2.

Department of ECE, DSATM 19


DSATM
IoT (Internet of Things) Lab 23CECE48

ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);


ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey);
delay(3000); //ThingSpeak will only accept updates every 3 seconds.
}

RESULT: Sending temperature and humidity data using DHT11 sensor to Thingspeak
cloud with ESP32 has successfully executed.

Department of ECE, DSATM 20


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 9
Write a program on Arduino/Raspberry Pi to retrieve temperature and humidity data from
thingspeak cloud.

AIM: Write a program on ESP32 to retrieve temperature and humidity values using DHT11
sensor from Thingspeak cloud.

COMPONENTS REQUIRED:

1. ESP32.
2. DHT11.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with ESP32

CODING:

#include <WiFi.h>
#include <ThingSpeak.h>
WiFiClient client;
void setup()
{
Serial.begin(9600);
ThingSpeak.begin(client);

Department of ECE, DSATM 21


DSATM
IoT (Internet of Things) Lab 23CECE48

WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("Sindu", "24kvsssin");
while ((!(WiFi.status() == WL_CONNECTED))) {
delay(300);
Serial.print("..");
}
Serial.println("Your IP is");
Serial.println((WiFi.localIP().toString()));
Serial.println("Connected");
}

void loop()
{
Serial.print("Temperature=");
Serial.println((ThingSpeak.readIntField(2420596,1,"VH42NQD7VW2J8Q4M")));
Serial.print("Humidity=");
Serial.println((ThingSpeak.readIntField(2420596,2,"VH42NQD7VW2J8Q4M")));
delay(3000);
}

EXPERIMENT – 10
To install MySQL database on Raspberry Pi and perform basic SQL queries.

(b) Available temperature and humidity data on ThingSpeak cloud

Department of ECE, DSATM 22


DSATM
IoT (Internet of Things) Lab 23CECE48

(c) Displaying temperature and humidity data on serial monitor of Arduino IDE from Thingspeak cloud

RESULT: Retrieving temperature and humidity data from Thingspeak cloud with ESP32
has successfully executed.

Department of ECE, DSATM 23


DSATM
IoT (Internet of Things) Lab 23CECE48

EXPERIMENT – 10
To install MySQL database on Raspberry Pi and perform basic SQL queries.

AIM: To perform basic SQL queries by installing MySQL database on Rsapberry Pi.

PROCEDURE:
CRUD operations act as the foundation of database operations.

1.Create:

In CRUD operations, 'C' is an acronym for create, which means to add or insert data
into the SQL table. So, firstly we will create a table using CREATE command and then
we will use the INSERT INTO command to insert rows in the created table. Syntax for
table creation:

CREATE TABLE Table_Name (ColumnName1 Datatype, ColumnName2


Datatype,..., ColumnNameN Datatype);

where,
➢ Table_Name is the name that we want to assign to the table.
➢ Column_Name is the attributes under which we want to store data of the table.
➢ Datatype is assigned to each column. Datatype decides the type of data that
will be stored in the respective column.

Department of ECE, DSATM 24


DSATM
IoT (Internet of Things) Lab 23CECE48

• Syntax for insertion of data in table:

INSERT INTO Table_Name (ColumnName1,...., ColumnNameN) VALUES


(Value1,....,Value N),....., (Value 1,....,Value N);

Prior to the creation of a table in SQL, we need to create a database or select an existing
database. Since we already had a database, we will select the database with the USE command.

➢ A query to create a table named employee in the database named dbe.

mysql> CREATE TABLE employee(ID INT PRIMARY KEY, First_Name VARCHAR(


20), Last_Name VARCHAR(20), Salary INT, Email_Id VARCHAR(40));

To ensure that the table is created as per the column names, data types and sizes which we
have assigned during table creation, we will execute the following query:

mysql> DESC employee;

will get the following output:

Department of ECE, DSATM 25


DSATM
IoT (Internet of Things) Lab 23CECE48

Execute the following query to insert multiple records in the employee table:

INSERT INTO employee(ID, First_Name, Last_Name, Salary, Email_Id)


VA LUES(1, "Neeta", "Korade", 59000, "[email protected]"), (2,
"Sushma ", "Singh", 62000, "[email protected]"), (3, "Kavita",
"Rathod", 27000, "[email protected]"), (4, "Mrunalini",
"Deshmukh", 88000,"[email protected]"), (5, "Swati", "Patel",
34000, "[email protected]"), (6, "Laxmi", "Kadam", 44000,
"[email protected]"), (7, "Lal ita", "Shah", 66000,
"[email protected]"), (8, "Savita", "Kulkarni", 31000,
"[email protected]"), (9, "Shravani", "Jaiswal", 38000,
"[email protected]"), (10, "Shweta", "Wagh", 20000,
"shwetaw03@gm ail.com");

2.Read:

In CRUD operations, 'R' is an acronym for read, which means retrieving or fetching the
data from the SQL table. So, we will use the SELECT command to fetch the inserted
records from the SQL table. We can retrieve all the records from a table using an asterisk
(*) in a SELECT query. There is also an option of retrieving only those records which
satisfy a particular condition by using the WHERE clause in a SELECT query.

• Syntax to fetch all the records:

SELECT *FROM TableName;

• Syntax to fetch records according to the condition:

SELECT *FROM TableName WHERE CONDITION;

Example : Write a query to fetch all the records stored in the employee table.

Department of ECE, DSATM 26


DSATM
IoT (Internet of Things) Lab 23CECE48

Query: mysql> SELECT *FROM employee;

Here, an asterisk is used in a SELECT query. This means all the column values for every
record will be retrieved.

You will get the following output after executing the above query:

3. Update:

In CRUD operations, 'U' is an acronym for the update, which means making updates to the
records present in the SQL tables. So, we will use the UPDATE command to make changes
in the data present in tables.

Syntax:

UPDATE Table_Name SET ColumnName = Value WHERE CONDITION;

Department of ECE, DSATM 27


DSATM
IoT (Internet of Things) Lab 23CECE48

Example: Write a query to update an employee's last name as 'Bose', whose employee id is 6.

Query:mysql> UPDATE employee SET Last_Name = "Bose" WHERE ID = 6;

Here in the SELECT query, we have used the SET keyword to update an employee's last
name as 'Bose'. We want to update an employee's last name only for the employee with
id 6, so we have specified this condition using the WHERE clause.

To ensure that an employee's last name with employee id 6 is updated successfully, we


will execute the SELECT query.

mysql> SELECT *FROM employee;

Department of ECE, DSATM 28


DSATM
IoT (Internet of Things) Lab 23CECE48

4. Delete:

In CRUD operations, 'D' is an acronym for delete, which means removing or deleting the
records from the SQL tables. We can delete all the rows from the SQL tables using the
DELETE query. There is also an option to remove only the specific records that satisfy a
particular condition by using the WHERE clause in a DELETE query.

to delete all the records:

DELETE FROM TableName;

Syntax to delete records according to the condition:

DELETE FROM TableName WHERE CONDITION;

Example:Write a query to delete the employee record from the employee table whose
salary is above 34000.

Query:mysql> DELETE FROM employee WHERE Salary = 34000;

Here we have applied the DELETE query on the employee table. We want to delete only
the employee record whose salary is 34000, so we have specified this condition using the
WHERE clause.

execute the SELECT query to ensure that the employee record with salary as 34000 is deleted
successfully.

mysql> SELECT *FROM employee;

Department of ECE, DSATM 29


DSATM
IoT (Internet of Things) Lab 23CECE48

To remove all the records from the employee table, we will execute the DELETE query on
the employee table.

mysql> DELETE FROM employee;

➢ Execute the SELECT query to ensure that all the records are deleted
successfully from the employee table.

mysql> SELECT *FROM employee;

RESULT: Performed basic SQL queries by installing MySQL database on Rsapberry Pi.

Department of ECE, DSATM 30


DSATM

You might also like