You are on page 1of 25

Raspberry Pi based Interactive

Home Automation System through E-mail

BY
V BHARATH KUMAR REDDY
13E11D5502
M.TECH 2nd YEAR
Embedded System

Aim of the Project


Send an Email From any where to
Raspberry pi Registered Mail Id
After Receiving An Email.
It Should Control The Switching
Between Lights As well as
Acknowledgement has to send to
email which we have provided in
source code

Abstract
Home automation is becoming more
and more popular day by day due to
its numerous advantages. This can
be achieved by local networking or
by remote control or through email.
This Project aims at designing a
basic home automation application
on Raspberry Pi through reading the
subject of E-mail

Raspberry Pi Introduction
Raspberry Pi is a credit-card-sized single
board computer developed in the UK.
Model A has 256Mb RAM, one USB port and no
network connection.
Model B+ has 512Mb RAM, 4 USB ports and an
Ethernet port and HDMI port
It has a Broadcom BCM2835 system on a chip
which includes an ARM1176JZF -S 700 MHz
processor, Video Core IV GPU, and an SD card.

Raspberry pi diagram:

Block Diagram
Laptop/PC

Raspberry Pi

WIFI
Hotspot

BUL
B

Rela
y

BUL
B

Rela
y

BUL
B

Rela
y

Arduino

Layout of the Proposed system


configuration

Hardware & software:


HARDWARE REQUIRED:
Wifi-Hotspot
Raspberry Pi
Relays
Leds
Bulbs(Optional)
Arduino Board
SOFWARE LANGUAGES USED:
Python
Linux Shell Script
SQL

Flow Chart
Turn on Raspberry pi (home
automation activated)

Email
received?

Read subject of the mail

Subject =
OFF 1?

Subject
=ON1?

OFF light 2

Subject =
OFF 2?

Subject
=ON2?

ON light 2

OFF light 3

Subject =
OFF 3?

Subject
=ON3?

ON light 3

OFF light 1

Subject =
ALL OFF?

Subject =
ALL ON?

ON light 1

Software Configuration:
By using Python language on Linux
platform have to write the code. to be
saved in one file. Which in turn should
save in Raspberry file System.
By using this script we can connect to
Web by importing related packages
and conditions to be defined according
the Requirement.

Source Code
#!/usr/bin/env python
import feedparser
import smtplib
from email.mime.text import MIMEText
import serial as io
ser=io.Serial('/dev/ttyUSB0',9600)
import RPi.GPIO as GPIO ## Import GPIO
library
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
USERNAME =
"raspberry.embeddedrf@gmail.com"
PASSWORD = "raspberry123"
MAILTO =
"reddybharath637@gmail.com"
check=1
check2=1
check3=1

while 1:
response = feedparser.parse("https://" + USERNAME
+ ":" + PASSWORD +
"@mail.google.com/gmail/feed/atom")
unread_count = int(response["feed"]["fullcount"])
for i in range(0,unread_count):
#print "Unread Mail "+str(i)
a= response['items'][0].title
b= response['items'][0].summary
c=response['items'][0].author

if a.startswith("ALL ON"):
if(checkall==1):
GPIO.output(7,True)
GPIO.output(11,True)
GPIO.output(13,True)
msg = MIMEText(' ')
msg['Subject'] = 'Turning ON all lights'
msg['From'] = USERNAME
msg['To'] = MAILTO
server =
smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO,
msg.as_string())
server.quit()
print "Turning ON all lights"
ser.write("7");
checkall=0

if a.startswith("ALL OFF"):
if(checkall==0):
GPIO.output(7,True)
GPIO.output(11,True)
GPIO.output(13,True)
msg = MIMEText(' ')
msg['Subject'] = 'Turning OFF all lights'
msg['From'] = USERNAME
msg['To'] = MAILTO
server =
smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO,
msg.as_string())
server.quit()
print "Turning OFF all lights"
ser.write("8");
checkall=1

if a.startswith("ON1"):
if(check==1):
GPIO.output(7,True)
msg = MIMEText(' ')
msg['Subject'] = 'Turning ON1'
msg['From'] = USERNAME
msg['To'] = MAILTO
server =
smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO,
msg.as_string())
server.quit()
print "Light 1 is on"
ser.write("1");
check=0

if a.startswith("ON2"):
if(check2==1):
GPIO.output(11,True)
msg = MIMEText(' ')
msg['Subject'] = 'Turning ON2'
msg['From'] = USERNAME
msg['To'] = MAILTO
server =
smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO,
msg.as_string())
server.quit()
print "Light 2 is on"
ser.write("3");
check2=0

if a.startswith("OFF2"):
if(check2==0):
GPIO.output(11,False)
msg = MIMEText(' ')
msg['Subject'] = 'Turning OFF2'
msg['From'] = USERNAME
msg['To'] = MAILTO
server =
smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO,
msg.as_string())
server.quit()
print "Light 2 is OFF"
ser.write("4");
check2=1

Arduino Code:
Void setup()
{
Serial.begin(9600);
Pinmode(8,output);
Pinmode(9,output);
}
Void loop()
{
If(serial.available())
{
a=serial.read()
If (a=1)
{
digital.write(8,HIGH);
}
If(a=2)
{
Digital.write(8,low):
}
}
}
etc . Will keep passing some
digit which will in turn controls the swithing

Procedure to Run The Code:


1. Login into Raspberry pi by Using Username
and Password
2. Go to the Path cd /dev to find the peripheral
devices connected to raspberry pi(optional)
3.Then go to the path where source code file is
saved
4.Run the code as root user
For Ex:
Sudo python code.py
Note: sudo command is used to run file as root
user
Python is used to execute the file

Result Check:
1. Login Into Any mail Id
2. Send the mail to
Raspberry.embeddedrf@gmail.com by
mentioning subject of email Like
ON1,OFF1,ON2,OFF2
3. We can check the status of Lights in the Kit
4. And also we can get Acknowledgement to
the mail which we have provided in the
source code.
5. This can be verified by login into provided
mail where we can get the
Acknowledgement Like: LIGHT ONE IS
OFF,LIGHT ONE IS ON .etc.

Working experimental
setup

Results

Acknowledgement

Advantages:

1.Home Automation results Conven


2.Energy efficiency
3.Improved quality of life
4.Safe and secure.
5.Centralized control

Thank You

You might also like