SlideShare a Scribd company logo
Visvesvaraya Technological University,
Belagavi
2023 – 2024
A
Report on Practical Exercises of the course
“Internet of Things (18CS81)”
Submitted in partial fulfilment of the requirements for the award of the degree of
BACHELOR OF ENGINEERING
in
COMPUTER SCIENCE & ENGINEERING
Submitted by
Under the guidance of
Prof. Hanumantha Rao K R
Assistant Professor
Dept. of CSE
SAMBHRAM INSTITUTE OF TECHNOLOGY
Department of Computer Science and Engineering
Bengaluru – 560097
1ST20CS093
RAMAN DUBEY
(Affiliated to Visvesvaraya Technological University)
M.S. Palya, Via Jalahalli East,
Bangalore – 560 097
Department of Computer Science and Engineering
CERTIFICATE
Certified that the Practical exercises with the demonstration was carried out by
, a bonafide student of the Department of
Computer Science and Engineering, Sambhram Institute of Technology,in partial
fulfilment for the award of Bachelor of Engineering in Computer Science &
Engineering of the Visvesvaraya Technological University, Belagavi, during the
year 2023 -2024 . It is certified that all corrections /suggestions indicated for
Internal Assessment have been incorporated in the Report. The Report on Practical
Exercises has been approved as it satisfies the academic requirements prescribed
for the said Degree.
Guide
Prof. Hanumantha Rao K R
Dept. of CSE
SaIT, Bengaluru
HOD
Dr. T. John Peter
Dept. of CSE
SaIT, Bengaluru
RAMAN DUBEY , 1ST 20 CS 093
(Affiliated to Visvesvaraya Technological University)
M.S. Palya, Via Jalahalli East,
Bangalore – 560 097
Department of Computer Science and Engineering
DECLARATION
, Student of the eighth semester, Bachelor of
Engineering , Sambhram Institute of Technology hereby declare that the
Practical Exercises on Internet of Things (18CS81) has been carried out by me at
Sambhram Institute of Technology , Bengaluru , and submitted in partial
fulfillment of the course requirements for the award of the degree of Bachelor of
Engineering In Computer Science & Engineering of Visvesvaraya
Technological University, Belagavi, during the academic year 2023-2024.
I also declare that, to the best of my knowledge and belief, the work
reported here doesn’t form part of any other dissertation on the basis of which a
degree or award was conferred on an earlier occasion on by any other student.
Place: Bengaluru
Date: 07-May-2024 1ST20CS093
RAMAN DUBEY
I, RAMAN DUBEY, 1ST20CS093
ACKNOWLEDGEMENT
I am grateful to my institution, Sambhram Institute of Technology, for
having provided me with the facilities to successfully complete these Practical
Exercises on Internet of Things (18CS81).
I thank the management of Sambhram Institute of Technology for
providing us this opportunity and necessary infrastructure.
I thank Dr. H.G. Chandrakanth, Principal and Dr. T John Peter, HOD,
CSE for providing us all the necessary facilities for successful completion of our
Practical Exercises.
I take this opportunity to express our deep sense of gratitude to my
coordinators Prof. Hanumantha Rao K R, Assistant Professor, Department of
CSE for his valuable guidance and help throughout the course. They have always
been patient with me and helped immensely in completing the task on hand.
Last but not least from the Department of Computer Science and
Engineering, teaching and non-teaching staffs for their constant encouragement,
support, patience and endurance shown during the preparation of this report were
remarkable.
1ST20CS093
RAMAN DUBEY
TABLE OF CONTENTS
Experiment No Title Page No
Transmit a String using UART 1
1.1 Introduction 1
1.2 Working 1
1 1.3 Implementation Code 2
1.4 Demonstration 2
Point-to-Point Communication of Motes over the
Radio Frequency.
4
2.1 Introduction 4
2 2.2 Working 4
2.3 Implementation Code 5
2.4 Demonstration 7
Multi Point to Single Point Communication of Motes
over the Radio frequency. LAN (Sub-netting)
9
3.1 Introduction 9
3 3.2 Working 9
3.3 Implementation Code 10
3.4 Demonstration 13
I2C Protocol Study 15
4 4.1 Introduction 15
4.2 Working 16
Reading Temperature and Relative Humidity Value
from The Sensor
17
5.1 Introduction 17
5 5.2 Working 17
5.3 Implementation Code 18
5.4 Demonstration 19
LIST OF FIGURES
Fig. No Figure Name Page No.
1.1
Hardware setup to Transmit a String on Arduino
UNO
2
1.2 String being Transmitted in Output Screen 3
2.1 NRF24L01Transceiver Module 7
2.2 Hardware Setup to P2P Communication over Radio
Frequency
7
2.3 Code Implementation for Transmitter and Receiver 8
3.1
ESP Many-to-One Structure
13
3.2 ESP32 Many-to One (Sender -Receiver)
Configuration Setup
14
3.3 Acknowledgement Packets received from Sender
Board
14
4.1 I2C Protocol Architecture 15
4.2 I2C Communication between Master and Slave 16
5.1
Hardware Setup for Measuring Temperature and
Relative Humidity.
19
5.2 Temperature and Humidity displayed over the
Output Console
19
IoT Laboratory Report
INTERFACE DESCRIPTION
1. Specific Requirements
A.1.1 Hardware Requirements
 SST IoT Board:
Components GPIO PIN DESCRIPTION
ON Board LED 2, 16
LDR A0
LCD SCL - 5, SDA - 4
OLED 4, 5
DC Motor Motor 1- 16, 5 Motor 2- 4,2
Ultra Sonic Sensor Trigger-12, Echo-14
Bluetooth RX-14, TX-12
DHT 11 2
RELAY 13
A.1.2 Software Requirements
 Arduino IDE 1.8.16
 ESP8266
 Blynk Account
 Libraries Required:
o Adafruit Sensor
o DHT-sensor-library
o Firebase-ESP8266
o Blynk-library
Dept. of CSE, SaIT 2023-2024
Experiment 01
Transmit a String using UART
1.1 Introduction
Transmit string using UART (Universal Asynchronous Receiver Transmitter) where the two devices
communicate directly with each other. UART is a hardware related to serial communication.
Asynchronous means there is no clock signal to synchronize the output bits from the transmitting device
going to the receiving end.
Baud Rate: Baud rate is the measure of the number of changes of the signal(p/sec) thatpropagate through
a medium. It is necessary to set both UART devices with the same baud rate to have the proper
transmission of data. Values for baud rate can be 9600, 1200, 2400, 480, 19200, 38400, 57600, and 115200
bps.
Components Required: Arduino UNO, Arduino USB Cable.
1.2 Working
UART transmits the received data from a data bus. The data bus is used to send data to the UART by
another device like a CPU, memory, or microcontroller Data is transferred from the data bus to the transmitting
UART in parallel form. After the transmitting UART gets the parallel data from the data bus, it adds a start bit,
a parity bit, and a stop bit. creating the data packet. Next, the data packet is output serially, bit by bit at the Tx
pin. The receiving UART reads the data packet bit by bit at its Rx pin. The receiving UART then converts the
data back into parallel form and removes the start bit. parity bit and stop bits Finally, the Receiving UART
transfers the data packet in parallel to the data bus on the receiving end.
1.2.1 Steps
1. Type the program in the Arduino IDE.
2. Connect the Arduino board with the CPU using the USB cable
3. Save the program
4. In Arduino IDE, Tools Board-> Select Arduino UNO
5. In Arduino IDE. Tools-> Port-> Select port for Arduino UNO
6. Verify the program
7. Upload the program.
8. Click on the serial monitor (right-hand side corner) for output.
Dept. of CSE, SaIT 2023-2024 1
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 2
1.3 Implementation Code
--Program Code to Transmit a String using UART--
int led = 13;
int value = 0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
value = Serial.read();
delay(5);
if (value == '1') {
digitalWrite(led, HIGH);
Serial.println("LED is ON");
}
if (value == '0') {
digitalWrite(led, LOW);
Serial.println("LED is OFF");
}
}
}
1.4 Demonstration
Fig. 1.1 Hardware setup to Transmit a String on Arduino UNO
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 3
Fig. 1.2 String being Transmitted in Output Screen
Dept. of CSE, SaIT 2023-2024 4
Experiment 02
Point-to-Point Communication of Motes over the Radio Frequency.
2.1 Introduction
A Point-to-Point connection (P2P) refers to a permanent direct communication link between
two parties. The two units communicate using either Frequency Division Multiplexing or Time Division
Multiplexing to allow for bidirectional traffic flow. For fixed links, this can involve useof high gain
directional antennas which enable long-distance and high-capacity links.
Radio frequency is the measurement representing the oscillation rate of the electromagnetic radiation
spectrum, or electromagnetic radio waves, from frequencies ranging from 300 GHz toas low as 9 kHz
Components Required: Node MCU, ESP8266, USB B Type Cable, NRF24L01.
2.2 Working
NRF24L01 Transceiver Module (Radio Frequency)
It uses the 2.4 GHz band and it can operate with baud rates from 250 kbps up to 2 Mbps. If used in
open space and with a lower baud rate its range can reach up to 100 meters. The module can use 125
different channels which gives the possibility to have a network of 125 independently workingmodems in
one place. Each channel can have up to 6 addresses, or each unit can communicate with up to 6 other units
at the same time.
The power consumption of this module is just around 12mA during transmission. which is even lower
than a single LED. The operating voltage of the module is from 19 to 3.6V, but the goodthing is that the
other pins tolerate 5V logic, so we can easily connect it to an Arduino without usingany logic-level
converters.
Three of these pins are for the SPI communication and they need to be connected to the SPI pins of the
Arduino, but note that each Arduino board has different SPI pins The pins CSN and CE can be connected
to any digital pin of the Arduino board and they are used for setting the module in standby or active mode,
as well as for switching between transmit or command mode. The last pin is an interrupt pin which doesn’t
have to be used.
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 5
2.2.1 Steps:
1. Import RF24Network-master.zip to Arduino IDE via Sketch->Include Library-> ADD Zip library
2. Import RF24-master.zip to Arduino IDE via Sketch->Include Library-> ADD Zip library
3. Type the transmitter code in Arduino IDE and select board and port for first Arduino uno. Uploadthe code
to transmitter Arduino (first Arduino).
4. 4.Type the receiver code in another Arduino IDE and select board and port for second Arduino uno.Upload
the code to receiver Arduino (second Arduino).
5. If data sent in the code is 'I' then LED in receiver will be ON otherwise LED will be OFF.
2.3 Implementation Code
--Transmitter Code--
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define buttonPin1 3
#define buttonPin2 4
int buttonState1 = 0;
int buttonState2 = 0;
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == 1)
{
buttonState1 = 1;
}
else if (buttonState1 == 0)
{
buttonState1 = 0;
}
if (buttonState2 == 1)
{
buttonState2 = 3;
}
else if (buttonState2 == 0)
{
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 6
buttonState2 = 2;
}
Serial.print(buttonState1);
Serial.print("t");
Serial.println(buttonState2);
radio.write(&buttonState1, sizeof(buttonState1));
radio.write(&buttonState2, sizeof(buttonState2));
}
--Receiver Code—
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led1 A0
#define led2 A1
int buttonState = 0;
RF24 radio(9, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
radio.startListening();
while (!radio.available());
radio.read(&buttonState, sizeof(buttonState));
Serial.println(buttonState);
if (buttonState == 1) {
digitalWrite(led1, LOW);
}
else if (buttonState == 0) {
digitalWrite(led1, HIGH);
}
else if (buttonState == 3) {
digitalWrite(led2, LOW);
}
else if (buttonState == 2) {
digitalWrite(led2, HIGH);
}
}
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 7
Fig. 2.2 Hardware Setup to P2P Communication over Radio Frequency
2.4 Demonstration
Fig. 2.1 NRF24L01Transceiver Module
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 8
Fig. 2.3 Code Implementation for Transmitter and Receiver
Dept. of CSE, SaIT 2023-2024 9
Experiment 03
Multi Point to Single Point Communication of Motes
over the Radio frequency. LAN (Sub-netting)
3.1 Introduction
Point-to-Multipoint communication refers to communication that is accomplished through a
distinct and specific form of one-to-many connections, offering several paths from one location to
various locations.
Radio Frequency is the measurement representing the oscillation rate of the Electro Magnetic radiation
spectrum, or electromagnetic radio waves, from frequencies ranging from 300 GHz toas low as 9 kHz
Components Required: Node MCU, ESP8266, USB B Type Cable
3.2 Working
ESP32 board to Receive Data from Multiple ESP32 boards via ESP-NOW Communication Protocol (Many-
to-One Configuration). One ESP32 board acts as a receiver/slave. Multiple ESP32 boards act as
senders/masters. The sender board receives an acknowledge message indicating if the message was
successfully delivered or not. The ESP32 Receiver Board receives the messages from all senders and identifies
which board sent the message.
3.2.1 Steps:
1. Gather the Receiver ESP32’s MAC Address via ESP-NOW.
2. ESP32 Sender Code (ESP-NOW)
3. Add peer Device.
4. Send ESP-NOW message.
5. ESP32 Receiver Code (ESP-NOW)
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 10
3.3 Implementation Code
--Code Snippet to Print Receiver’s MAC Address--
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
void setup(){
Serial.begin(115200);
Serial.println();
Serial.print("ESP Board MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop(){
}
--Sender’s Code—
#include <esp_now.h>
#include <WiFi.h>
// REPLACE WITH THE RECEIVER'S MAC Address
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
int id; // must be unique for each sender board
int x;
int y;
} struct_message;
// Create a struct_message called myData
struct_message myData;
// Create peer interface
esp_now_peer_info_t peerInfo;
// callback when data is sent
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 11
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("rnLast Packet Send Status:t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" :
"Delivery Fail");
}
void setup() {
// Init Serial Monitor
Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);
// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}
void loop() {
// Set values to send
myData.id = 1;
myData.x = random(0,50);
myData.y = random(0,50);
// Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData,
sizeof(myData));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
delay(10000);
}
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 12
--Sender’s ESP Message—
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData,
sizeof(myData));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
--Receiver’s Code—
#include <esp_now.h>
#include <WiFi.h>
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
int id;
int x;
int y;
}struct_message;
// Create a struct_message called myData
struct_message myData;
// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;
struct_message board3;
// Create an array with all the structures
struct_message boardsStruct[3] = {board1, board2, board3};
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len)
{
char macStr[18];
Serial.print("Packet received from: ");
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4],
mac_addr[5]);
Serial.println(macStr);
memcpy(&myData, incomingData, sizeof(myData));
Serial.printf("Board ID %u: %u bytesn", myData.id, len);
// Update the structures with the new incoming data
boardsStruct[myData.id-1].x = myData.x;
boardsStruct[myData.id-1].y = myData.y;
Serial.printf("x value: %d n", boardsStruct[myData.id-1].x);
Serial.printf("y value: %d n", boardsStruct[myData.id-1].y);
Serial.println();
}
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 13
void setup() {
//Initialize Serial Monitor
Serial.begin(115200);
//Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
//Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
// Acess the variables for each board
/*int board1X = boardsStruct[0].x;
int board1Y = boardsStruct[0].y;
int board2X = boardsStruct[1].x;
int board2Y = boardsStruct[1].y;
int board3X = boardsStruct[2].x;
int board3Y = boardsStruct[2].y;*/
delay(10000);
}
3.4 Demonstration
Fig. 3.1 ESP Many-to-One Structure
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 14
Fig. 3.2 ESP32 Many-to One (Sender -Receiver) Configuration Setup
Fig. 3.3 Acknowledgement Packets received from Sender Board
Experiment 04
I2C Protocol Study
4.1 Introduction
I2C stands for inter-integrated controller. This is a serial communication protocol that is used to connect
low-speed devices. It is a master-slave communication in which we can connect and control multiple slaves
from a single master. It uses only 2 bi-directional open-drain lines for data communication called SDA and
SCL. Both these lines are pulled high. With I2C, data is transferred in messages. Messages are broken up into
frames of data. Each message has an address frame that contains the binary address of the slave, and one or
more data frames that contain the data being transmitted. The message also includes start and stop conditions,
read/write bits, and ACK/NACK bits between each data frame
Fig 4.1 I2C Protocol Architecture
Advantages:
 Can be configured in multi-master mode
 Complexity is reduced because it uses only 2 bi-directional lines
 Cost-efficient
 It uses ACK/NACK feature due to which it has improved error handling capabilities
