Home > News & Updates > Electronics News Updates > Doorbell alert with pushmessage and mail with webcam footage

Doorbell alert with pushmessage and mail with webcam footage

Summary of Doorbell alert with pushmessage and mail with webcam footage


This article details a Raspberry Pi project that sends push notifications and emails with webcam footage when the doorbell is pressed. The system uses a relay to connect the doorbell circuit to the Pi's GPIO pins, triggering Python scripts via Pushover for alerts and email for visual verification. It includes hardware modifications like LEDs, capacitors, and diodes to ensure safe operation alongside the software logic for capturing images and sending messages.

Parts used in the Doorbell alert with pushmessage and mail with webcam footage:

  • Raspberry Pi
  • Pushover app
  • Wireless transmitter
  • Relay
  • LED
  • 330R resistor
  • 100u capacitor
  • Flyback diode
  • Test switch
  • Logitech C270 webcam

Pi-files: Doorbell alert with pushmessage and mail with webcam footage

Actually the first ‘project’ I ever did with a Raspberry Pi was sending a push message to my Iphone. It was 2012, I was lying sick in bed and found a new app on my Iphone called Pushover (what else to do when you’re sick?). With Pushover you can send and receive custom made push messages. On the website I found a simple Python script to send messages. I knew the Rpi was able to run Python code, so here my Rpi adventures started. Within 30 minutes I was able to receive ‘hello world’ on my phone (needless to say I wasn’t lying in bed anymore). Seeing ‘hello world’ on your screen is like the software equivalent of the blinking led, THE coolest feature ever!
I decided to hook up this push message feature with my doorbell. The idea is that every time somebody rings the doorbell, I get a push message that there is somebody at the door. The wires of the doorbell were already connected to a wireless transmitter and I wanted to keep thaDoorbell alert with pushmessage and mail with webcam footaget functionality. I used a relay to combine the transmitter with a switch on the GPIO header of the Raspberry Pi.
The led and 330R resistor can be installed in the actual doorbell, so the person can find the doorbell and is triggered when the button is pressed in case he/she doesn’t actual hear the bell (the led turns off when the doorbell is pressed). The 100u capacitor and flyback diode are to limit voltage peaks when using the relay. The ‘test’ switch is available close to the GPIO header to test the (software) functionality of the doorbell alert. The relay and test switch are connected to pin11 (GPIO0) of the Rpi.
The Python code looks as follows. First the necessary libraries are included and the GPIO header is configured:
#import libs
import RPi.GPIO as GPIO
import httplib, urllib
import time
from time import sleep, localtime, strftime
#display no warnings (on command line)
GPIO.setwarnings(False)
#set GPIO: use RPi board pin numbers
GPIO.setmode(GPIO.BOARD)  #alternative is GPIO.BCM (Broadcom names)
#set pin 11 as input
GPIO.setup(11, GPIO.IN)  #Input: doorbell (relay)
A seperate function is written for the push message. This is mainly copied from the Pushover FAQ section (‘How do I send Pushover notifications in Python?’). The token (‘push_token’) and user ID (‘push_user’) you get when you sign in on the website. There you can also select the devices on which you want to receive the push messages.
#set up push message (pushover)
def push(text):push_token = ‘xxx’
push_user   = ‘yyy’

conn = httplib.HTTPSConnection(“api.pushover.net:443”)
conn.request(“POST”, “/1/messages.json”,
urllib.urlencode({“token”: push_token,
“user”: push_user,
“message”: text,}),

             {“Content-type”: “application/x-www-form-urlencoded” })
conn.getresponse()

The main loop checks for the GPIO input regularly. I added a tiny bit of delay (sleep) to relieve the CPU. When the doorbell is pressed, it takes the current date and time and adds that to the push message.

while 1:

sleep(0.1) #relieves CPU load big time!

#if doorbell is pressed…
if GPIO.input(11):

#determine date/time and add to message
timestr_date = strftime(“%a %d %b %Y”, localtime())
timestr_time = strftime(“%H:%M:%S”, localtime())

mess = “Doorbell pressed on {}, {}.”.format(timestr_date,timestr_time)
print “\n”
print mess

push(mess)

When this all worked it was time to extend the doorbell alert feature. Not only I want to know that there is someone at the door, I also would like to know who was at the door, especially when I am not at home. I added a Logitech C270 webcam to the setup to capture snapshots and a short movie.

A Python mail script is supposed to send it all to my mailbox. The mail functionality I didn’t invent myself, I just relied on the beautiful internet community. On Kutuma’s Ramblings I found almost exactly what I needed. The only difference is that I wanted to sent multiple attachments. For that I changed the mail function a little bit:

Quick Solutions to Questions related to Doorbell alert with pushmessage and mail with webcam footage:

  • How did the author start their Raspberry Pi adventures?
    The author started by finding a Python script on the Pushover website to send custom push messages to an iPhone.
  • Can the original wireless transmitter functionality be kept?
    Yes, the author used a relay to combine the existing transmitter with a switch on the GPIO header while keeping its functionality.
  • What components are used to limit voltage peaks when using the relay?
    A 100u capacitor and a flyback diode are installed to limit voltage peaks during relay operation.
  • Which GPIO pin is connected to the relay and test switch?
    The relay and test switch are connected to pin 11 (GPIO0) of the Raspberry Pi.
  • Does the code add the date and time to the notification message?
    Yes, the main loop determines the current date and time and adds it to the push message when the doorbell is pressed.
  • Why was a Logitech C270 webcam added to the setup?
    The webcam was added to capture snapshots and short movies to identify who is at the door when the user is not home.
  • How were multiple attachments handled in the email script?
    The author modified the mail function found on Kutuma's Ramblings to support sending multiple attachments.
  • What library is imported to configure the GPIO header?
    The RPi.GPIO library is imported and configured to set the board pin numbers mode.
  • Does the sleep function in the main loop affect CPU load?
    Adding a small delay using sleep relieves the CPU load significantly.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top