Ocs352 Iot Concepts and Applications Laboratory Manual
Ocs352 Iot Concepts and Applications Laboratory Manual
DEPARTMENT
OF
ELECTRICAL AND ELECTRONICS ENGINEERING
LABORATORY MANUAL
REGISTER NUMBER
YEAR
SEMESTER
Prepared By
SENTHILKUMAR K
AP/EEE
THE KAVERY ENGINEERING COLLEGE
OCS352 IOT CONCEPTS AND APPLICATIONS LT
PC
2 0
23
OBJECTIVES:
• To apprise students with basic knowledge of IoT that paves a platform to
understand physical and logical design of IOT
• To teach a student how to analyse requirements of various communication
models and protocols for cost-effective design of IoT applications on different IoT
platforms.
• To introduce the technologies behind Internet of Things(IoT).
• To explain the students how to code for an IoT application using
Arduino/Raspberry Pi open platform.
• To apply the concept of Internet of Things in real world scenario.
OUTCOMES:
CO 1:Explain the concept of IoT.
CO 2:Understand the communication models and various protocols for IoT.
CO 3:Design portable IoT using Arduino/Raspberry Pi /open platform
CO 4:Apply data analytics and use cloud offerings related to IoT.
CO 5:Analyze applications of IoT in real time scenario.
TOTAL PERIODS:60
TEXTBOOKS
1. Robert Barton, Patrick Grossetete, David Hanes, Jerome Henry, Gonzalo
Salgueiro, “IoT Fundamentals: Networking Technologies, Protocols, and Use Cases for the
Internet of Things”, CISCO Press, 2017
2. Samuel Greengard, The Internet of Things, The MIT Press, 2015
REFERENCES
1. Perry Lea, “Internet of things for architects”, Packt, 2018
2. Olivier Hersent, David Boswarthick, Omar Elloumi , “The Internet of
Things – Key applications and Protocols”, Wiley, 2012
3. IOT (Internet of Things) Programming: A Simple and Fast Way of
Learning, IOT KindleEdition.
4. Dieter Uckelmann, Mark Harrison, Michahelles, Florian (Eds), “Architecting the
Internet ofThings”, Springer, 2011.
5. ArshdeepBahga, Vijay Madisetti, “Internet of Things – A hands-on
approach”, Universities Press, 2015
6. https://www.arduino.cc/
https://www.ibm.com/smarterplanet/us/en/?ca=v_smarterplan
et
SUBJECT CODE: OCS352
List of experiments
AIM:
To write and execute Embedded Language Program for Addition, Subtraction,
Multiplication, Modulation and Division of two 8-Bit numbers using Keil uVision5.
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 Keil uVision5 Software 1
ALGORITHM:
1. Start the program.
2. Call x51 header file
3. Declare Variables
3. Load 1st value in A
4. Load 2nd value in B
5. Add A and B values and result store in the Addition variable
6. Subtract A and B values and result store in the Subtraction variable
7. Multiply A and B values and result store in the Multiplication variable
8. Divide A and B values and resultant Quotient store in the Division variable
9. Modulation A and B values and resultant Reminder store in the Modulation
variable
10. Stop the program.
PROGRAM
PROGRAM COMMENT
START
Variable Declaration
STOP
PROCEDURE:
Addition :
Subtraction :
Multiplication :
Division :
Modulation:
AIM:
To write and execute Embedded Language Program for Addition, Subtraction,
Multiplication, Modulation and Division of two 8-Bit numbers using Keil uVision5.
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 Keil uVision5 Software 1
ALGORITHM:
1. Start the program.
2. Call x51 header file
3. Declare Variables
3. Load 1st value in A
4. Load 2nd value in B
5. Perform AND Logic A and B values and result store in the variable
6. Perform OR Logic A and B values and result store in the variable
7. Perform XOR Logic A and B values and result store in the variable
8. Perform NOT Logic A value and result store in the variable
9. Perform Increment Logic A value and result store in the variable
10. Perform Decrement Logic A value and result store in the variable
11. Stop the program.
PROGRAM
PROGRAM COMMENT
START
Variable Declaration
STOP
PROCEDURE:
AND:
OR:
XOR :
NOT:
INCREMENT:
DECREMENT:
AIM:
To interface the 1X4 LED array with Arduino using Arduino IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Arduino Nano unit 1
LED Array unit
3 Jumper Wires As Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Define GPIO Pins
3. Define GPIO Pin Mode
4. if Infinite loop True:
ON LED_1
Delay 1 Second
ON LED_2
Delay 1 Second
ON LED_3
Delay 1 Second
ON LED_4
Delay 1 Second
OFF LED_1
OFF LED_2
OFF LED_3
OFF LED_4
Delay 1 Second
5. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT ARDUINO
1 VCC 5V POWER +
2 GND GND POWER -
3 LED_1 (L1) D2 OUTPUT
4 LED_2 (L2) D3 OUTPUT
5 LED_3 (L3) D4 OUTPUT
6 LED_4 (L4) D5 OUTPUT
BLOCK DIAGRAM
ARDUINO
POWER SUPPLY LED ARRAY
NANO
FLOW CHART
START
NO
if Infinite
STOP
Loop True
YES
CIRCUIT DIAGRAM
PROCEDURE:
AIM:
To interface the I2C LCD with Arduino using Arduino IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Arduino Nano Unit 1
I2C LCD Unit
3 Jumper Wires AS Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Call I2C LCD Library
3. Initiate LCD
4. if Infinite loop True:
Set LCD Cursor (0,0) Position 0 and Column 1
Print HELLO WORLD
Set LCD Cursor (0,1) Position 0 and Column 2
Print *****
Delay 2 Second
Clear LCD
Delay 2 Second
5. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT ARDUINO
1 VCC 5V POWER +
2 GND GND POWER -
3 LCD (SDA) A4 Serial Data
4 LCD (SCL) A5 Serial Clock
BLOCK DIAGRAM
ARDUINO
POWER SUPPLY I2C LCD
NANO
FLOW CHART
START
Initialize LCD
NO
if Infinite
STOP
Loop True
YES
Print on LCD as
HELLO WORLD
*****
Delay 2 Second
Clear LCD
Delay 2 Second
CIRCUIT DIAGRAM
PROCEDURE:
1. Open ARDUINO IDE Software
2. Click File >> New or CTRL+N to create New Project.
3. To Select Board Click Tools >> Board > Arduino AVR Boards >> Arduino
Nano
4. To select Processor Click Tools >> Processor >> ATmega328P (Old
Bootloader)
5. To select Programmer Click Tools >> Programmer >> AVRISP mkII
6. Click File >> Save or CTRL+S to Save Project where we Desire.
7. Type the Program.
8. Click Sketch >> Verify / Compile or CTRL+R to compile the program (If any
error present debug the program)
9. Connect the Arduino Nano with PC / Laptop by USB Cable
10. Select the COM PORT by Click Tools >> Port and Select Arduino's COM PORT
Number.
Note : If COM PORT Number is Don't Know:
Right Click My Computer Icon and Select Properties
Click Device Manager
Expand Ports (COM & LPT). COM PORT Number will be shown
11. Click Sketch >> Upload or CTRL+U to upload the program to Arduino Nano.
12. Switch On the corresponding Units we need and Verify the Program.
Interface and program Bluetooth Communication with Arduino using
Arduino Platform
AIM:
To interface the Bluetooth with Arduino using Arduino IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Arduino Nano Unit 1
HC-05 Bluetooth Unit
3 Jumper Wires As Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Variable declaration
3. Initialize Bluetooth
4. Send Welcome Message
5. if Infinite loop True:
if Bluetooth Data Available
Receive Data And Send Again to Bluetooth Module
6. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT ARDUINO
1 VCC 5V POWER +
2 GND GND POWER -
3 HC-05_TX RX DATA RECIEVE
4 HC-05_RX TX DATA TRANSMIT
BLOCK DIAGRAM
ARDUINO
POWER SUPPLY HC-05
NANO
BLUETOOTH
FLOW CHART
START
Initialize Bluetooth
NO
if Infinite
STOP
Loop True
YES
NO
While Bluetooth
Data Available
YES
Receive Data
NO
if Full Data Reset
Received Variable
YES
PROCEDURE:
AIM:
To interface the Zigbee with Arduino using Arduino IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Arduino Nano Unit 1
Zigbee Unit
3 Jumper Wires As Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Variable declaration
3. Initialize Zigbee
4. Send Welcome Message
5. if Infinite loop True:
if Zigbee Data Available
Receive Data And Send Again to Zigbee Module
6. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT ARDUINO
1 VCC 5V POWER +
2 GND GND POWER -
3 Zigbee_TX RX DATA RECIEVE
4 Zigbee_RX TX DATA TRANSMIT
BLOCK DIAGRAM
ARDUINO
POWER SUPPLY ZIGBEE
NANO
FLOW CHART
START
Initialize Zigbee
NO
if Infinite
STOP
Loop True
YES
NO
While Zigbee
Data Available
YES
Receive Data
NO
if Full Data Reset
Received Variable
YES
PROCEDURE:
AIM:
To interface the GSM with Arduino and Send SMS using Arduino IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Arduino Nano Unit 1
GSM Unit
3 Jumper Wires As Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Variable declaration
3. Wait 20 Seconds
4. Initialize GSM
5. Check SIM Signal Strength
6. Configure GSM as Text Mode
7.Define SMS Receive Mobile Number
8. Define SMS Message Content
9. Send SMS
10.Stop Program
PROGRAM
PROGRAM COMMENT
delay(3000);
} Set up Loop Close
void loop() Infinite Loop Start
{
delay(1000); Delay 1 Second
} Infinite Loop Close
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT ARDUINO
1 VCC 5V POWER +
2 GND GND POWER -
3 GSM_TX RX DATA RECIEVE
4 GSM_RX TX DATA TRANSMIT
BLOCK DIAGRAM
ARDUINO
POWER SUPPLY GSM
NANO
FLOW CHART
START
Wait 20 Second
Initialize GSM
Send SMS
STOP
CIRCUIT DIAGRAM
PROCEDURE:
AIM:
To interface the 1X4 LED array with Raspberry Pi using Thoony Python IDE
REQUIRED ITEMS
PC / LAPTOP
1 SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi unit 1
LED Array unit
3 Jumper Wires As Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Define GPIO Pins
3. Define GPIO Pin Mode
4. if Infinite loop True:
ON LED_1
Delay 1 Second
ON LED_2
Delay 1 Second
ON LED_3
Delay 1 Second
ON LED_4
Delay 1 Second
OFF LED_1
OFF LED_2
OFF LED_3
OFF LED_4
Delay 1 Second
5. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT RASPBERRY PI
1 VCC 5V POWER +
2 GND GND POWER -
3 LED_1 (L1) GPIO 18 OUTPUT
4 LED_2 (L2) GPIO 23 OUTPUT
5 LED_3 (L3) GPIO 24 OUTPUT
6 LED_4 (L4) GPIO 25 OUTPUT
BLOCK DIAGRAM
RASPBERRY PI
POWER SUPPLY LED ARRAY
FLOW CHART
START
NO
if Infinite
STOP
Loop True
YES
CIRCUIT DIAGRAM
TERMINAL COMMAND LINE
PROCEDURE:
AIM:
To interface the I2C LCD with Raspberry Pi using Thoony Python IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi Unit 1
I2C LCD Unit
3 Jumper Wires AS Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Call I2C LCD Library
3. Initiate LCD
4. if Infinite loop True:
Set LCD Cursor (0,0) Position 0 and Column 1
Print HELLO WORLD
Set LCD Cursor (0,1) Position 0 and Column 2
Print *****
Delay 2 Second
Clear LCD
Delay 2 Second
5. else
Stop Program
PROGRAM
PROGRAM COMMENT
import lcddriver Import LCD Library
from time import * Import Delay Library
lcd = lcddriver.lcd() Initialize LCD
try: Test a block of code for errors
while True: Infinite Loop Start
lcd.lcd_display_string(" HELLO Print HELLO WORLD on LCD 1st Line
WORLD", 1)
lcd.lcd_display_string(" ********", 2) Print ******** on LCD 2nd Line
time.sleep(2) Delay 2 Second
lcd.lcd_clear() Clear LCD
time.sleep(2) Delay 2 Second
except: Block lets you handle the error
GPIO.cleanup() Reset GPIO Pins
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT RASPBERRY PI
1 VCC 5V POWER +
2 GND GND POWER -
3 LCD (SDA) GPIO 2 Serial Data
4 LCD (SCL) GPIO 3 Serial Clock
BLOCK DIAGRAM
RASPBERRY PI
POWER SUPPLY I2C LCD
FLOW CHART
START
Initialize LCD
NO
if Infinite
STOP
Loop True
YES
Print on LCD as
HELLO WORLD
*****
Delay 2 Second
Clear LCD
Delay 2 Second
CIRCUIT DIAGRAM
PROCEDURE:
AIM:
To interface the DHT11 Sensor and I2C LCD with Raspberry Pi using Thoony
Python IDE
REQUIRED ITEMS
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi Unit
1
I2C LCD Unit
DHT 11 Sensor Unit
3 Jumper Wires AS Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Call I2C LCD Library and DHT11 Sensor Library
3. Define GPIO Pins
4. Variable Declaration
5. Initiate LCD
6. if Infinite loop True:
Read Temperature and Humidity Value
Clear LCD
Set LCD Cursor (0,0) Position 0 and Column 1
Print TEMP: VALUE
Set LCD Cursor (0,1) Position 0 and Column 2
Print HUMI: VALUE
Delay 3 Second
5. else
Stop Program
PROGRAM
PROGRAM COMMENT
CONNECTION
S.NO PIN MODE
COMPONENT RASPBERRY PI
1 VCC 5V POWER +
2 GND GND POWER -
3 LCD (SDA) SPIO 02 Serial Data
4 LCD (SCL) GPIO 03 Serial Clock
5 DHT11 GPIO 25 Digital Input
BLOCK DIAGRAM
RASPBERRY PI
POWER SUPPLY I2C LCD
DHT11 SENSOR
FLOW CHART
START
Define GPIO Pin Mode and Initialize LCD & DHT Sensor
NO
if Infinite
STOP
Loop True
YES
Clear LCD
Print on LCD as
TEMP: XX.XX
HUMI: XX.XX
Delay 3 Second
CIRCUIT DIAGRAM
PROCEDURE:
AIM:
To : Interface and Communication between Raspberry pi and Arduino Nano Using
I2C Protocol
REQUIRED ITEMS
S.NO ITEM QTY
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi Unit
1
Arduino Nano Unit
LED Array Unit
3 Jumper Wires As Required
4 USB Cable 1
RASPBERRY PI ALGORITHM:
1. Start the program
2. Define I2C Bus and Address
3. if Infinite loop True:
Read Data from Interpreter Pane
if Data ==1
Send 0x1 to Arduino
else if Data==0
Send 0x0 to Arduino
4. else
Stop Program
ARDUINO ALGORITHM:
1. Start the program
2. Define I2C Bus and Address
3. if Infinite loop True:
Read Data from I2C port
if Data ==1
LED ON
if Data==0
LED OFF
6. else
Stop Program
RASPBERRY PI PROGRAM
PROGRAM COMMENT
from smbus import SMBus Import I2C Bus
addr = 0x8 Define Address For Bus
bus = SMBus(1) Initialize I2C Bus
print ("Enter 1 for ON or 0 for OFF") Print ON/OFF Instruction on
Console
while numb == 1: Infinite Loop Starts
ledstate = input(">>>> ") Read Console Data
if ledstate == "1": Check ON State
bus.write_byte(addr, 0x1) Send 1 to Arduino
elif ledstate == "0": Check OFF State
bus.write_byte(addr, 0x0) Send 0 to Arduino
else: Wait For Data
ARDUINO PROGRAM
PROGRAM COMMENT
#include <Wire.h> Call 1 Wire Library
const int ledPin = 2; LED connected with D2
void setup() { Set up Loop Start
Wire.begin(0x8); Define I2C Address
Wire.onReceive(receiveEvent); Define I2C Interrupt Function
pinMode(ledPin, OUTPUT); LED Configures as OUTPUT
digitalWrite(ledPin, LOW); LED OFF
} Set up Loop Close
void receiveEvent(int howMany) { I2C Interrupt Function Calling
while (Wire.available()) { Check I2C Data
char c = Wire.read(); Read I2C Data and Stored in Variable
digitalWrite(ledPin, c); Toggle LED as per I2C Data
} I2C Interrupt Function Close
}
void loop() { Infinite Loop
delay(100);
}
LED ARRAY
START
NO
if Infinite
STOP
Loop True
YES
YES
Send 0x1 to
if Data==1
Arduino Via
I2C Bus
YES
Send 0x1 to
if Data==2
Arduino Via
I2C Bus
ARDUINO FLOW CHART
START
NO
if Infinite
STOP
Loop True
YES
YES
if Data==1
LED1 ON
YES
if Data==2
LED1 OFF
CIRCUIT DIAGRAM
PROCEDURE:
1. Open ARDUINO IDE Software
2. Click File >> New or CTRL+N to create New Project.
3. To Select Board Click Tools >> Board > Arduino AVR Boards >> Arduino
Nano
4. To select Processor Click Tools >> Processor >> ATmega328P (Old
Bootloader)
5. To select Programmer Click Tools >> Programmer >> AVRISP mkII
6. Click File >> Save or CTRL+S to Save Project where we Desire.
7. Type the Program.
8. Click Sketch >> Verify / Compile or CTRL+R to compile the program (If any
error present debug the program)
9. Connect the Arduino Nano with PC / Laptop by USB Cable
10. Select the COM PORT by Click Tools >> Port and Select Arduino's COM PORT
Number.
Note : If COM PORT Number is Don't Know:
Right Click My Computer Icon and Select Properties
Click Device Manager
Expand Ports (COM & LPT). COM PORT Number will be shown
11. Click Sketch >> Upload or CTRL+U to upload the program to Arduino Nano.
12. Switch On the corresponding Units we need and Verify the Program.
Create New Project And Setup A Firebase Cloud Platform To Log The Data
.
Setup a cloud platform to log the data
AIM:
To Create New Project and Setup Firebase Real-time Database.
REQUIRED ITEMS
S.NO ITEM QTY
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
Hard disk : 256 GB or above 1
RAM : 2 GB or above
Keyboard and Mouse
With High Speed Internet Facility
STEP_1:
First, Visit Firebase Console Using This Visiting The Following URL -
https://console.firebase.google.com.
SPEP_2:
Login Using Your Google Account - If You Are Not Already Logged In.
STEP_3:
STEP_5:
Click Continue
STEP_7:
STEP_9:
Firebase Console Home Page Opened and Click Build And Select Real Time
Database
STEP_10:
STEP_11:
STEP_13:
Now Real Time Database Is Created With Host URL.Click Rules And Change
Write And Read Rules As true And Click Publish
STEP_14:
Copy These Line Saved In Notepad File For Future IOT Project Deployment
Firebase Configuration Data's Are Created. Click Continue to Console
Design and Implementation of IOT Based Weather Station and Log
Humidity Sensor Data using Raspberry PI and upload to the cloud
platform
AIM:
To Design and Implement IOT Based Weather Station using Raspberry Pi.
REQUIRED ITEMS
S.NO ITEM QTY
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi Unit
1
I2C LCD Unit
DHT11Sensor Unit
3 Jumper Wires AS Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Call GPIO, DHT11, FIREBASE And I2C LCD Library
3. Initialize LCD, DHT11 And FIREBASE
4. Variable Declaration
5. Define GPIO Pins And Its Mode
6. if Infinite loop True:
Read Temperature And Humidity Value
Clear LCD
Print TEMP: VALUE
Print HUMI: VALUE
Update Temperature And Humidity Value on IoT Firebase Database
if Temperature >=40
Print CLIMATE
Print SUNNY
Update Climate Status on IoT Firebase Database
else if humidity >=80
Print CLIMATE
Print RAINY
Update Climate Status on IoT Firebase Database
else
Print CLIMATE
Print NORMAL
Update Climate Status on IoT Firebase Database
7. else
Stop Program
PROGRAM
PROGRAM COMMENT
import lcddriver Import LCD Library
from time import * Import Delay Library
lcd = lcddriver.lcd() Initialize LCD
import RPi.GPIO as GPIO import GPIO library
import pyrebase Import Firebase Library
from time import sleep Import Delay Library
import time Import Time Library
import Adafruit_DHT Import DHT Library
import time Import Time Library
DHT_SENSOR = Adafruit_DHT.DHT11 Define DHT Model as DHT11
DHT_PIN = 25 DHT11 Data Pin Connected With GPIO 25
config = { configure firebase database Variables
"apiKey":
"wgsNjBl7qvzVY0KiezCBplSlRxLI9OiPwEsc
hMfh",
"authDomain": "rasptest-
2fdb7.firebaseapp.com",
"databaseURL": "https://rasptest-2fdb7-
default-rtdb.firebaseio.com/",
"storageBucket": "rasptest123"
}
firebase = pyrebase.initialize_app(config) Initialize Firebase
GPIO.setmode(GPIO.BCM) Define as Physical numbering
GPIO.setwarnings(False) Warning Off for GPIO pins
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" IoT Based ", 1) Print IoT Based on LCD 1st Line
lcd.lcd_display_string("Weather Station" , 2) Print Weather Station on LCD 2nd Line
time.sleep(2) Delay 2 Second
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" System", 1) Print System on LCD 1st Line
lcd.lcd_display_string(" *******" , 2) Print ******** on LCD 2nd Line
time.sleep(2) Delay 2 Second
try: Test a block of code for errors
while True: Infinite Loop Start
database = firebase.database() Read Firebase Database
ProjectBucket = database.child("IOTLAB") Define Firebase Data Storage Bucket
LEDDATA = Read Firebase Data
ProjectBucket.child("LED").get().val()
humidity, temperature = Read Temperature And Humidity Value
Adafruit_DHT.read(DHT_SENSOR,
DHT_PIN)
if humidity is not None and temperature is not Validate the Read Values
None:
print("Temp={0:0.1f}C Print Temperature and Humidity Values on
Humidity={1:0.1f}%".format(temperature,
Console
humidity))
ProjectBucket.child("IOTLAB").child("Humid Update Humidity Value on IoT Firebase
ity").set(humidity) Database
ProjectBucket.child("IOTLAB").child("Tempe Update Temperature Value on IoT Firebase
rature").set(temperature) Database
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string("Temp: %d%s C" % Print Temperature Value on LCD's 1st Line
(temperature, chr(223)), 1)
lcd.lcd_display_string("Humidity: %d %%" % Print Humidity Value on LCD's 2nd Line
humidity, 2)
else: Non _ Validated Values
print("DATA READING...."); Reading Again
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string("DATA Print DATA READING... on LCD's 1st
READING...",1)
Line
lcd.lcd_display_string(" ****" , 2) Print **** on LCD's 2nd Line
time.sleep(2) Delay 2 Second
if temperature >=40: Check SUNNY Loop
print("SUNNY") Print SUNNY on Console
ProjectBucket.child("IOTLAB").child("Climat Update CLIMATE as SUNNY on IoT
e").set("Sunny")
Firebase Database
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" CLIMATE",1) Print CLIMATE. on LCD's 1st Line
lcd.lcd_display_string(" SUNNY" , 2) Print SUNNY on LCD's 2nd Line
elif humidity>=80: Check RAINY Loop
print("RAINY") Print RAINY on Console
ProjectBucket.child("IOTLAB").child("Climat Update CLIMATE as RAINY on IoT
e").set("Rainy")
Firebase Database
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" CLIMATE",1) Print CLIMATE. on LCD's 1st Line
lcd.lcd_display_string(" RAINY" , 2) Print RAINY on LCD's 2nd Line
else: Check NORMAL Loop
print("NORMAL") Print NORMAL on Console
ProjectBucket.child("IOTLAB").child("Climat Update CLIMATE as NORMAL on IoT
e").set("Normal")
Firebase Database
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" CLIMATE",1) Print CLIMATE. on LCD's 1st Line
lcd.lcd_display_string(" NORMAL" , 2) Print NORMAL on LCD's 2nd Line
time.sleep(2) Delay 2 Second
except KeyboardInterrupt: Program Is Interrupted By The User
Keyboard
GPIO.cleanup() Reset GPIO Pins
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT RASPBERRY PI
1 VCC 5V POWER +
2 GND GND POWER -
3 LCD (SDA) GPIO 2 Serial Data
4 LCD (SCL) GPIO 3 Serial Clock
5 DHT11 GPIO 25 Digital Input
BLOCK DIAGRAM
RASPBERRY PI
POWER SUPPLY I2C LCD
DHT11 SENSOR
FLOW CHART
START
NO
if Infinite STOP
Loop True
YES
YES
Print LCD Update IoT
if TEMP>=40
CLIMATE CLIMATE
SUNNY SUNNY
NO
YES
else if Print LCD Update IoT
CLIMATE CLIMATE
HUMI>=80
RAINY RAINY
NO
Print LCD Update IoT
CLIMATE CLIMATE
SUNNY SUNNY
CIRCUIT DIAGRAM
PROCEDURE:
AIM:
To Design and Implement IOT Based Home Automation using Raspberry Pi.
REQUIRED ITEMS
S.NO ITEM QTY
1 PC / LAPTOP
SYSTEM SPECIFICATION:
OS : windows 7 or above
1
Hard disk : 256 GB or above
RAM : 2 GB or above
Keyboard and Mouse
2 CS3691 IOT TRAINER KIT
Raspberry Pi Unit 1
Relay Unit
3 Jumper Wires AS Required
4 USB Cable 1
ALGORITHM:
1. Start the program
2. Call GPIO, FIREBASE And I2C LCD Library
3. Initialize LCD, And FIREBASE
4. Variable Declaration
5. Define GPIO Pins And Its Mode
6. if Infinite loop True:
Read Firebase Data
if LED1Data =1
Relay_1 ON
else
Realy_1 OFF
if LED2Data =1
Relay_2 ON
else
Realy_2 OFF
Clear LCD
Print Relay_1: Status
Print Relay_2: Status
Update Relay_1 & Realay_2 Status on IoT Firebase Database
7. else
Stop Program
PROGRAM
PROGRAM COMMENT
import lcddriver Import LCD Library
from time import * Import Delay Library
lcd = lcddriver.lcd() Initialize LCD
import RPi.GPIO as GPIO import GPIO library
import pyrebase Import Firebase Library
from time import sleep Import Delay Library
import time Import Time Library
config = { configure firebase database
Variables
"apiKey":
"wgsNjBl7qvzVY0KiezCBplSlRxLI9OiPwEschMfh",
"authDomain": "rasptest-2fdb7.firebaseapp.com",
"databaseURL": "https://rasptest-2fdb7-default-
rtdb.firebaseio.com/",
"storageBucket": "rasptest123"
}
firebase = pyrebase.initialize_app(config) Initialize Firebase
LED_1 = 18 LED_1 connect with GPIO 18
LED_2 = 23 LED_2 connect with GPIO 23
GPIO.setmode(GPIO.BCM) Define as Physical numbering
GPIO.setwarnings(False) Warning Off for GPIO pins
GPIO.setup(LED_1,GPIO.OUT) Configure LED_1 as Output
GPIO.setup(LED_2,GPIO.OUT) Configure LED_2 as Output
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" IoT Based ", 1) Print IoT Based on LCD 1st Line
lcd.lcd_display_string("Home Automation" , 2) Print Home Automation on LCD
2nd Line
time.sleep(2) Delay 2 Second
lcd.lcd_clear() Clear LCD
lcd.lcd_display_string(" System", 1) Print System on LCD 1st Line
lcd.lcd_display_string(" *******" , 2) Print ******** on LCD 2nd Line
time.sleep(2) Delay 2 Second
try: Test a block of code for errors
while True: Infinite Loop Start
database = firebase.database() Read Firebase Database
ProjectBucket = database.child("IOTLAB") Define Firebase Data Storage
Bucket
LEDDATA1 = ProjectBucket.child("LED1").get().val() Read LED_1 Data
ProjectBucket = database.child("IOTLAB") Define Firebase Data Storage
Bucket
LEDDATA2 = ProjectBucket.child("LED2").get().val() Read LED_2 Data
lcd.lcd_clear() Clear LCD
if str(LEDDATA1) == "1": Check LED_1 ON Loop
print("LED_1 now is ON.") Print LED_1 now is ON on
Console
GPIO.output(LED_1, GPIO.HIGH) LED_1 ON
ProjectBucket.child("IOTLAB").child("L1").set("ON") Update LED1 Status on IoT as ON
lcd.lcd_display_string("LED_1 : ON", 1) Print LED-1: ON on LCD 1st
Line
else: Check LED_1 OFF Loop
print("LED_1 now is OFF.") Print LED_1 now is OFF on
Console
GPIO.output(LED_1, GPIO.LOW) LED_1 OFF
ProjectBucket.child("IOTLAB").child("L1").set("OFF") Update LED1 Status on IoT as
OFF
lcd.lcd_display_string("LED_1 : OFF", 1) Print LED-1: OFF on LCD 2nd
Line
if str(LEDDATA2) == "1": Check LED_2 ON Loop
print("LED_2 now is ON.") Print LED_2 now is ON on
Console
GPIO.output(LED_2, GPIO.HIGH) LED_2 ON
CONNECTION TABLE
CONNECTION
S.NO PIN MODE
COMPONENT RASPBERRY PI
1 VCC 5V POWER +
2 GND GND POWER -
3 Relay_1 (R1) GPIO 18 OUTPUT
4 Relay_2 (R2) GPIO 23 OUTPUT
5 LCD (SDA) GPIO 2 Serial Data
6 LCD (SCL) GPIO 3 Serial Clock
BLOCK DIAGRAM
I2C LCD
WIFI
FLOW CHART
START
NO
if Infinite
STOP
Loop True
YES
NO YES
if LED1
Relay_1 OFF Relay_1 ON
DATA==1
NO YES
if LED2
Relay_2 OFF Relay_2 ON
DATA==1
PROCEDURE: