IoT Lab Manual - VTU (21EC581) by Raviteja Balekai

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 284

Internet of Things Lab (21EC581) 5th Sem B.

Internet of Things
Lab Manual

Prepared By:

Mr. Raviteja Balekai Mr.Raghudathesh G P, Dr. Prathviraj N


Asst.Professor, Manipal School of Information Sciences,
Department of ECE, Manipal Academy of Higher Education,
GMIT, Davangere Manipal

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 1


Internet of Things Lab (21EC581) 5th Sem B.E

FIVE DAYS FACULTY DEVELOPMENT


PROGRAMME (FDP)
On

Ability Enhancement Course-IoT Lab


(As per 5th Semester VTU 2021 Scheme)
06 to 10 November-2023
th th

In Collaboration with

Manipal School of Information Sciences


(MSIS), Manipal
Sponsored by
Visvesvaraya Technological University,
Belagavi,
&
Indian Society for Technical Education, Karnataka
Section

Mr.Raviteja Balekai , Mr.Raghudathesh G P & Dr. Prathviraj N Page 2


CHIEF PATRONS COORDINATORS & CONTACT PERSONS ARKA Education & Cultural Trust®
Dr. Chenraj Roychand Dr. Rajendra Soloni
JAIN INSTITUTE OF TECHNOLOGY
Chairman, Jain Group of Institutions, Bengaluru (A unit of Jain Group of Institutions, Bangalore)
Associate Professor (Approved by AICTE, New Delhi, Affiliated to VTU, Belagavi,
Dept. of E&CE, JIT, Davanagere Recognized by Govt. of Karnataka)
Sri. Achalchand Jain Mob. No.: 8892668693
President, Jain Institute of Technology, Davanagere Email ID : rajendrasoloni@jitd.in

PATRONS Mr. Sharanabasaveshwara H B


Dr. S Vidyashankar Assistant Professor
Vice-Chancellor, VTU, Belagavi Dept. of E&CE, JIT, Davanagere FIVE DAYS FACULTY DEVELOPMENT
Dr. B.E. Rangaswamy Mob. No.: 7892034517
Email ID : sharanabasaveshwarahb@jitd.in PROGRAMME (FDP)
Registrar, VTU, Belagavi
On
CHAIRMAN PROGRAM COMMITTEE
Dr. Santosh Herur, Chairman & Convener, Professor & Head, “Ability Enhancement Course-IoT Lab”
Dr. Ganesh D B Dept. of E&CE, JITD (As per 5th Semester VTU 2021 Scheme)
Principal and Director, Dr. Rajendra Soloni, Coordinator, Assoc. Professor, Dept. of 06th to 10th November-2023
JIT, Davangere E&CE, JITD
Mr. Sharanabasaveshwara H B, Coordinator, Asst. Professor, In Collaboration with
CONVENER Dept. of E&CE, JITD
Manipal School of Information Sciences,
Dr. Santosh Herur Dr. Ravi Rayappa, Assoc. Professor, Dept. of E&CE, JITD
Mr. Ravikumar K I, Asst. Professor, Dept. of E&CE, JITD Manipal
Professor and Head
Dept. of E&CE, JIT, Davanagere Mrs. Pushpalatha. O, Asst. Professor, Dept. of E&CE, JITD Sponsored by
Mrs. Rajeshwari H M, Asst. Professor, Dept. of E&CE, JITD
ADVISORY COMMITTEE Mrs. Deepthi G B, Asst. Professor, Dept. of E&CE, JITD Visvesvaraya Technological University,
Dr. Manjappa Sarathi, Advisor, Jain Group of Institutions
Dr. Nataraj K R, Director, R&D, VTU, Belagavi
Mrs. Savitra Totad, Asst. Professor, Dept. of E&CE, JITD Belagavi
Mrs. Savita M, Asst. Professor, Dept. of E&CE, JITD
Dr. Sadashiv Halbhavi, Special Officer, VTU, Belagavi
Mrs. Anusha K, Asst. Professor, Dept. of E&CE, JITD &
Dr. Nagashettappa Biradar, Chairman-BOS (E&CE), VTU
Principal, BKIT, Bhalki Mr. Sunil M, Asst. Professor, Dept. of E&CE, JITD Indian Society for Technical Education,
Mrs. Anusha T S, Asst. Professor, Dept. of E&CE, JITD
Dr. S. V. Satyanarayana, BOS Member (E&CE), VTU Karnataka Section
Professor, Dept. of E&CE, JNNCE, Shivamogga Mrs. Shilpa M, Asst. Professor, Dept. of E&CE, JITD
Dr. Jagadish Chandra, BOS Member (E&CE), VTU
Professor, Dept. of E&CE, AIT, Chikmagalur TARGETED PARTICIPANTS
Dr. S. K. Shreedhara Murthy, BOS Member (E&CE), VTU
Professor, Dept. of E&CE, UBDTCE, Davangere
Faculty members of VTU affiliated Engineering
Dr. Manju T. M., BOS Member (E&CE), VTU
Professor, Dept. of E&CE, KLEIT, Hubballi
Colleges who are handling Ability Enhancement
Dr. Savita Sonoli, BOS Member (E&CE), VTU Course-IoT Lab (21EC581) and willing to learn IoT
Vice Principal & HOD, Dept. of E&CE, RBYMEC, Bellary Technology.
Dr. Jayashri Rudagi, BOS Member (E&CE), VTU Organized by
Professor, Dept. of E&CE, SGBIT, Belagavi NOTE Dept. of Electronics and Communication
Dr. Suresh D., BOS Member (E&CE), VTU
Professor, Dept. of E&CE, RNSIT, Bengaluru A maximum of 30 participants are accepted. All Engineering
Dr. Girish V Attimarad, BOS Member (E&CE), VTU
individuals are welcome to register, and preference Jain Institute of Technology, Davanagere
Professor, Dept. of E&CE, KSSEM, Bengaluru #323, Near Veereshwar Punyashrama, Davanagere – 577003
will be given on a first-come-first-served basis. No TA
Dr. C.P. Ravikumar, BOS Member Industry (E&CE), VTU Website: https://www.jitd.in
Director of TTD, Texas Instruments, Bengaluru
and DA will be given. Arrangements for
Dr. Somsing Rathod, BOS Member Industry (E&CE), VTU accommodation will be made based on your
Scientist- E in E&RDE (LRDE), DRDO, Bengaluru requirements on advance payments.
ABOUT VTU, BELAGAVI ABOUT JIT, DAVANAGERE and technologies. Objectives of the FDP is to provide
 The program involves the development of Ability
VTU is one of the largest Technological Universities in JIT is one of the best developing engineering colleges Enhancement Course-IoT Lab with respect to the
India with 24 years of Tradition of excellence in of Davangere and is located adjacent to Pune 2021 VTU scheme syllabus (21EC581) for 5th
Engineering & Technical Education, Research and Bangalore National Highway. It has lush green semester students.
Innovations. It came into existence in the year 1998 campus. Three programs namely, Computer Science  Faculty members are trained in the technical
to cater the needs of Indian industries for trained and Engineering, Electrical and Electronics aspects of IoT, including hardware components
technical manpower with practical experience and Engineering, Electronics and Communication (sensors, actuators, and microcontrollers),
sound theoretical knowledge. University has very Engineering are accredited by National Board of communication protocols (such as MQTT or HTTP),
successfully achieved the tremendous task of bringing Accreditation, New Delhi. The college has excellent data analytics, and IoT security. Hands-on training
various colleges affiliated earlier to different infrastructural facilities that include spacious class is the part of this FDP.
Universities, with different syllabi, different rooms, well-equipped laboratories, Workshops,  Familiarity with popular IoT development
procedures and different traditions under one Drawing halls, seminar halls, digital library, EDUSAT platforms and tools, such as Arduino, Raspberry
umbrella. The university is currently having 182 room etc. The college has well experienced & dedicated Pi, and cloud-based IoT platforms is included in
affiliated colleges, 1 constituent college and 25 faculty and a strong student’s mentorship program. this training. Faculty members learn about the
Autonomous colleges with undergraduate programs in latest trends and real-world applications of IoT.
37 disciplines, PG programs in 96 disciplines and
ABOUT DEPARTMENT
Ph.D. & M.Sc (Engg.) Research programs with 7 The Department of Electronics and Communication This Faculty Development Program is essential for
faculty, over 3 lakhs Engineering Students study in Engineering was started in the year 2011-12. The faculty members to educate the next generation IoT
the various institutes affiliated to the University. department emphasizes on imparting advanced professionals. As the field of IoT continues to evolve,
technical knowledge in various fields like Signal staying up-to-date and adapting teaching methods
ABOUT ISTE processing, VLSI Technology, Embedded system, and materials are crucial for providing quality
Wireless technology, Microwave Engineering, Optical education in this area.
The Indian Society for Technical Education (ISTE) is
Communication, Micro Electronics and Control RESOURCE PERSONS
the leading National Professional non-profit making
Systems. Highly qualified, experienced and dedicated
Society for the Technical Education System in our
staff members are the backbone of the department. 1. Dr. Prathviraj N, Associate Professor, Manipal School of
country with the motto of Career Development of Information Sciences, Manipal
ENCORE association of the department of E & CE
Teachers and Personality Development of Students 2. Mr. Raghudathesh G P, Assistant Professor - Senior
aims at targeting innovations in the field of advanced
and overall development of our Technical Education Scale, Manipal School of Information Sciences, Manipal
Electronics & Communication. The ECE department is
System. Being the only national organization of 3. Mr. Raviteja B, Assistant Professor, Dept. of E&CE,
accredited by NBA.
educators in the field of Engineering and Technology, G M Institute of Technology, Davanagere
ISTE effectively contributes in various missions of the 4. Dr. Santosh Herur, Professor & Head, Dept. of E&CE,
ABOUT FDP
Union Government. The strength of ISTE is the strong Jain Institute of Technology, Davanagere
base it has in technical education institutions in the
An IoT (Internet of Things) Faculty Development REGISTRATION (FREE)
country. ISTE has an Executive Council at National
Program is designed to equip faculty members with
level The major objective of the ISTE is to provide 1. For registration of the FDP, please visit:
the knowledge and skills necessary to teach and
quality training programmes to teachers and
mentor students in the field of IoT. IoT refers to the https://forms.gle/Z6sDwBfYWCVWMzCz7
administrators of technical institutions to update
interconnectedness of devices and objects through
their knowledge and skills in their fields of activity 2. Fill in all necessary details.
the internet, allowing them to collect and exchange
and to assist and contribute in the production and
data for various applications. IoT is a rapidly evolving IMPORTANT DATES
development of top quality professional engineers and
field with numerous applications across industries, Last date (Online Registration): 03-11-2023
technicians needed by the industry and other
making it essential for educational institutions to Selection Intimation by E-mail: 04-11-2023
organizations.
prepare their faculty to effectively teach IoT concepts Duration: 06-11-2023 to 10-11-2023
Internet of Things Lab (21EC581) 5th Sem B.E

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 3