Limitations:
 Slower speed Half-duplex communication is used in the I2C communication protocol.
Dept. of CSE, SaIT 2023-2024 15
IoT Laboratory Report
4.2 Working
I2C Communication Protocol uses only 2 bi-directional open-drain lines for data communication called
SDA and SCL.
• Serial Data (SDA) – Transfer of data takes place through this pin.
• Serial Clock (SCL) – It carries the clock signal.
I2C operates in 2 modes
• Master mode
• Slave mode
Each data bit transferred on SDA line is synchronized by a high to the low pulse of each clock on the
SCL line.
Fig 4.2 I2C Communication between Master and Slave
Dept. of CSE, SaIT 2023-2024 16
Dept. of CSE, SaIT 2023-2024 17
Experiment 05
Reading Temperature and Relative Humidity Value from the Sensor
5.1 Introduction
DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity
sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog
input pins needed). It's fairly simple to use but requires careful timing to grab data. The only real downside of
this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor
readings can be up to 2 seconds old.
DHT11 is a relative humidity sensor. To measure the surrounding air this sensor uses a thermistor and a
capacitive humidity sensor. DHT11 has a Capacitive Sensor for measuring humidity & NTC Thermistor for
temperature sensing. (We will cover them in detail below). It calibrates the humidity using humidity
coefficients, which are stored in the OTP program memory of the built-in controller.
The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of
this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one
reading for every second. DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum
current used while measuring is 2.5mA.
Components Required: Node MCU, DHT sensor, USB B Type Cable.
5.2 Working
The DHT - Digital Temperature and Humidity sensor is set to pin 2 and Blynk app is listened on Serial monitor
connection. The V0 pin is monitored continuously and any change results in calling dht() function.
The DHT sensor monitors the floating-point values of Temperature in °C and Humidity and writes to the
Blynk app through V2 pin. This dht() function repeats in loop for continuous monitoring of the values of
temperature and humidity.
The Node MCU is connected with the DHT11 sensor. The libraries such as:
• Adafruit library
• DHT sensor library
• Firebase ESP8266 library
• Blynk Library
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 18
5.2.1 Steps:
1. Add the libraries by navigating to
2. Sketch >> Include Library >>
3. Add .zip library >> Select .zip file and load.
4. Thereby the values with respect to DHT can be obtained in real-time.
5.3 Implementation Code
#include <dht11.h>
#define DHT11PIN 4
dht11 DHT11;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);
delay(2000);
}
IoT Laboratory Report
Dept. of CSE, SaIT 2023-2024 19
5.4 Demonstration
Fig. 5.1 Hardware Setup for Measuring Temperature and Relative Humidity.
Fig. 5.2 Temperature and Humidity displayed over the Output Console.

More Related Content

PDF
Internet of things laboratory
DOCX
PDF
IRJET- BSIOTR IT SMART LAB using IOT
PPTX
Advanced Arduino Programming for Communications.pptx
PDF
Arduino Based Home Lighting Control by Android Phone
PPTX
IoT Platform
PPTX
IoT Platform
PDF
Smart Home Automation using Wi-Fi
Internet of things laboratory
IRJET- BSIOTR IT SMART LAB using IOT
Advanced Arduino Programming for Communications.pptx
Arduino Based Home Lighting Control by Android Phone
IoT Platform
IoT Platform
Smart Home Automation using Wi-Fi

Similar to IOT REPORT a Report on subject of IOT under VTU curriculum (20)

PDF
Internet of Things (IoT) - workshop with wifi chip
PPTX
Arduino interfacing with bluetooth.
PDF
Syed IoT - module 5
PPTX
Lecture23_Home automation where we talk how iot can be used for home automation
PDF
Intelligent Device TO Device Communication Using IoT
PDF
manual Internet of ThingsArduino_IOTArdu
PDF
Device Operation using PC by Arduino (1).pdf
PDF
ARUDINO UNO and RasberryPi with Python
PPT
IoT Basics with few Embedded System Connections for sensors
PDF
USB OTG
PPT
Scripting Things - Creating the Internet of Things with Perl
PPTX
Arduino blueooth
PPTX
IOT Talking to Webserver - how to
PPTX
Home Automation Over Internet Project (Ev Otomasyon Projesi)
PPTX
Bluetooth Home Automation
PDF
WiFi mesh network(ESP32 mStar and mesh topology)
PDF
Power consumption analysis on an IoT network based on wemos: a case study
PPTX
Gas leakage detection system
DOCX
Voice controlled smart home
PPTX
Remote temperature monitor (DHT11)
Internet of Things (IoT) - workshop with wifi chip
Arduino interfacing with bluetooth.
Syed IoT - module 5
Lecture23_Home automation where we talk how iot can be used for home automation
Intelligent Device TO Device Communication Using IoT
manual Internet of ThingsArduino_IOTArdu
Device Operation using PC by Arduino (1).pdf
ARUDINO UNO and RasberryPi with Python
IoT Basics with few Embedded System Connections for sensors
USB OTG
Scripting Things - Creating the Internet of Things with Perl
Arduino blueooth
IOT Talking to Webserver - how to
Home Automation Over Internet Project (Ev Otomasyon Projesi)
Bluetooth Home Automation
WiFi mesh network(ESP32 mStar and mesh topology)
Power consumption analysis on an IoT network based on wemos: a case study
Gas leakage detection system
Voice controlled smart home
Remote temperature monitor (DHT11)
Ad

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Digital Logic Computer Design lecture notes
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
PPT on Performance Review to get promotions
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
composite construction of structures.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
UNIT 4 Total Quality Management .pptx
PPT
Project quality management in manufacturing
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
CH1 Production IntroductoryConcepts.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Digital Logic Computer Design lecture notes
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPT on Performance Review to get promotions
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
composite construction of structures.pdf
OOP with Java - Java Introduction (Basics)
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
UNIT 4 Total Quality Management .pptx
Project quality management in manufacturing
Automation-in-Manufacturing-Chapter-Introduction.pdf
Ad

