Smart Doorbell using RPi with voice and email notification.

Part of my project involves having a doorbell, I figured a simple doorbell whereby a visitor just presses a button and then it rings/ notify whoever is it the house, That’s not really creative in my point of view.

So I then decided why not have a doorbell that not only rings when the button is pressed but also tell you someone is at the door and then sends you an email notification just in case you might be away(Not able to hear the bell.) as well as log the time that the button was pressed.

IDEA: It would be really cool if I had a USB Webcam that would take a picture of the person visiting and emails it.

first things first, we’ll need to create the wav file ie TextToSpeech. Using this simple tool below.

pico2wave -w DoorNotify.wav "Someone is ringing the doorbell. Please Go Check"

Next, create a python script that will watch the state of GPIO pin 18 on the RPi and take some action when the doorbell brings it to ‘HIGH’.

#!/usr/bin/env python2.7
__author__ = "Mpho Mphego"
__version__ = "$Revision: 1.1 $"
__description__ = "Smart Doorbell Notifier with voice and email notification : Interrupt driven"
__date__ = "$Date: 2015/01/11 02:23 $"
__copyright__ = "Copyright (c) 2015 Mpho Mphego"
__url__ = ""
__license__ = "Python"

import RPi.GPIO as GPIO
import time
import os

# Connect to Relay which will control the 12V Buzzer.
led = 17 #GPIO0
button = 18 #GPIO1

GPIO.setup(led, GPIO.OUT)
GPIO.output(led, False)

# GPIO 1 set up as inputs, pulled up to avoid false detection.
# Both ports are wired to connect to GND on button press.
# So we'll be setting up falling edge detection for both
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# define callback functions
# this will run when an event are detected
def buttonHandler(channel):
    print "falling edge detected on 18"
    GPIO.output(led, True)
    GPIO.output(led, False)
    os.system("aplay /home/pi/Scripts/Smart_DoorBell/DoorNotify.wav")			
    os.system("python /home/pi/Scripts/Smart_DoorBell/")
    GPIO.output(led, True)
    GPIO.output(led, False)

# when a falling edge is detected on port 1, regardless of whatever 
# else is happening in the program, the function buttonHandler will be run
GPIO.add_event_detect(button, GPIO.FALLING, callback=buttonHandler, bouncetime=5000)

    print "Waiting for button to be pressed"
    while True:
        # To ease the CPU Usage have a 10s delay on while loop.
    GPIO.cleanup()       # clean up GPIO on CTRL+C exit
GPIO.cleanup()           # clean up GPIO on normal exit
print "Clean up by resetting all GPIO"

Now for the fun part, the email notification and data log.

#!/usr/bin/env python
__author__ = "Mpho Mphego"
__description__ = "Doorbell notifier time logger and email notifier."
__version__ = "$Revision: 1.0 $"
__date__ = "$Date: 2015/01/10 02:09 $"
__copyright__ = "Copyright (c) 2015 Mpho Mphego"
__license__ = "Python"

import time
import datetime
import os
import smtplib
from email.mime.text import MIMEText

#-----------------------Data Logger-----------------
now =
timestamp = now.strftime("%H:%M on %Y/%m/%d")
outstring1 = " Someone was at the door at " + str(timestamp) 
outstring2 = "\n********************************************* \n "
outstring = outstring1 + outstring2

# -----------------------Email Notifier----------------------
# Replace with your details.
USERNAME = "*******"
PASSWORD = "*********"
MAILTO  = "******"

if os.system("ping -c 1 >> /dev/null 2&>1") == 0 :
	print "Sending Email Notification"
	msg = MIMEText('Someone is ringing the doorbell! \nGo Check!')
	msg['Subject'] = 'Doorbell notification!'
	msg['From'] = USERNAME
	msg['To'] = MAILTO

	server = smtplib.SMTP('')
	server.sendmail(USERNAME, MAILTO, msg.as_string())
	print "Unable to connect to Internet."

To have this run upon booting, we need to edit /etc/rc.local (as root since this is the owner).

sudo nano /etc/rc.local

At the bottom, just above exit 0 we’ll add a call to our script.

python /home/pi/Scripts/Smart_DoorBell/ 

One thought on “Smart Doorbell using RPi with voice and email notification.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s