Internet of Things Lab (21EC581) 5th Sem B.E

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 4


Internet of Things Lab (21EC581) 5th Sem B.E

Exp.No Experiments
i. To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to
turn ON LED for 1 sec after every 2 seconds.

1 ii. To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry


Pi and write a program to turn ON LED when push button is pressed or at
sensor detection.
i. To interface DHT11 sensor with Arduino/Raspberry Pi and write a program
to print temperature and humidity readings.
2
ii. To interface OLED with Arduino/Raspberry Pi and write a program to print
temperature and humidity readings on it.
To interface motor using relay with Arduino/Raspberry Pi and write a program to
3
turn ON motor when push button is pressed.
To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED
4
ON/OFF when '1'/'0' is received from smartphone using Bluetooth.
To interface Bluetooth with Arduino/Raspberry Pi and write a program to send
5
sensor data to smartphone using Bluetooth.
Write a program on Arduino/Raspberry Pi to upload temperature and humidity data
6
to thingspeak cloud.
Write a program on Arduino/Raspberry Pi to retrieve temperature and humidity
7
data from thingspeak cloud.
Write a program on Arduino/Raspberry Pi to publish temperature data to MQTT
8
broker.
Write a program on Arduino/Raspberry Pi to subscribe to MQTT broker for
9
temperature data and print it.
Write a program to create UDP server on Arduino/Raspberry Pi and respond with
10
humidity data to UDP client when requested.
Write a program to create TCP server on Arduino/Raspberry Pi and respond with
11
humidity data to TCP client when requested.

12 To install MySQL database on Raspberry Pi and perform basic SQL queries.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 5


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 1
i. 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
Arduino/ 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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 6


Internet of Things Lab (21EC581) 5th Sem B.E

(d) LED interfacing with Raspberry Pi

CODING:

Embedded C

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
}

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 7


Internet of Things Lab (21EC581) 5th Sem B.E

Python code

import time

# blinking function
def blink(pin):
GPIO.output(pin,GPIO.HIGH)
time.sleep(1)
GPIO.output(pin,GPIO.LOW)
time.sleep(2)
return

# to use Raspberry Pi board pin numbers


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

# set up GPIO output channel


GPIO.setup(17,GPIO.OUT)

# blink GPIO17 10 times


for i in range(0,10):
blink(17)
GPIO.cleanup()

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 8


Internet of Things Lab (21EC581) 5th Sem B.E

ii. To interface Push button/Digital sensor (IR/LDR) with Arduino UNO and write a
program to turn ON LED when push button is pressed or at sensor detection.

CASE -1

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

COMPONENTS REQUIRED:

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

CONNECTION DIAGRAM:

(a) Push button interfacing with Arduino

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 9


Internet of Things Lab (21EC581) 5th Sem B.E

CODING:

Embedded C

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

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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 10


Internet of Things Lab (21EC581) 5th Sem B.E

CASE -2

AIM: Write a program to turn ON LED at sensor (LDR) detection using Arduino UNO.

COMPONENTS REQUIRED:

1. Arduino UNO.
2. LDR.
3. LED.
4. Resistor (100KΩ)
5. Connecting cable or USB cable.
6. Breadboard.
7. Jumper wires.

CONNECTION DIAGRAM:

(b) LDR interfacing with Arduino

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 11


Internet of Things Lab (21EC581) 5th Sem B.E

CODING:

Embedded C

int sensorPin = A0; // select the input pin for LDR