IOT REPORT a Report on subject of IOT under VTU curriculum

  • 1. Visvesvaraya Technological University, Belagavi 2023 – 2024 A Report on Practical Exercises of the course “Internet of Things (18CS81)” Submitted in partial fulfilment of the requirements for the award of the degree of BACHELOR OF ENGINEERING in COMPUTER SCIENCE & ENGINEERING Submitted by Under the guidance of Prof. Hanumantha Rao K R Assistant Professor Dept. of CSE SAMBHRAM INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Bengaluru – 560097 1ST20CS093 RAMAN DUBEY
  • 2. (Affiliated to Visvesvaraya Technological University) M.S. Palya, Via Jalahalli East, Bangalore – 560 097 Department of Computer Science and Engineering CERTIFICATE Certified that the Practical exercises with the demonstration was carried out by , a bonafide student of the Department of Computer Science and Engineering, Sambhram Institute of Technology,in partial fulfilment for the award of Bachelor of Engineering in Computer Science & Engineering of the Visvesvaraya Technological University, Belagavi, during the year 2023 -2024 . It is certified that all corrections /suggestions indicated for Internal Assessment have been incorporated in the Report. The Report on Practical Exercises has been approved as it satisfies the academic requirements prescribed for the said Degree. Guide Prof. Hanumantha Rao K R Dept. of CSE SaIT, Bengaluru HOD Dr. T. John Peter Dept. of CSE SaIT, Bengaluru RAMAN DUBEY , 1ST 20 CS 093
  • 3. (Affiliated to Visvesvaraya Technological University) M.S. Palya, Via Jalahalli East, Bangalore – 560 097 Department of Computer Science and Engineering DECLARATION , Student of the eighth semester, Bachelor of Engineering , Sambhram Institute of Technology hereby declare that the Practical Exercises on Internet of Things (18CS81) has been carried out by me at Sambhram Institute of Technology , Bengaluru , and submitted in partial fulfillment of the course requirements for the award of the degree of Bachelor of Engineering In Computer Science & Engineering of Visvesvaraya Technological University, Belagavi, during the academic year 2023-2024. I also declare that, to the best of my knowledge and belief, the work reported here doesn’t form part of any other dissertation on the basis of which a degree or award was conferred on an earlier occasion on by any other student. Place: Bengaluru Date: 07-May-2024 1ST20CS093 RAMAN DUBEY I, RAMAN DUBEY, 1ST20CS093
  • 4. ACKNOWLEDGEMENT I am grateful to my institution, Sambhram Institute of Technology, for having provided me with the facilities to successfully complete these Practical Exercises on Internet of Things (18CS81). I thank the management of Sambhram Institute of Technology for providing us this opportunity and necessary infrastructure. I thank Dr. H.G. Chandrakanth, Principal and Dr. T John Peter, HOD, CSE for providing us all the necessary facilities for successful completion of our Practical Exercises. I take this opportunity to express our deep sense of gratitude to my coordinators Prof. Hanumantha Rao K R, Assistant Professor, Department of CSE for his valuable guidance and help throughout the course. They have always been patient with me and helped immensely in completing the task on hand. Last but not least from the Department of Computer Science and Engineering, teaching and non-teaching staffs for their constant encouragement, support, patience and endurance shown during the preparation of this report were remarkable. 1ST20CS093 RAMAN DUBEY
  • 5. TABLE OF CONTENTS Experiment No Title Page No Transmit a String using UART 1 1.1 Introduction 1 1.2 Working 1 1 1.3 Implementation Code 2 1.4 Demonstration 2 Point-to-Point Communication of Motes over the Radio Frequency. 4 2.1 Introduction 4 2 2.2 Working 4 2.3 Implementation Code 5 2.4 Demonstration 7 Multi Point to Single Point Communication of Motes over the Radio frequency. LAN (Sub-netting) 9 3.1 Introduction 9 3 3.2 Working 9 3.3 Implementation Code 10 3.4 Demonstration 13 I2C Protocol Study 15 4 4.1 Introduction 15 4.2 Working 16 Reading Temperature and Relative Humidity Value from The Sensor 17 5.1 Introduction 17 5 5.2 Working 17 5.3 Implementation Code 18 5.4 Demonstration 19
  • 6. LIST OF FIGURES Fig. No Figure Name Page No. 1.1 Hardware setup to Transmit a String on Arduino UNO 2 1.2 String being Transmitted in Output Screen 3 2.1 NRF24L01Transceiver Module 7 2.2 Hardware Setup to P2P Communication over Radio Frequency 7 2.3 Code Implementation for Transmitter and Receiver 8 3.1 ESP Many-to-One Structure 13 3.2 ESP32 Many-to One (Sender -Receiver) Configuration Setup 14 3.3 Acknowledgement Packets received from Sender Board 14 4.1 I2C Protocol Architecture 15 4.2 I2C Communication between Master and Slave 16 5.1 Hardware Setup for Measuring Temperature and Relative Humidity. 19 5.2 Temperature and Humidity displayed over the Output Console 19
  • 7. IoT Laboratory Report INTERFACE DESCRIPTION 1. Specific Requirements A.1.1 Hardware Requirements  SST IoT Board: Components GPIO PIN DESCRIPTION ON Board LED 2, 16 LDR A0 LCD SCL - 5, SDA - 4 OLED 4, 5 DC Motor Motor 1- 16, 5 Motor 2- 4,2 Ultra Sonic Sensor Trigger-12, Echo-14 Bluetooth RX-14, TX-12 DHT 11 2 RELAY 13 A.1.2 Software Requirements  Arduino IDE 1.8.16  ESP8266  Blynk Account  Libraries Required: o Adafruit Sensor o DHT-sensor-library o Firebase-ESP8266 o Blynk-library Dept. of CSE, SaIT 2023-2024
  • 8. Experiment 01 Transmit a String using UART 1.1 Introduction Transmit string using UART (Universal Asynchronous Receiver Transmitter) where the two devices communicate directly with each other. UART is a hardware related to serial communication. Asynchronous means there is no clock signal to synchronize the output bits from the transmitting device going to the receiving end. Baud Rate: Baud rate is the measure of the number of changes of the signal(p/sec) thatpropagate through a medium. It is necessary to set both UART devices with the same baud rate to have the proper transmission of data. Values for baud rate can be 9600, 1200, 2400, 480, 19200, 38400, 57600, and 115200 bps. Components Required: Arduino UNO, Arduino USB Cable. 1.2 Working UART transmits the received data from a data bus. The data bus is used to send data to the UART by another device like a CPU, memory, or microcontroller Data is transferred from the data bus to the transmitting UART in parallel form. After the transmitting UART gets the parallel data from the data bus, it adds a start bit, a parity bit, and a stop bit. creating the data packet. Next, the data packet is output serially, bit by bit at the Tx pin. The receiving UART reads the data packet bit by bit at its Rx pin. The receiving UART then converts the data back into parallel form and removes the start bit. parity bit and stop bits Finally, the Receiving UART transfers the data packet in parallel to the data bus on the receiving end. 1.2.1 Steps 1. Type the program in the Arduino IDE. 2. Connect the Arduino board with the CPU using the USB cable 3. Save the program 4. In Arduino IDE, Tools Board-> Select Arduino UNO 5. In Arduino IDE. Tools-> Port-> Select port for Arduino UNO 6. Verify the program 7. Upload the program. 8. Click on the serial monitor (right-hand side corner) for output. Dept. of CSE, SaIT 2023-2024 1
  • 9. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 2 1.3 Implementation Code --Program Code to Transmit a String using UART-- int led = 13; int value = 0; void setup() { Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { if (Serial.available() > 0) { value = Serial.read(); delay(5); if (value == '1') { digitalWrite(led, HIGH); Serial.println("LED is ON"); } if (value == '0') { digitalWrite(led, LOW); Serial.println("LED is OFF"); } } } 1.4 Demonstration Fig. 1.1 Hardware setup to Transmit a String on Arduino UNO
  • 10. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 3 Fig. 1.2 String being Transmitted in Output Screen
  • 11. Dept. of CSE, SaIT 2023-2024 4 Experiment 02 Point-to-Point Communication of Motes over the Radio Frequency. 2.1 Introduction A Point-to-Point connection (P2P) refers to a permanent direct communication link between two parties. The two units communicate using either Frequency Division Multiplexing or Time Division Multiplexing to allow for bidirectional traffic flow. For fixed links, this can involve useof high gain directional antennas which enable long-distance and high-capacity links. Radio frequency is the measurement representing the oscillation rate of the electromagnetic radiation spectrum, or electromagnetic radio waves, from frequencies ranging from 300 GHz toas low as 9 kHz Components Required: Node MCU, ESP8266, USB B Type Cable, NRF24L01. 2.2 Working NRF24L01 Transceiver Module (Radio Frequency) It uses the 2.4 GHz band and it can operate with baud rates from 250 kbps up to 2 Mbps. If used in open space and with a lower baud rate its range can reach up to 100 meters. The module can use 125 different channels which gives the possibility to have a network of 125 independently workingmodems in one place. Each channel can have up to 6 addresses, or each unit can communicate with up to 6 other units at the same time. The power consumption of this module is just around 12mA during transmission. which is even lower than a single LED. The operating voltage of the module is from 19 to 3.6V, but the goodthing is that the other pins tolerate 5V logic, so we can easily connect it to an Arduino without usingany logic-level converters. Three of these pins are for the SPI communication and they need to be connected to the SPI pins of the Arduino, but note that each Arduino board has different SPI pins The pins CSN and CE can be connected to any digital pin of the Arduino board and they are used for setting the module in standby or active mode, as well as for switching between transmit or command mode. The last pin is an interrupt pin which doesn’t have to be used.
  • 12. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 5 2.2.1 Steps: 1. Import RF24Network-master.zip to Arduino IDE via Sketch->Include Library-> ADD Zip library 2. Import RF24-master.zip to Arduino IDE via Sketch->Include Library-> ADD Zip library 3. Type the transmitter code in Arduino IDE and select board and port for first Arduino uno. Uploadthe code to transmitter Arduino (first Arduino). 4. 4.Type the receiver code in another Arduino IDE and select board and port for second Arduino uno.Upload the code to receiver Arduino (second Arduino). 5. If data sent in the code is 'I' then LED in receiver will be ON otherwise LED will be OFF. 2.3 Implementation Code --Transmitter Code-- #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define buttonPin1 3 #define buttonPin2 4 int buttonState1 = 0; int buttonState2 = 0; RF24 radio(9, 8); // CE, CSN const byte address[6] = "00002"; void setup() { pinMode(buttonPin1, INPUT_PULLUP); pinMode(buttonPin2, INPUT_PULLUP); Serial.begin(9600); radio.begin(); radio.openWritingPipe(address); radio.setPALevel(RF24_PA_MIN); radio.stopListening(); } void loop() { buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); if (buttonState1 == 1) { buttonState1 = 1; } else if (buttonState1 == 0) { buttonState1 = 0; } if (buttonState2 == 1) { buttonState2 = 3; } else if (buttonState2 == 0) {
  • 13. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 6 buttonState2 = 2; } Serial.print(buttonState1); Serial.print("t"); Serial.println(buttonState2); radio.write(&buttonState1, sizeof(buttonState1)); radio.write(&buttonState2, sizeof(buttonState2)); } --Receiver Code— #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define led1 A0 #define led2 A1 int buttonState = 0; RF24 radio(9, 8); // CE, CSN const byte address[6] = "00002"; void setup() { Serial.begin(9600); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MIN); } void loop() { radio.startListening(); while (!radio.available()); radio.read(&buttonState, sizeof(buttonState)); Serial.println(buttonState); if (buttonState == 1) { digitalWrite(led1, LOW); } else if (buttonState == 0) { digitalWrite(led1, HIGH); } else if (buttonState == 3) { digitalWrite(led2, LOW); } else if (buttonState == 2) { digitalWrite(led2, HIGH); } }
  • 14. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 7 Fig. 2.2 Hardware Setup to P2P Communication over Radio Frequency 2.4 Demonstration Fig. 2.1 NRF24L01Transceiver Module
  • 15. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 8 Fig. 2.3 Code Implementation for Transmitter and Receiver
  • 16. Dept. of CSE, SaIT 2023-2024 9 Experiment 03 Multi Point to Single Point Communication of Motes over the Radio frequency. LAN (Sub-netting) 3.1 Introduction Point-to-Multipoint communication refers to communication that is accomplished through a distinct and specific form of one-to-many connections, offering several paths from one location to various locations. Radio Frequency is the measurement representing the oscillation rate of the Electro Magnetic radiation spectrum, or electromagnetic radio waves, from frequencies ranging from 300 GHz toas low as 9 kHz Components Required: Node MCU, ESP8266, USB B Type Cable 3.2 Working ESP32 board to Receive Data from Multiple ESP32 boards via ESP-NOW Communication Protocol (Many- to-One Configuration). One ESP32 board acts as a receiver/slave. Multiple ESP32 boards act as senders/masters. The sender board receives an acknowledge message indicating if the message was successfully delivered or not. The ESP32 Receiver Board receives the messages from all senders and identifies which board sent the message. 3.2.1 Steps: 1. Gather the Receiver ESP32’s MAC Address via ESP-NOW. 2. ESP32 Sender Code (ESP-NOW) 3. Add peer Device. 4. Send ESP-NOW message. 5. ESP32 Receiver Code (ESP-NOW)
  • 17. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 10 3.3 Implementation Code --Code Snippet to Print Receiver’s MAC Address-- #ifdef ESP32 #include <WiFi.h> #else #include <ESP8266WiFi.h> #endif void setup(){ Serial.begin(115200); Serial.println(); Serial.print("ESP Board MAC Address: "); Serial.println(WiFi.macAddress()); } void loop(){ } --Sender’s Code— #include <esp_now.h> #include <WiFi.h> // REPLACE WITH THE RECEIVER'S MAC Address uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Structure example to send data // Must match the receiver structure typedef struct struct_message { int id; // must be unique for each sender board int x; int y; } struct_message; // Create a struct_message called myData struct_message myData; // Create peer interface esp_now_peer_info_t peerInfo; // callback when data is sent
  • 18. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 11 void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("rnLast Packet Send Status:t"); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); } void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_register_send_cb(OnDataSent); // Register peer memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } } void loop() { // Set values to send myData.id = 1; myData.x = random(0,50); myData.y = random(0,50); // Send message via ESP-NOW esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } delay(10000); }
  • 19. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 12 --Sender’s ESP Message— esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } --Receiver’s Code— #include <esp_now.h> #include <WiFi.h> // Structure example to receive data // Must match the sender structure typedef struct struct_message { int id; int x; int y; }struct_message; // Create a struct_message called myData struct_message myData; // Create a structure to hold the readings from each board struct_message board1; struct_message board2; struct_message board3; // Create an array with all the structures struct_message boardsStruct[3] = {board1, board2, board3}; // callback function that will be executed when data is received void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) { char macStr[18]; Serial.print("Packet received from: "); snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); Serial.println(macStr); memcpy(&myData, incomingData, sizeof(myData)); Serial.printf("Board ID %u: %u bytesn", myData.id, len); // Update the structures with the new incoming data boardsStruct[myData.id-1].x = myData.x; boardsStruct[myData.id-1].y = myData.y; Serial.printf("x value: %d n", boardsStruct[myData.id-1].x); Serial.printf("y value: %d n", boardsStruct[myData.id-1].y); Serial.println(); }
  • 20. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 13 void setup() { //Initialize Serial Monitor Serial.begin(115200); //Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); //Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for recv CB to // get recv packer info esp_now_register_recv_cb(OnDataRecv); } void loop() { // Acess the variables for each board /*int board1X = boardsStruct[0].x; int board1Y = boardsStruct[0].y; int board2X = boardsStruct[1].x; int board2Y = boardsStruct[1].y; int board3X = boardsStruct[2].x; int board3Y = boardsStruct[2].y;*/ delay(10000); } 3.4 Demonstration Fig. 3.1 ESP Many-to-One Structure
  • 21. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 14 Fig. 3.2 ESP32 Many-to One (Sender -Receiver) Configuration Setup Fig. 3.3 Acknowledgement Packets received from Sender Board
  • 22. Experiment 04 I2C Protocol Study 4.1 Introduction I2C stands for inter-integrated controller. This is a serial communication protocol that is used to connect low-speed devices. It is a master-slave communication in which we can connect and control multiple slaves from a single master. It uses only 2 bi-directional open-drain lines for data communication called SDA and SCL. Both these lines are pulled high. With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame Fig 4.1 I2C Protocol Architecture Advantages:  Can be configured in multi-master mode  Complexity is reduced because it uses only 2 bi-directional lines  Cost-efficient  It uses ACK/NACK feature due to which it has improved error handling capabilities Limitations:  Slower speed Half-duplex communication is used in the I2C communication protocol. Dept. of CSE, SaIT 2023-2024 15
  • 23. IoT Laboratory Report 4.2 Working I2C Communication Protocol uses only 2 bi-directional open-drain lines for data communication called SDA and SCL. • Serial Data (SDA) – Transfer of data takes place through this pin. • Serial Clock (SCL) – It carries the clock signal. I2C operates in 2 modes • Master mode • Slave mode Each data bit transferred on SDA line is synchronized by a high to the low pulse of each clock on the SCL line. Fig 4.2 I2C Communication between Master and Slave Dept. of CSE, SaIT 2023-2024 16
  • 24. Dept. of CSE, SaIT 2023-2024 17 Experiment 05 Reading Temperature and Relative Humidity Value from the Sensor 5.1 Introduction DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). It's fairly simple to use but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old. DHT11 is a relative humidity sensor. To measure the surrounding air this sensor uses a thermistor and a capacitive humidity sensor. DHT11 has a Capacitive Sensor for measuring humidity & NTC Thermistor for temperature sensing. (We will cover them in detail below). It calibrates the humidity using humidity coefficients, which are stored in the OTP program memory of the built-in controller. The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one reading for every second. DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum current used while measuring is 2.5mA. Components Required: Node MCU, DHT sensor, USB B Type Cable. 5.2 Working The DHT - Digital Temperature and Humidity sensor is set to pin 2 and Blynk app is listened on Serial monitor connection. The V0 pin is monitored continuously and any change results in calling dht() function. The DHT sensor monitors the floating-point values of Temperature in °C and Humidity and writes to the Blynk app through V2 pin. This dht() function repeats in loop for continuous monitoring of the values of temperature and humidity. The Node MCU is connected with the DHT11 sensor. The libraries such as: • Adafruit library • DHT sensor library • Firebase ESP8266 library • Blynk Library
  • 25. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 18 5.2.1 Steps: 1. Add the libraries by navigating to 2. Sketch >> Include Library >> 3. Add .zip library >> Select .zip file and load. 4. Thereby the values with respect to DHT can be obtained in real-time. 5.3 Implementation Code #include <dht11.h> #define DHT11PIN 4 dht11 DHT11; void setup() { Serial.begin(9600); } void loop() { Serial.println(); int chk = DHT11.read(DHT11PIN); Serial.print("Humidity (%): "); Serial.println((float)DHT11.humidity, 2); Serial.print("Temperature (C): "); Serial.println((float)DHT11.temperature, 2); delay(2000); }
  • 26. IoT Laboratory Report Dept. of CSE, SaIT 2023-2024 19 5.4 Demonstration Fig. 5.1 Hardware Setup for Measuring Temperature and Relative Humidity. Fig. 5.2 Temperature and Humidity displayed over the Output Console.