int sensorValue = 0; // variable to store the value coming from the sensor
int led=13;
void setup()
{
Serial.begin(9600); //sets serial port for communication
pinMode(13, OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the
screen

if (sensorValue<400)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
delay(1000);
}

RESULT: Controlling LED by interfacing LDR with Arduino UNO has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 12


Internet of Things Lab (21EC581) 5th Sem B.E

CASE -3

AIM: Write a program to turn ON LED at sensor (IR) detection using Arduino UNO.

COMPONENTS REQUIRED:

1. Arduino UNO.
2. IR.
3. LED.
4. Resistor (220Ω)
5. Connecting cable or USB cable.
6. Breadboard.
7. Jumper wires.

CONNECTION DIAGRAM:

(c) IR sensor

(d) IR sensor interfacing with Arduino

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 13


Internet of Things Lab (21EC581) 5th Sem B.E

CODING:

Embedded C

int IR=9;
int IRvalue;
int LED=13;

void setup()
{
Serial.begin(9600);
pinMode(IR, INPUT);
pinMode(LED, OUTPUT); // LED Pin Output
}

void loop()
{
IRvalue=digitalRead(IR);
if (IRvalue==1)
{
digitalWrite(LED, HIGH); // LED High
Serial.println("Object detected");
}
else
{
digitalWrite(LED, LOW);
Serial.println("Object is not detected");
}
delay(1000);
}

RESULT: Object detection by interfacing IR with Arduino UNO has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 14


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 2
i. 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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 15


Internet of Things Lab (21EC581) 5th Sem B.E

(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:

Embedded C

#define dht_dpin 2
#include<dht.h>
dht DHT;

void setup()
{
Serial.begin(9600);
Serial.println("Humidity and temperature\n\n");
}
void loop()
{

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 16


Internet of Things Lab (21EC581) 5th Sem B.E

//This is the "heart" of the program.


DHT.read11(dht_dpin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(1000);
}

You need to install PIP before you can install the Adafruit_DHT module:

sudo pip3 install Adafruit_DHT

Python code

import time
#import sys
import Adafruit_DHT
while(1):
humidity, temperature = Adafruit_DHT.read_retry(11, 4) # Sensor ,GPIO Pin
print("-------------------------------------------")
print('Temp:{0:0.1f} C, Humidity:{1:0.1f} %'.format(temperature, humidity))
print("-------------------------------------------")

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 17


Internet of Things Lab (21EC581) 5th Sem B.E

ii. To interface OLED/I2C LCD with Arduino/Raspberry Pi and write a program to


print temperature and humidity readings on it.

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

COMPONENTS REQUIRED:

1. Arduino UNO/ Raspberry Pi.


2. DHT11.
3. (0.96 Inch) I2C/IIC 4pin OLED Display Module / I2C LCD .
4. Connecting cable or USB cable.
5. Jumper wires.

CONNECTION DIAGRAM:

(d) 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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 18


Internet of Things Lab (21EC581) 5th Sem B.E

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.

Steps to interface I2C LCD with Arduino:


Step 1: Install the library for LCD display in Arduino IDE.
 Open Arduino IDE and navigate to Sketch > Include Library > Manage
Libraries.
 Search for “LiquidCrystal I2C” and install the “LiquidCrystal I2C” library in the
Arduino IDE.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 19


Internet of Things Lab (21EC581) 5th Sem B.E

Step 2: Import “LiquidCrystal_I2C.h” header file in the code.


 Define header file in the code #include <LiquidCrystal_I2C.h> .
Step 3: Connect I2C LCD 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 LCD module is 0x27.

(e) I2C LCD interfacing with Arduino UNO

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 20


Internet of Things Lab (21EC581) 5th Sem B.E

CODING:

Embedded C

Displaying Temperature and Humidity in the OLED Display with Arduino

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define dht_dpin 7
#include<dht.h>
dht DHT;

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


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

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


// The (-1) parameter means that your OLED display doesn’t have a RESET pin.
// If your OLED display does have a RESET pin, it should be connected to a GPIO.
// In that case, you should pass the GPIO number as a parameter.

void setup()
{
Serial.begin(115200);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}

delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}

void loop()
{
delay(5000);
//clear display
display.clearDisplay();

// display temperature
DHT.read11(dht_dpin);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Temp=");
display.print(DHT.temperature); //print the temperature
display.print(" Celsius");
display.display();

// display humidity

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 21


Internet of Things Lab (21EC581) 5th Sem B.E

display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity=");
display.print(DHT.humidity); //print the humidity
display.print("%");
display.display();

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

Displaying Temperature and Humidity in the I2C LCD with Arduino

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
#define dht_dpin 7
#include<dht.h>
dht DHT;

void setup()
{
Serial.begin(9600);
lcd.begin();
}

void loop()
{
DHT.read11(dht_dpin);
lcd.setCursor(0, 0);//(Col,ROW)
lcd.print("Temp=");
lcd.print(DHT.temperature); //print the temperature
lcd.print("Celsius");

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 22


Internet of Things Lab (21EC581) 5th Sem B.E

lcd.setCursor(0, 1);//(Col,ROW)
lcd.print("Humidity=");
lcd.print(DHT.humidity); //print the humidity
lcd.print("%");
delay(2000);
}

(g) Displaying Temperature and Humidity values on I2C LCD using Arduino UNO

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 23


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 3
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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 24


Internet of Things Lab (21EC581) 5th Sem B.E

(b) Interfacing motor with relay using Arduino

CODING:

Embedded C

#define RELAY_PIN 8 // Digital pin connected to the relay module


#define BUTTON_PIN 2 // Digital pin connected to the push button
void setup()
{
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
}
void loop()
{
int buttonState = digitalRead(BUTTON_PIN);

if(buttonState == HIGH)
{
// Button is pressed, turn ON the motor via relay
digitalWrite(RELAY_PIN, HIGH);
delay(1000); // Delay for motor ON time (1 second in this case)
} else
{
// Button is not pressed, turn OFF the motor via relay
digitalWrite(RELAY_PIN, LOW);
}
}

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 25


Internet of Things Lab (21EC581) 5th Sem B.E

(c) 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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 26


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 4
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:

Embedded C

// Interfacing LED with ESP32 and controlling LED through Bluetooth


#include <BluetoothSerial.h>
#define ledPIN 2 //D2 pin
BluetoothSerial SerialBT;
byte BTData;
/* Check if Bluetooth configurations are enabled in the SDK */

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 27


Internet of Things Lab (21EC581) 5th Sem B.E

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)


#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
void setup()
{
pinMode(ledPIN, OUTPUT);
Serial.begin(115200);
SerialBT.begin();
Serial.println("Bluetooth Started! Ready to pair...");
}
void loop()
{
if(SerialBT.available())
{
BTData = SerialBT.read();
Serial.write(BTData);
}
if(BTData == '1')
{
digitalWrite(ledPIN, HIGH);
}
/* If received Character is 0, then turn OFF the LED */
if(BTData == '0')
{
digitalWrite(ledPIN, LOW);
}
}

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 28


Internet of Things Lab (21EC581) 5th Sem B.E

(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 with
ESP32 has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 29


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 5
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:

Embedded C

// Interfacing DHT11 with ESP32 and sending data to mobile through Bluetooth

#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
byte BTData;
#include "DHT.h"
DHT dht(2,DHT11); //D4 pin

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 30


Internet of Things Lab (21EC581) 5th Sem B.E

/* Check if Bluetooth configurations are enabled in the SDK */


#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

void setup()
{
Serial.begin(115200);
SerialBT.begin();
Serial.println("Bluetooth Started! Ready to pair...");
}

void loop()
{
Serial.print("Temperature in c :");
Serial.println(dht.readTemperature( ));
String temperatureString = String(dht.readTemperature( ));
SerialBT.println(temperatureString);
delay(2000);
}

(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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 31


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 6
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:

Embedded C

//Interfacing DHT11 to ESP32 to upload temperature and humidity data to


thingspeak cloud

#include <DHT.h>
#include <WiFi.h>
#include <WiFiClient.h>

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 32


Internet of Things Lab (21EC581) 5th Sem B.E

#include <ThingSpeak.h>
#include <Adafruit_Sensor.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "GMIT";
const char* password = "DAVANGERE";
WiFiClient client;
unsigned long myChannelNumber = 12345;
const char * myWriteAPIKey = "ABCDEFGH";
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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 33


Internet of Things Lab (21EC581) 5th Sem B.E

// pieces of information in a channel. Here, we write to field 1 and 2.

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


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

(b) Displaying temperature and humidity data on ThingSpeak cloud

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 34


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 7
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:

Embedded C

// Retrieving temperature and humidity data from Thingspeak cloud using ESP32
#include <WiFi.h>
#include <ThingSpeak.h>
WiFiClient client;
void setup()
{

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 35


Internet of Things Lab (21EC581) 5th Sem B.E

Serial.begin(9600);
ThingSpeak.begin(client);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("GMIT","DAVANGERE");
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(12345,1,"ABCDEFGH")));
Serial.print("Humidity=");
Serial.println((ThingSpeak.readIntField(12345,2,"ABCDEFGH")));
delay(3000);
}

(b) Available temperature and humidity data on ThingSpeak cloud

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 36


Internet of Things Lab (21EC581) 5th Sem B.E

(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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 37


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 8
Write a program on Arduino/Raspberry Pi to publish temperature data to MQTT broker.

AIM: Write a program on ESP32 to publish temperature and humidity values using DHT11
sensor to MQTT broker.

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:

Embedded C

/****************************************************/
#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "DHT.h"
/************************* WiFi Access Point *********************************/

#define WLAN_SSID "GMIT"


#define WLAN_PASS "Davangere"

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 38


Internet of Things Lab (21EC581) 5th Sem B.E

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"


#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "ABCDE"
#define AIO_KEY "A1B2C3D4E5F6G7"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.


WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and
login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME,
AIO_KEY);

/****************************** Feeds ***************************************/

// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>


Adafruit_MQTT_Publish sensor_1 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME
"/feeds/Temperature"); /// Temperature Value
Adafruit_MQTT_Publish sensor_2 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME
"/feeds/Humidity"); /// Humidity Value

// Setup a feed called 'onoff' for subscribing to changes.


//Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/onoff");

/*************************** Sketch Code ************************************/

void MQTT_connect();

void setup() {
Serial.begin(115200);
delay(10);
Serial.println(F("Adafruit MQTT demo"));

// Connect to WiFi access point.


Serial.println(); Serial.println();
Serial.print("Connecting to ");

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 39


Internet of Things Lab (21EC581) 5th Sem B.E

Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// Setup MQTT subscription for onoff feed.


//mqtt.subscribe(&onoffbutton);
}

uint32_t x=0;

void loop()
{
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected).
// See the MQTT_connect
// function definition further below.
MQTT_connect();

// Now we can publish stuff!

Serial.print(F("\nSending Sensor's Value "));


DHT dht(4,DHT11); //D4 on board numbering system
Serial.print("Sensor 1 ");
Serial.println((dht.readTemperature( )));
delay(3000);
Serial.print("...");
float Value = dht.readTemperature( );
if (! sensor_1.publish(Value))
{
Serial.println(F("Failed"));
}
else
{
Serial.println(F("OK!"));
}

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 40


Internet of Things Lab (21EC581) 5th Sem B.E

Serial.print("Sensor 2 ");
Serial.println((dht.readHumidity( )));
Serial.print("...");
int Value1 = dht.readHumidity( );
delay(3000);
if (! sensor_2.publish(Value1))
{
Serial.println(F("Failed"));
}
else
{
Serial.println(F("OK!"));
}

delay(3000);

// Function to connect and reconnect as necessary to the MQTT server.


// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;

// Stop if already connected.


if (mqtt.connected()) {
return;
}

Serial.print("Connecting to MQTT... ");

uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 41


Internet of Things Lab (21EC581) 5th Sem B.E

(b) Displaying temperature and humidity data on Adafruit IO platform

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

RESULT: Published temperature and humidity data to MQTT broker with ESP32 has
successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 42


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 9
Write a program on Arduino/Raspberry Pi to subscribe to MQTT broker for temperature
data and print it.

AIM: Write a program on ESP32 to subscribe to MQTT broker for temperature data and print it.

COMPONENTS REQUIRED:

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

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with ESP32 (Publisher)


(b) ESP32 (Subscriber)

CODING:

Embedded C

#include <ESP8266WiFi.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_Client.h>

#define WIFI_SSID "GMIT"


#define WIFI_PASS "DAVANGERE"
#define ADAFRUIT_SERVER "io.adafruit.com"
#define ADAFRUIT_PORT 1883
#define ADAFRUIT_USERNAME "VTU"

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 43


Internet of Things Lab (21EC581) 5th Sem B.E

#define ADAFRUIT_KEY "A1B2C3D4E5F6G7H8"

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, ADAFRUIT_SERVER, ADAFRUIT_PORT,
ADAFRUIT_USERNAME, ADAFRUIT_USERNAME, ADAFRUIT_KEY);

Adafruit_MQTT_Subscribe Temperature = Adafruit_MQTT_Subscribe(&mqtt,


ADAFRUIT_USERNAME "/feeds/Temperature");

void MQTT_connect() {
int8_t ret;

// Stop if already connected.


if (mqtt.connected()) {
return;
}

Serial.print("Connecting to MQTT... ");

while ((ret = mqtt.connect()) != 0) {


Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
}

Serial.println("MQTT Connected!");
}

void setup() {
Serial.begin(115200);
delay(10);

// Connect to Wi-Fi
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);

WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 44


Internet of Things Lab (21EC581) 5th Sem B.E

Serial.println("WiFi connected");
Serial.println("IP Address: ");
Serial.println(WiFi.localIP());

mqtt.subscribe(&Temperature);
}

void loop() {
MQTT_connect();

Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000)))
{
if (subscription == &Temperature)
{
Serial.print(F("Received temperature value is: "));
Serial.println((char *)Temperature.lastread);
}
}
}

(c) Receiving the temperature data on serial monitor of Arduino IDE

RESULT: Program on ESP32 to subscribe to MQTT broker for temperature data and printing
the data has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 45


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 10
Write a program to create UDP server on Arduino/Raspberry Pi and respond with
humidity data to UDP client when requested.

AIM: Write a program to create UDP server on NodeMCU (ESP8266) and respond with
humidity data to UDP client when requested.

COMPONENTS REQUIRED:

1. NodeMCU (ESP8266).
2. DHT11.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with NodeMCU

CODING:

Embedded C

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "DHT.h"
DHT dht(14,DHT11); //D5 on board numbering system & 14 GPIO numbering system

const char* ssid = "Ravitej";


const char* password = "sharada10";
const int udpPort = 5219; // UDP port to listen on 5219

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 46


Internet of Things Lab (21EC581) 5th Sem B.E

WiFiUDP udp;

void setup() {
Serial.begin(115200);
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(1000);
Serial.println("Connecting to WiFi...");
}

Serial.println("WiFi connected.");
Serial.println("UDP server started");
udp.begin(udpPort);
}

void loop() {
char packetBuffer[255]; // buffer to hold incoming packet

int packetSize = udp.parsePacket();


if (packetSize) {
// receive incoming UDP packet
int len = udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}

// check if the received packet is a request for humidity data


if (strcmp(packetBuffer, "GET_H") == 0) {
// replace the following line with your humidity sensor reading logic
float humidity = readHumidity(); // function to read humidity data

// send humidity data back to the client


udp.beginPacket(udp.remoteIP(), udp.remotePort());
udp.printf("Humidity: %.2f%%", humidity);
udp.endPacket();
}
}
delay(1000); // add a small delay to avoid excessive response
}

float readHumidity()
{

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 47


Internet of Things Lab (21EC581) 5th Sem B.E

// Read data from a DHT sensor


float humidity = dht.readHumidity();
return humidity;

(b) Receiving humidity on UDP client based on request to UDP server NodeMCU (ESP8266)

RESULT: Received humidity data to UDP client from UDP server on NodeMCU (ESP8266)
has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 48


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 11
Write a program to create TCP server on Arduino/Raspberry Pi and respond with
humidity data to TCP client when requested.

AIM: Write a program to create TCP server on NodeMCU (ESP8266) and respond with
humidity data to TCP client when requested.

COMPONENTS REQUIRED:

1. NodeMCU (ESP8266).
2. DHT11.
3. Connecting cable or USB cable.
4. Breadboard.
5. Jumper wires.

CONNECTION DIAGRAM:

(a) Interfacing DHT11 with NodeMCU

CODING:

Embedded C

#include <ESP8266WiFi.h>
#include "DHT.h"
DHT dht(5,DHT11); //D1 on board numbering system & 5 GPIO numbering system
// Replace with your network credentials
const char* ssid = "GMIT";
const char* password = "Davangere";

WiFiServer server(80); // Create a server instance on port 80

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 49


Internet of Things Lab (21EC581) 5th Sem B.E

void setup() {
Serial.begin(115200);
delay(10);

// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");

server.begin(); // Start the server


}

void loop() {
WiFiClient client = server.available(); // Check for a client connection

if (client) {
Serial.println("New client connected");
float humidity = dht.readHumidity();
String response = "Humidity:"; // Replace this with your actual humidity data

// Send the humidity data


client.print(response);
client.print(humidity);

// Close the connection


client.stop();
Serial.println("Client disconnected");
}
}

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 50


Internet of Things Lab (21EC581) 5th Sem B.E

(b) Receiving humidity on TCP client based on request to TCP server NodeMCU (ESP8266)

RESULT: Received humidity data to TCP client from TCP server on NodeMCU (ESP8266)
has successfully executed.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 51


Internet of Things Lab (21EC581) 5th Sem B.E

EXPERIMENT – 12
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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 52


Internet of Things Lab (21EC581) 5th Sem B.E

 Syntax for insertion of data in table:

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


1,....,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:

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 53


Internet of Things Lab (21EC581) 5th Sem B.E

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, "neetak12@gmail.com"), (2, "Sushma
", "Singh", 62000, "sushsingh67@gmail.com"), (3, "Kavita", "Rathod",
27000, "kavitar09@gmail.com"), (4, "Mrunalini", "Deshmukh", 88000,
"mrunald78@gmail.com"), (5, "Swati", "Patel", 34000, "swatip67@gmail
.com"), (6, "Laxmi", "Kadam", 44000, "laxmik14@gmail.com"), (7, "Lal
ita", "Shah", 66000, "lalita45@gmail.com"), (8, "Savita", "Kulkarni"
, 31000, "savitak56@gmail.com"), (9, "Shravani", "Jaiswal", 38000, "
shravanij39@gmail.com"), (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;

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 54


Internet of Things Lab (21EC581) 5th Sem B.E

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

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;

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

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 55


Internet of Things Lab (21EC581) 5th Sem B.E

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;

Mr.Raviteja Balekai & Mr.Raghudathesh G P Dr. Prathviraj N Page 56


Internet of Things Lab (21EC581) 5th Sem B.E

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.

Syntax 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;

Mr.Raviteja Balekai & Mr.Raghudathesh G P Page 57


Internet of Things Lab (21EC581) 5th Sem B.E

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.

Mr.Raviteja Balekai & Mr.Raghudathesh G P Page 58


Faculty Development Programme (FDP)
on
Internet of Things Lab

Ability enhancement course – “Internet of Things Lab”


for 5th sem ECE/ETE students as per VTU syllabus under 2021
scheme.
to
Everyone
By:

Mr. Raviteja Balekai


Asst. Professor , Dept of ECE
GMIT, Davangere
 What is Microcontroller ?
 What is Arduino ?
 Why Arduino ?
 How do I use Arduino?
 Getting Started with Arduino UNO
• A microcontroller (MCU) is a small computer on a single integrated
circuit that is designed to control specific tasks within electronic
systems. It combines the functions of a central processing unit (CPU),
memory, and input/output interfaces, all on a single chip.

• A typical microcontroller consists of a processor core, volatile and non-


volatile memory, input/output peripherals, and various communication
interfaces. The processor core is responsible for executing instructions
and controlling the other components of the microcontroller. The
memory is used to store data and program code, while the
input/output peripherals are used to interact with the external
environment.

• Microcontrollers are widely used in embedded systems, such as home


appliances, automotive systems, medical devices, and industrial
control systems. They are also used in consumer electronics products,
such as gaming systems, digital cameras, and audio players.
Mr.Raviteja Balekai, Asst.Professor, Dept of
4
ECE, GMIT, Davangere
• Arduino is an open-source electronics platform based on easy-to-
use hardware and software.
• Arduino boards are able to read inputs - light on a sensor, a finger
on a button, or a Twitter message - and turn it into an output -
activating a motor, turning on an LED, publishing something online.
• You can tell your board what to do by sending a set of
instructions to the microcontroller on the board. To do so you use
the Arduino programming language (based on Wiring- It is an
open-source programming framework for microcontrollers),
and the Arduino Software (IDE), based on Processing.
• Arduino was born at the Ivrea Interaction Design Institute as an
easy tool for fast prototyping, aimed at students without a
background in electronics and programming.

Mr.Raviteja Balekai, Asst.Professor, Dept of


5
ECE, GMIT, Davangere
Why Arduino?

• Inexpensive
• Cross -Platform
• Simple, clear programming environment
• Open source and extensible software
(The Arduino software is published as open source tools, available for extension by experienced
programmers)

• Open source and extensible hardware


(The plans of the Arduino boards are published under a Creative Commons license, so experienced
circuit designers can make their own version of the module, extending it and improving it)

Mr.Raviteja Balekai, Asst.Professor, Dept of


6
ECE, GMIT, Davangere
Types of Arduino Boards
LEONARDO
ETHERNET
UNO
YUN

MEGA LILYPAD

ESPLORA DUE

Mr.Raviteja Balekai, Asst.Professor, Dept of


7
ECE, GMIT, Davangere
Getting Started with Arduino UNO
Arduino Software (IDE)
• The Arduino Integrated Development
Environment - or Arduino Software (IDE)
- contains a text editor for writing code, a
message area, a text console, a toolbar
with buttons for common functions and a
series of menus. It connects to the
Arduino and Genuino hardware to upload
programs and communicate with them.
• Programs written using Arduino Software
(IDE) are called sketches. These sketches
are written in the text editor and are
saved with the file extension .ino.

Mr.Raviteja Balekai, Asst.Professor, Dept of


9
ECE, GMIT, Davangere
Writing and Downloading Code

Mr.Raviteja Balekai, Asst.Professor, Dept of


10
ECE, GMIT, Davangere
Running Code While
Tethered

Running Code
Stand-Alone

Mr.Raviteja Balekai, Asst.Professor, Dept of


11
ECE, GMIT, Davangere
ARDUINO IDE

Mr.Raviteja Balekai, Asst.Professor, Dept of


12
ECE, GMIT, Davangere
Select Serial Port and Board

Mr.Raviteja Balekai, Asst.Professor, Dept of


13
ECE, GMIT, Davangere
What can it do?
• Sensors ( to sense stuff )
– Push buttons, Touch pads, Tilt switches.
– Variable resistors (eg. Volume knob / Sliders)
– Photoresistors (Sensing light levels)
– Thermistors (Temperature)
– Ultrasound (Proximity range finder)
– Moisture Sensor (Measure Dryness / Wetness)
• Actuators ( to do stuff )
– Lights, LED’s
– Motors
– Speakers
– Displays (LCD)

Mr.Raviteja Balekai, Asst.Professor, Dept of


14
ECE, GMIT, Davangere
Overview of

the Embedded C
Programming Language

Mr.Raviteja Balekai, Asst.Professor, Dept of


15
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of
16
ECE, GMIT, Davangere
Few Instructions

Mr.Raviteja Balekai, Asst.Professor, Dept of


17
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of
18
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of
19
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of 20
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of 21
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of 22
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of 23
ECE, GMIT, Davangere
TINKERCAD

• Tinkercad is a free, easy-to-use app for 3D


design, electronics, and coding. It's used by
teachers, hobbyists, and designers to imagine,
design, and make anything!

Mr.Raviteja Balekai, Asst.Professor, Dept of


24
ECE, GMIT, Davangere
TINKERCAD
• Create an account at https://www.tinkercad.com/

Mr.Raviteja Balekai, Asst.Professor, Dept of


25
ECE, GMIT, Davangere
TINKERCAD

Mr.Raviteja Balekai, Asst.Professor, Dept of


26
ECE, GMIT, Davangere
ARDUINO interfacing with

• ACTUATORS
• SENSORS

Mr.Raviteja Balekai, Asst.Professor, Dept of 27


ECE, GMIT, Davangere
LED

• A Light-Emitting Diode
(LED) is a two lead
semiconductor device that
emits visible light when an
electric current passes
through it.
• An basic LED has two
terminals
– Anode (+)
– Cathode (-)

Mr.Raviteja Balekai, Asst.Professor, Dept of


28
ECE, GMIT, Davangere
LCD

Mr.Raviteja Balekai, Asst.Professor, Dept of


29
ECE, GMIT, Davangere
LCD PINOUTS

Mr.Raviteja Balekai, Asst.Professor, Dept of


30
ECE, GMIT, Davangere
ULTRASONIC SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


31
ECE, GMIT, Davangere
ULTRASONIC SENSOR
The modules includes ultrasonic transmitters, receiver and control circuit.
The basic principle of work:
(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz pulse signal and detect
whether there is a pulse signal back.
(3) IF the signal back, through high level , time of high output IO duration
is the time from sending ultrasonic to returning.
Test distance = (high level time × velocity of sound (340M/S) / 2

Mr.Raviteja Balekai, Asst.Professor, Dept of


32
ECE, GMIT, Davangere
PASSIVE INFRARED (PIR) SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


33
ECE, GMIT, Davangere
PASSIVE INFRARED (PIR) SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


34
ECE, GMIT, Davangere
LIGHT DEPENDENT RESISTOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


35
ECE, GMIT, Davangere
LIGHT DEPENDENT RESISTOR
The LDR is a special type of resistor which allows higher voltages to
pass through it (low resistance=5KΩ) whenever there is a high intensity
of light, and passes a low voltage (high resistance= 20MΩ) whenever it
is dark.
• Digital Applications
• Night light control, Automatic headlight dimmer
Absence/Presence (Beam breaker)
• Analog Applications
• Camera exposure control

Mr.Raviteja Balekai, Asst.Professor, Dept of


36
ECE, GMIT, Davangere
TEMPERATURE SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


37
ECE, GMIT, Davangere
TEMPERATURE SENSOR
Features
• Operate on low voltage
• ±2°C Temperature accuracy
• External Calibration not required
• Specified −40°C to +125°C, operation to +150°C
• Less than 50 µA quiescent current
• Auto Shutdown current 0.5 µA max

Technical Specification
• Supply Voltage: 2.7 V to 5.5 V
• Supply Current up to 50uA
• Ramp-Up Rate 3°C/sec
• Ramp-Down Rate −6°C/sec
• Offset Voltage: 0.5V
• Output voltage at 25°C: 750mV
• Device turning ON time: 0.5ms
• Operating Temperature Range: −55°C to +150°C
• Storage Temperature Range: −65°C to +160°C
Mr.Raviteja Balekai, Asst.Professor, Dept of
38
ECE, GMIT, Davangere
GAS SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


39
ECE, GMIT, Davangere
SERVO MOTOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


40
ECE, GMIT, Davangere
SERVO MOTOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


41
ECE, GMIT, Davangere
Hex Keypad

APPLICATIONS
• Industrial automation systems
• Authentication and security

Mr.Raviteja Balekai, Asst.Professor, Dept of


42
ECE, GMIT, Davangere
SOIL MOISTURE SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


43
ECE, GMIT, Davangere
SOIL MOISTURE SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


44
ECE, GMIT, Davangere
SOIL MOISTURE SENSOR

Mr.Raviteja Balekai, Asst.Professor, Dept of


45
ECE, GMIT, Davangere
Examples

• Home Automation System


• Smart Agriculture System
• Air Pollution Monitoring System (Smart Gas
Leakage Detector Bot)
• Streetlight Monitoring System
• Garbage monitoring system
• Health monitoring system

Mr.Raviteja Balekai, Asst.Professor, Dept of


46
ECE, GMIT, Davangere
Mr.Raviteja Balekai, Asst.Professor, Dept of
47
ECE, GMIT, Davangere
Faculty Development Programme (FDP)
on
Internet of Things Lab

Ability enhancement course – “Internet of Things Lab”


for 5th sem ECE/ETE students as per VTU syllabus under 2021
scheme.
Presentation by,
Mr. Raviteja Balekai,
Assistant Professor, Department of ECE,
GMIT, Davangere

Mr. Raghudathesh G P,
Assistant Professor-Senior Scale,
Manipal School of Information Sciences, Manipal

Dr. Prathviraj N,
Associate Professor,
Manipal School of Information Sciences, Manipal
EXPERIMENT – 1

i. To interface LED/Buzzer with Arduino/Raspberry Pi and


write a program to turn ON LED for 1 sec after every 2
seconds.
LED

• A Light-Emitting Diode (LED) is a two


lead semiconductor device that emits
visible light when an electric current
passes through it.
• An basic LED has two terminals
– Anode (+)
– Cathode (-)
Buzzer

• A buzzer or beeper is an audio


signaling device, which may be
mechanical, electromechanical, or
piezoelectric. Typical uses of
buzzers and beepers include
alarm devices, timers, and
confirmation of user input such as
a mouse click or keystroke
Fig. LED interfacing with Arduino
Fig. Buzzer interfacing with Arduino
EXPERIMENT – 1

ii. To interface Push button/Digital sensor (IR/LDR) with


Arduino UNO and write a program to turn ON LED when
push button is pressed or at sensor detection.
Push Button

• A push button switch is a


mechanical device used to control
an electrical circuit in which the
operator manually presses a
button to actuate an internal
switching mechanism. They come
in a variety of shapes, sizes, and
configurations, depending on the
design requirements.
Fig. Push button interfacing with Arduino
LDR

• The LDR is a special type of


resistor which allows higher
voltages to pass through it
(low resistance=5KΩ) whenever
there is a high intensity of light,
and passes a low voltage (high
resistance= 20MΩ) whenever it
is dark.
Fig. LDR interfacing with Arduino
IR Sensor
Fig. IR sensor interfacing with Arduino
EXPERIMENT – 2

i. To interface DHT11 sensor with Arduino/Raspberry Pi and


write a program to print temperature and humidity
readings.
DHT Sensor
DHT Sensor specifications
DHT11 DHT22

• Ultra low cost • Low cost


• 3 to 5V power and I/O • 3 to 5V power and I/O
• 2.5 mA max current • 2.5 mA max current
• Good for 20-80% humidity • Good for 0-100% humidity
readings with 5% accuracy readings with 2-5% accuracy
• Good for 0-50°C • Good for -40 to 125°C
temperature readings ±2°C temperature readings ±0.5°C
accuracy accuracy
DHT Sensor
Example 1: 40 bits of data is received:
0011 0101 0000 0000 0001 1000 0000 0000 0100 1101
High humidity (8) , Low humidity (8), High temp. (8), Low temp.(8), Parity bit (8)
Calculate:
0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101
Received data is correct:
Humidity:0011 0101=35H=23%RH
Temperature:0001 1000=18H=24℃

Example 2: 40 bits of data is received:


0011 0101 0000 0000 0001 1000 0000 0000 0100 1001
High humidity (8) , Low humidity (8), High temp. (8), Low temp.(8), Parity bit (8)
Calculate:
0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101
01001101≠0100 1001
The received data is not correct, give up, to re-receive data.
Installing DHT library

• Click on sketch  Include Library  Add Zip Library


• Navigate to the Zip named DHT-sensor-library-master.zip and
click Ok
Fig. DHT sensor interfacing with Arduino
EXPERIMENT – 2

ii. To interface OLED/I2C LCD with Arduino/Raspberry Pi


and write a program to print temperature and humidity
readings on it
OLED
Installing OLED library
• 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.
Fig. DHT sensor and OLED interfacing with Arduino
Fig. Displaying Temperature and Humidity values on I2C OLED using Arduino UNO
I2C LCD
LCD PINOUT
Installing I2C Library
• Click on sketch  Include Library  Add Zip Library
• Navigate to the Zip named Arduino-LiquidCrystal-
I2C-library-master.zip and click Ok
Fig. I2C LCD and DHT 11 interfacing with Arduino UNO
Fig. Displaying Temperature and Humidity values on I2C LCD using Arduino UNO
EXPERIMENT – 3

To interface motor using relay with Arduino and write a


program to turn ON motor when push button is pressed
Step 1 :

Fig. Push button interfacing with Arduino

Step 2 :

Fig. Interfacing motor with relay using Arduino


NODEMCU
• NodeMCU is an open source IoT platform.
• It includes firmware which runs on the ESP8266
Wi-Fi SoC from Espressif Systems, and hardware
which is based on the ESP-12 module.
• The firmware uses the Lua scripting language.
ESP-XX Modules
NODE MCU ESP8266 12E Module
SPECIFICATIONS

• 802.11 b/g/n
• Integrated low power 32-bit MCU (Xtensa@ Single- Core)
• Typical frequency of 80MHz
• SRAM- 160 Kbytes
• SPI Flash, up to 16 MBytes
• Integrated 10-bit ADC
• Integrated TCP/IP protocol stack
• SDIO (Secure Digital Input Output) 2.0, (H) SPI, UART, I2C, I2S (Inter IC Sound),
IRDA(Infrared Data Association), PWM, GPIO
• Supports antenna diversity
• Integrated PLL, regulators, and power management unit
• Wi-Fi 2.4 GHz, support WPA(Wi-Fi Protected Access)/WPA2
• Support STA( Station) /AP ( Access point) /STA+AP operation modes
• Operating temperature range -40C ~ 125C
PIN DIAGRAM
How to Use Arduino IDE to
Program NodeMCU
1. Start Arduino IDE and open Preferences window from File
2. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into
Additional Board Manager URLs field
3. Open Boards Manager from Tools > Board menu and find esp8266 platform
ESP32
• ESP32 is a low-cost System on Chip (SoC)
Microcontroller from Espressif Systems, the
developers of the famous ESP8266 SoC. It is a
successor to ESP8266 SoC and comes in both single-
core and dual-core variations of the Tensilica’s 32-bit
Xtensa LX6 Microprocessor with integrated Wi-Fi and
Bluetooth.
Specifications of ESP32
• Single or Dual-Core 32-bit LX6 Microprocessor with clock frequency up to
240 MHz.
• 520 KB of SRAM, 448 KB of ROM and 16 KB of RTC SRAM.
• Supports 802.11 b/g/n Wi-Fi connectivity with speeds up to 150 Mbps.
• Support for both Classic Bluetooth v4.2 and BLE specifications.
• 34 Programmable GPIOs.
• Up to 18 channels of 12-bit SAR ADC and 2 channels of 8-bit DAC
• Serial Connectivity include 4 x SPI, 2 x I2C, 2 x I2S, 3 x UART.
• Ethernet MAC for physical LAN Communication (requires external PHY).
• 1 Host controller for SD/SDIO/MMC and 1 Slave controller for SDIO/SPI.
• Motor PWM and up to 16-channels of LED PWM.
• Secure Boot and Flash Encryption.
• Cryptographic Hardware Acceleration for AES, Hash (SHA-2), RSA, ECC and
RNG.
ESP32 Module
How to Use Arduino IDE to
Program ESP32
1. Start Arduino IDE and open Preferences window from File
2. Enter https://raw.githubusercontent.com/espressif/arduino-esp32/gh-
pages/package_esp32_index.json into Additional Board Manager URLs field
3. Open Boards Manager from Tools > Board >Board Manager Search for ESP32 and
press install button for the “ESP32 by Espressif Systems“
EXPERIMENT – 4

To interface Bluetooth with Arduino and write a program to


turn LED ON/OFF when '1'/'0' is received from smartphone
using Bluetooth
Fig. Interfacing LED with ESP32
• Download Serial Bluetooth Terminal application on your
mobile.

• 'Serial Bluetooth Terminal' is a line-


oriented terminal / console app for
microcontrollers, arduinos and other devices
with a serial / UART interface connected
with a bluetooth to serial converter to your
android device.

• This app supports different bluetooth


versions:
- Bluetooth Classic
- Bluetooth Low Energy / Bluetooth Smart
Fig. Connecting smartphone to ESP32 using Fig. Controlling LED Turn ON (1)/ OFF (0) through
Bluetooth smartphone
EXPERIMENT – 5

To interface Bluetooth with Arduino and write a program to


send sensor data to smartphone using Bluetooth
Fig. Interfacing DHT11 with ESP32
Fig. Receiving Temperature data on bluetooth terminal of smart phone
EXPERIMENT – 6

Write a program on Arduino to upload temperature and


humidity data to Thingspeak cloud
• When building IoT (Internet of Things) applications,
the cloud part where all information from sensors is
stored are important.

• There are many cloud services that can collect IoT


data, but the fundamental issue here is that the
Internet of Things does not have a standard set of
open APIs for consumers.

• Thingspeak is one such IoT service that lets user to


access cloud for storing or processing their data.
ThingSpeak
• The Internet of Things (IoT) provides access to a broad
range of embedded devices and web services.

• ThingSpeak is an IoT platform that enables you to


collect, store, analyze, visualize, and act on data from
sensors or actuators, such as Arduino®, Raspberry Pi™,
BeagleBone Black, and other hardware.

• ThingSpeak acts as the IoT platform for data collection


and analytics that serves as a bridge connecting edge
node devices such as temperature and pressure
sensors to collect data and data exploratory/historical
analysis software to analyze data.
Contd…

ThingSpeak
• With ThingSpeak you can create sensor-logging
applications, location-tracking applications, and a
social network of things with status updates, so that
you could have your home thermostat control itself
based on your current location.
IoT End – End Architecture
ThingSpeak Features

• All-purpose Data Storage and Retrieval

 Tweet-sized data
 Push data from devices
 Use data in apps
 Data Types:
 Sensor Data
 Text Data
 Geolocation Data

• Data Visualization

– Charts
– Maps
Contd…

ThingSpeak Features
• Data Processing

– Min / Max Filtering


– Time scaling
– Summing
– Averaging
– Median

• Twitter Integration

– Send Tweets
– Use data collected by Twitter
– Twitter callbacks
Channel Creation

• Go to the weblink: https://thingspeak.com/


• Click signup button
• Create mathwork account
• Check your E-mail to verify
the account.
• Click the Green button I agree
• You are redirected to thingspeak
Website in your account a new channel button as
Channel setting
Go to API KEY Window

Use this API Key in your Arduino Code for Sensor data update to Cloud
Private/Public View
Installing ThingSpeak Library

• Click on sketch  Include Library  Add Zip


Library
• Navigate to the Zip named thingspeak-
arduino-master.zip and click Ok
Fig. Interfacing DHT11 with ESP32
Fig. Displaying temperature and humidity data on ThingSpeak cloud
EXPERIMENT – 7

Write a program on Arduino/Raspberry Pi to retrieve


temperature and humidity data from Thingspeak cloud
Fig. Interfacing DHT11 with ESP32
Fig. Displaying temperature and humidity data on serial monitor of Arduino IDE from
Thingspeak cloud
EXPERIMENT – 8

Write a program on Arduino/Raspberry Pi to publish


temperature data to MQTT broker
Fig. Interfacing DHT11 with ESP32
Installing Adafruit MQTT Library
• Click on sketch  Include Library  Add Zip Library
• Navigate to the Zip named Adafruit_MQTT_Library-master.zip
and click Ok
Adafruit IO Cloud Service
• Create an account at https://io.adafruit.com/
Creating a Dashboard

2
Designing Your Dashboard
• Click on “+” Symbol.

• Select Gauge option


Configuring Toggle Option
• Check the feed you have
just created and click next
step.

• Enter the Block particulars.


• Now your block has been
just created.
Getting AIO Key Credentials
1. Click on Key Icon.
2. Copy both username and Active key to respective
fields in Arduino Sketch.
3. Now you have Configured your Adafruit Dashboard.
4. Do create one more toggle button named “sensor-2”
in the same dashboard.
MQTT – IoT Protocol
• MQTT - Message Queue Telemetry Transport.
• It is a publish‐subscribe‐based lightweight messaging protocol for use in conju
nction with the TCP/IP protocol.
• MQTT was introduced by IBM in 1999 and standardized by OASIS in 2013.
• MQTT is suited for M2M, WSN and ultimately IoT scenarios where sensor and
actor nodes communicate with applications through the MQTT message
broker.
• A message broker controls the publish‐subscribe messaging pattern.
• A topic to which a client is subscribed is updated in the form of messages and
distributed by the message broker.
• Designed for:
– Remote connections
– Limited bandwidth
– Small‐code footprint
• Scenario: sensor continuously sends/publishes sensed data to the broker.
Interested users can subscribe to these data via broker using common topic
name.
A Typical MQTT Scenario
A Applications of MQTT
• MQTT excels in scenarios where reliable message delivery is crucial
for an application but a reliable network connection is not
necessarily available, e.g. mobile networks.
• Typical applications of MQTT include:
– Telemetry
– Automotive
– Smart Home
– Energy Monitoring
– Chat Applications
– Notification Services
– Healthcare Application
Fig. Displaying temperature and humidity data on Adafruit IO platform
Fig. Displaying temperature and humidity data on serial monitor of Arduino IDE
EXPERIMENT – 9

Write a program on Arduino/Raspberry Pi to subscribe to MQTT


broker for temperature data and print it
Fig. Interfacing DHT11 with ESP32 (Publisher) Fig. ESP32 (Subscriber)
Fig. Receiving the temperature data on serial monitor of Arduino IDE
EXPERIMENT – 10

Write a program to create UDP server on Arduino/Raspberry Pi


and respond with humidity data to UDP client when requested
Fig. Interfacing DHT11 with NodeMCU
• Download Packet sender application on your
system- https://packetsender.com/
• Packet Sender is an open source utility to allow
sending and receiving TCP and UDP packets. It
also supports TCP connections using SSL,
intense traffic generation, HTTP(S) GET/POST
requests, and panel generation. It is available
for Windows, Mac, and Linux. It is licensed GNU
General Public License v2 and is free software.
Fig. Receiving humidity on UDP client based on request to UDP server NodeMCU (ESP8266)
EXPERIMENT – 11

Write a program to create TCP server on Arduino/Raspberry Pi and


respond with humidity data to TCP client when requested
Fig. Interfacing DHT11 with NodeMCU
Fig. Receiving humidity on TCP client based on request to TCP server NodeMCU (ESP8266)
Introduction To Raspberry Pi

By:
Raghudathesh G P
Asst. Professor
MSOIS, MAHE, MANIPAL
Why
Raspberry PI ?
Introduction
• A credit card size single board, low cost computer.
• Developed in UK by Raspberry-pi foundation in May 2009. Supported by
“University of Cambridge Computer laboratory & tech firm Broadcom”
• Designed to promote the teaching of basic computer science schools in developing
countries, but increasingly use by researchers to build real time applications, DIY
enthusiasts to build cool projects, companies to build POC’s as well as products.
• Add to its popularity, now a days Raspberry Pi’s are used for the purpose of mining
cryptocurrency by infecting a linux trojan named Linux.MulDrop.14
• According to the Raspberry Pi Foundation, over 37 million* Raspberry Pi’s have
been sold till date, making it the best-selling British computer.
• The Raspberry Pi uses Linux kernel based operating systems. Raspbian, a Debian-
based free operating system optimized for the Raspberry Pi hardware.
*https://www.raspberrypi.org/blog/raspberry-pi-silicon-pico-now-on-sale/
Raspberry Pi v/s Other Single
Board Computer
Raspberry Pi Applications
Features
• Ultra Low Cost Device $35 or Rs 2275
• Ultra Low-power 1.1W
• Credit-card sized, fanless, instant start-up.
• Complete easy-to-use program computer
• Easy and fun environment for experimenting with programming and electronics.
Technology
• Raspberry Pi 3 has a Broadcom BCM2837 system on a chip (SoC), which includes an
ARMCortex-A53, 1.2GHz processor.
• Video Core (GPU): Broadcom VideoCore
• Originally Shipped with 256 Mb of RAM, now Upgraded to 1 GB.
• Does not have a built-in hard disk, but uses an SD card for booting and storage.
• Video outputs: Composite RCA, HDMI, DSI
• Audio outputs : 3.5 mm jack, HDMI, I²S audio
• Onboard network:10/100 Ethernet only on Model-B
• Onboard storage: SD card slot
• Low-level peripherals: 40 × GPIO, UART, I²C bus, SPI bus with two chip selects, I²S audio,
+3.3 V, +5 V, ground
• Power ratings: via MicroUSB
– 5v, 1.5-2.5 amp (3.5 W) for Model-B
Know Your Raspberry Pi Board
Know Your Raspberry Pi Board
Know Your Raspberry Pi Board
Basic Hardware Setups required to work with Your RPi Board

1. Raspberry Pi Board
2. Display
3. Audio
4. Keyboard and Mouse
5. Flashed SD Card
6. Power Supply
7. Cables
Display
Options for Connecting Display device
a. HDMI(High Definition Multimedia Interface)
video
b. Composite video (RCA)
c. DSI(Display Serial Interface) video
Audio
Options for Connecting Audio device
a. In-built (with HDMI)
b. a black 3.5 mm audio jack (for DVI-D monitors
and composite video RCA output)
Keyboard and Mouse
➢ For Connecting Keyboard & mouse you can use USB Hub
➢ Any standard USB keyboard and mouse should work.
Flashed SD Card
➢ A Bootable SD Card with Ported Linux OS.
➢ The minimum sized SD card you can use is 16GB, but it is recommended to use at
least 8GB if you want to add additional programs to the OS image .
Power Supply
The Model B requires a 5 V supply capable of providing a 1.5 – 2.5 A current, depending
upon the hardware connected top it
Cables
More or less you will be needing…
• HDMI-A cable
• HDMI-A cable + DVI adapter
• Composite video cable
• Composite video cable + SCART adaptor
• Audio cable (not needed if you use the HDMI video connection to a TV)
• Ethernet/LAN cable
• Connecting wires if required to connect peripherals in the GPIO pins
Raspberry Pi OS Setup
• Hardware Requirements:
– Card Reader
– Micro SD (minimum of 4 Gb) Card Class 10
• Software Requirements:
– Raspberry PI OS Image: download from below link and unzip it
https://www.raspberrypi.org/downloads/raspbian/
– Unzip the file that you just downloaded
– Right click on the file and choose “Extract all”.
– Follow the instructions you will end up with a file ending in .img
Continue …
– Download SD Formatter to format your Card
https://www.sdcard.org/downloads/formatter_4/index.html/
– Install the SD Formatter tool as you install normal software on windows machine.
– Select SD card Volume Label
– Click on option and select format
adjustment option to ON
Continue …
– Download the Win32DiskImager software
– https://win32-disk-imager.en.uptodown.com/windows/
– Unzip it in the same way you did the Raspbian .zip file
– You now have a new folder called
win32diskimager-binary
▪ Writing Raspbian to the SD card
▪ Plug your SD card into your PC
▪ Run the file named Win32DiskImager.exe from the folder you made earlier
• If the SD card (Device) you are using isn’t found automatically then click on the
drop down box and select it
• In the Image File box, choose the Raspbian .img file that you downloaded
▪ Click Write
▪ After a few minutes you will have an SD card that you can use in your Raspberry Pi
RPI Connection Setup

RPI First Boot
You will see the desktop home window like this
First Boot Configuration
Continue …
• First, update your system's package list by entering the following
command in LXTerminal or from the command line:
sudo apt-get update
• Next, upgrade all your installed packages to their latest versions with
the command:
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get raspi-upgrade (doute ful)

• Generally speaking, doing this regularly will keep your installation up


to date, in that it will be equivalent to the latest released image
available from raspberrypi.org/downloads.
Linux File System Layout
• boot: This contains Linux kernel and other packages needed to start the Pi
• bin: OS-related binary files, like those required to run the GUI, are stored here.
• dev: Virtual directory, which doesn’t actually exist on the SD card. All devices connected to
the system can be accessed from here.
• etc: This stores miscellaneous configuration files, including the list of users and their
encrypted passwords
• home: Each user gets a subdirectory beneath this directory to store all their personal files
• lib: This is a storage space for libraries, which are shared bits of code required by different
applications.
• lost+found: A special directory where file fragments are stored if the system crashes.
• media: A special directory for removable storage devices, like USB memory sticks or
external CD drives.
Continued ..
• mnt: This folder is used to manually mount storage devices, such as external hard
drives.
• opt: This stores optional software that is not part of the OS itself. If you install new
software to your Pi, it will usually go here.
• proc: Another virtual directory, containing information about running programs which
are known in Linux as processes.
• selinux: Files related to Security Enhanced Linux, a suite of security utilites originally
developed by the US National Security Agency.
• sbin: Stores special binary files, primarily used by the root account for system
maintenance.
• sys: This directory is where special OS files are stored.
• tmp: Temporary files are stored here automatically.
• usr: This directory provides storage for user accessible programs.
• var: This is virtual directory that programs use to store changing values or variables.
Linux Basic Commands
•pwd - print working directory, will show you the full path to the directory you are
currently in
•man - Help manual
•ls - Short listing of directory contents
•cd - change directories, type cd followed by the name of a directory to access
directory. E.g, cd ..
•mv - Move or rename files or directories, type mv followed by the current name of
a directory and the new name of the directory. E.g, mv testdir newnamedir
•cp – Copy files, type cp followed by src_dirctory trgt_directory
•rmdir – Remove an existing directory, type rmdir followed by directory_name
•rm – remove a file, type rm followed by file_name
•cat - Sends file contents to standard output
•Ifconfig – Shows the IP Address of the board
•mkdir – make directories
•poweroff – shutdown the system
Continues …
RPI General Purpose Input/Output (GPIO)
• General Purpose Input/Output (GPIO) is a generic pin on a chip whose
behavior can be controlled by the user at run time.
• The GPIO connector has a number of different types of connection:
– True GPIO (General Purpose Input Output) pins that you can use to turn
LEDs on and off etc.
– I2C (Inter Integrated Circuit) interface pins that allow you to connect
hardware modules with just two control pins
– SPI(Serial Peripheral interface) with SPI devices, a similar concept to I2C
but uses a different standard
– Serial Rx and Tx pins for communication with serial peripherals
Continues …
• GPIO pins can be used as both digital outputs and digital inputs.
• Output: turn a particular pin HIGH or LOW.
– Setting it HIGH sets it to 3.3V; setting it LOW sets it to 0V.
• Input: detect the pin being at HIGH or LOW
– we can connect switches and simple sensors to a pin and
check whether it is open or closed (that is, activated or not)
• Caution: All the pins have 3.3V logic levels and are not
5V-safe so the output levels are 0 - 3.3V and the inputs
should not be higher than 3.3V.
• There are (at least) two, different numbering schemes you may encounter
when referencing Pi pin
- Broadcom chip-specific pin numbers and
- P1 physical pin numbers
- Wiring Pi
• You’re usually free to use either number-system, but many programs require
that you declare which scheme you’re using at the very beginning of your
program
RPI3 GPIO PIN LAYOUT
GPIO setup on Raspberry Pi
• Install Python 2 library Rpi.GPIO.
– A library that will let us control the GPIO pins.
https://pypi.python.org/pypi/RPi.GPIO
• Install commands:
- sudo apt-get update
- sudo apt-get install python-dev
- sudo apt-get install python-rpi.gpio
Continues …
• Setup Stuff: In order to us RPi.GPIO throughout the rest of your Python script, you need to put this statement at the top
of your file:
language:Python
import RPi.GPIO as GPIO
• That statement “includes” the RPi.GPIO module, and goes a step further by providing a local name –GPIO – which we’ll
call to reference the module from here on.
• Pin Numbering Declaration: After you’ve included the RPi.GPIO module, the next step is to determine which o
the two pin - numbering schemes you want to use:
GPIO.BOARD – Board numbering scheme. The pin numbers follow the pin numbers on header P1.
• GPIO.BCM – Broadcom chip-specific pin numbers. These pin numbers follow the lower-level numbering system
defined by the Raspberry Pi’s Broadcom-chip brain.
• To specify in your code which number-system is being used, use the GPIO.setmode() function. For example...
language:Python
GPIO.setmode(GPIO.BCM)
• ...will activate the BROADCOM-CHIP SPECIFIC pin numbers.
GPIO.setmode(GPIO.BOARD)
• ...will activate the PHYSICAL BOARD specific pin numbers.
• Both the import and setmode lines of code are required, if you want to use Python.
Time to Hook Up Your
Sensors & Actuators
MQTT – IoT Protocol

Mr. Raghudathesh G. P. Mr. Raviteja Balekai


Asst. Professor Asst. Professor
Manipal School of Information Sciences Dept. of E&CE
MAHE, Manipal GM Institute of Technology, Davangere
Introduction
• MQTT - Message Queue Telemetry Transport.
• It is a publish‐subscribe‐based lightweight messaging protocol for use in conj
unction with the TCP/IP protocol.
• MQTT was introduced by IBM in 1999 and standardized by OASIS in 2013.
• MQTT is suited for M2M, WSN and ultimately IoT scenarios where sensor and
actor nodes communicate with applications through the MQTT message
broker.
• A message broker controls the publish‐subscribe messaging pattern.
• A topic
to which a client is subscribed is updated in the form of messages and distrib
uted by the message broker.
• Designed for:
– Remote connections
– Limited bandwidth
– Small‐code footprint
• Scenario: sensor continuously sends/publishes sensed data to the broker.
Interested users can subscribe to these data via broker using common topic
name.
Applications of MQTT

• MQTT excels in scenarios where reliable message


delivery is crucial for an application but a reliable
network connection is not necessarily available, e.g.
mobile networks.
• Typical applications of MQTT include:
– Telemetry
– Automotive
– Smart Home
– Energy Monitoring
– Chat Applications
– Notification Services
– Healthcare Application
A Typical MQTT Scenario
Components of MQTT
1. Publishers:
– Clients which subscribe to topics to publish the
messages.
– Example: Lightweight sensors.
2. Subscribers:
– Clients which subscribe to topics to receive the
messages.
– Example: Applications interested in sensor data,
actuators.
3. Broker:
– Servers run topics, i.e. receive subscriptions from
publishers on topics, receive messages from publishers
and forward these, based on subscribers subscriptions,
to interested clients.
MQTT Methods

• MQTT has 14 different message types.


• Typically, end users only need to employ the
CONNECT, PUBLISH, SUBSCRIBE, UNSUBSCRIBE
and DISCONNECT message types.
• The other message types are used for internal
mechanisms and message flows.
Communication
• The protocol uses a publish/subscribe
architecture (HTTP uses a request/response paradigm).
• Publish/subscribe is event‐driven
and enables messages to be pushed to clients.
• The central communication point is the MQTT broker, which is in charge of
dispatching all messages between the senders and the rightful receivers.
• Each client that publishes a message to the broker, includes a topic into th
e message. The topic is the routing information for the broker.
• Each client that wants to receive messages subscribes to a certain topic an
d the broker delivers all messages with the matching topic to the client.
• Therefore the clients don’t have to know each other. They only communic
ate over the topic.
• This architecture enables highly scalable solutions without dependencies b
etween the data producers and the data consumers.
Applications

• Facebook Messenger uses MQTT for online chat.


• Amazon Web Services use Amazon IoT with MQTT.
• Microsoft Azure IoTHub uses MQTT as its main protocol
for telemetry messages.
• The EVRYTHNG IoTplatform uses MQTT as an M2M prot
ocol for millions of connected products.
• Adafruit launched a free MQTT cloud service for IoT
experimenters called Adafruit IO.
MQTT Raspberry PI
Hands On
Connection Diagram

DHT 11 to RPI
1 → VCC (pin 1)
2 → GPIO 4
3 → No Connection
4 → GND (pin 6)

LED to RPI
+ve → GPIO 21
-ve → GND
RPI - LED
INTERFACING
LED PINOUTS
RPI - LED
LED
+ Ve → GPIO 17
Cathode → PIN 6
Code RPI - LED
RPI – DHT11
INTERFACING
DHT11 PINOUTS
Specification
DHT11 DHT22
• Ultra low cost • Low cost
• 3 to 5V power and I/O • 3 to 5V power and I/O
• 2.5 mA max current • 2.5 mA max current
• Good for 20-80% humidity • Good for 0-100% humidity
readings with 5% accuracy readings with 2-5% accuracy
• Good for 0-50°C temperature • Good for -40 to 125°C
readings ±2°C accuracy temperature readings ±0.5°C
accuracy
Received Data:
Example 1: 40 bits of data is received:
0011 0101 0000 0000 0001 1000 0000 0000 0100 1101
High humidity (8) , Low humidity (8), High temp. (8), Low temp.(8), Parity bit (8)
Calculate:
0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101
Received data is correct:
Humidity:0011 0101=35H=23%RH
Temperature:0001 1000=18H=24℃

Example 2: 40 bits of data is received:


0011 0101 0000 0000 0001 1000 0000 0000 0100 1001
High humidity (8) , Low humidity (8), High temp. (8), Low temp.(8), Parity bit (8)
Calculate:
0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101
01001101≠0100 1001
The received data is not correct, give up, to re-receive data.
Installing Library
• To start with update your package lists and
install a few Python libraries :
• Sudo apt-get update
• Sudo apt-get install build-essential python-dev
• Clone the Adafruit library from their repository :
• git clone
https://github.com/adafruit/Adafruit_Python_DHT.git
• cd Adafruit_Python_DHT
• Install the library for Python 2 and Python 3
• sudo python setup.py install
• sudo python3 setup.py install
Temperature & Humidity Values on
Terminal
DHT 11 to RPI

1 → VCC (pin 2)

2 → GPIO 4
3 → No Connection
4 → GND (pin 6)
CODE

• 1_dht11_Terminal_Display-1
• 1_dht11_Terminal_Display-2
Configurations on MQTT.Cool
• Go to following URL– “https://testclient-
cloud.mqtt.cool/”
• Select a Broker: tcp://test.mosquito.org/
• Cilck on connect.
Configuring MQTT.Cool

• For Subscribe:
– Write Topic filter as “jitdvg“ with QoS0
– Click Subscribe
• For Publish:
– Write destination as “jitdvg“
– Write message to be sent
– Click Publish
Configurations on Android Phone
• In Playstore download and install My MQTT
Procedure to Create MQTT Instance
• Configure as per the image below
Configuring MY MQTT
– To SUBSCRIBE
• Enter topic name as “jitdvg”
• Cilck on subscribe
– To PUBLISH
• Enter topic name as “jitdvg”
• Enter the message to be sent.
• Click on ‘Create’
Thank You ☺
Database
By,
Dr. Prathiviraj N , MSIS, MAHE, Manipal
Prof. Raghudathesh G P, MSIS, MAHE, Manipal
Databases

• A program that
– Manages possibly huge quantities of data
– Facilitates fast and easy access
– Makes data integrity guarantees
– Has A LOT under the covers

ACID - http://en.wikipedia.org/wiki/ACID
Databases (cont.)
• Applications
– Amazon.com, Facebook, IMDB, digg.com, banks,
Google, etc
• Implementations
– MySQL, Postgre, Oracle, Microsoft SQL Server
MySQL (MariaDb)
• MySQL is a popular open-source relational
database management system.
• It allows users to perform various operations on
data, including Create, Read, Update, and Delete
(CRUD).
• CRUD operations are essential to managing and
manipulating data in any database system.
Database Organization
• A single database has multiple tables
• A table has multiple rows
• Each row has multiple columns
• Each column represents a different data
category

Table of actors:
Database Structure
• Column types
– INT, VARCHAR (String), DOUBLE…
• Schemas
– What tables exist?
– What types of columns are in each table?
Database Operations (CRUD)
• Create data in a table
– A new actor has just appeared in a film

• Read data from a table


– Somebody has searched for an Customer

• Update data in a table


– An actor has appeared in a new movie

• Delete data in a table


– A planned movie is cancelled
Structured Query Language
(SQL)
• The language that one uses to interface with a
database
• Allows a user to perform CRUD operations on
a particular database
Thing to Do
– Install Database tool: mariadb
$sudo apt-get install mariadb-server mariadb-client
– Install Connector bw Python and mariadb:
$ sudo pip install mysqlclient
– Adding a User to Db in root:
• $sudo mysql
• >CREATE USER ‘jitdvg’@localhost IDENTIFIED BY ‘jitdvg’;
– Creating a database:
• Create database employess;
– Creating a user setting permissions
• mysql> GRANT ALL PRIVILEGES ON employess.* TO
‘jitdvg'@'localhost’ IDENTIFIED BY ‘jitdvg’;
– Creating a table
Create (INSERT)
Insert a row into the actors table containing id=5, name=“Nicole Kidman”,
DOB=“06/20/1967” gender=“F”

INSERT INTO actors


VALUES (‘5’, ‘Nicole Kidman’, ‘06/20/1967’, ‘F’);

Note that the order of values depends on the way the table was created
Read (SELECT)
Get all rows and only the id column from the “actors” table
SELECT id
FROM actors;

Get all rows and columns from the “actors” table


SELECT *
FROM actors;

Get all rows and columns from the “actors” table whose name field is “Tom Cruise.”
SELECT *
FROM actors
WHERE name = ‘Tom Cruise’;

Get all rows and columns from the “actors” table whose name field is either “Tom Cruise” or
“Katie Holmes.”
SELECT *
FROM actors
WHERE name = ‘Tom Cruise’
OR name = ‘Katie Holmes’;
Update (UPDATE)
Change Tom Cruise’s gender
UPDATE actors
SET gender = ‘F’
WHERE name = ‘Tom Cruise’;

Change Tom Cruise’s gender if he is a man


UPDATE actors
SET gender = ‘F’
WHERE name = ‘Tom Cruise’
AND gender = ‘M’;
Delete (DELETE)
Delete Tom Cruise from the table

DELETE FROM actors


WHERE name = ‘Tom Cruise’;
ACID
• Atomicity
– All or none
• Consistency
– Always in a legal state
• Isolation
– Each user is isolated from each other user
• Durability
– Can recover after a crash or power failure
Useful Links
• IMDB Database:
– http://www.imdb.com/interfaces
– Download the plain text interface and import it
into MySQL (see Google)
• Sun’s Data Access Object Pattern
– http://java.sun.com/blueprints/corej2eepatterns/
Patterns/DataAccessObject.html
Thank You ☺

You might also like