Umang AjmeraRavin Shah
Published © GPL3+

Smart Doorbell (PIR Sensor and Camera)

A doorbell, smart enough to sense someone at your door and notify you on your mail/phone with a captured photo with Google Drive Sync.

IntermediateFull instructions provided6 hours1,324
Smart Doorbell (PIR Sensor and Camera)

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
Any Model of Pi is fine.
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
Bought from amazon at Rs 140/- http://www.amazon.in/Hc-Sr501-Pyroelectric-Infrared-Motion-Detector/dp/B007XQRKD4?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o01_s00
×1
Webcam
Currently trying on a standard USB Webcam (Logitech). A camera module for pi can be set up in future
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Pushetta
For Push Notifications on mobile.

Story

Read more

Schematics

The Structural Flow Diagram

The Overall Flow of the project

Use Case Diagram

Sequence Diagram

Activity Diagram

Software Requirement Specifications (SRS)

good'ol sleep inducing soporific theoretical document.

Presentation

A fancy ready-made presentation. Thank me later, but do :p

Code

Python Script

Python
The main python script for the Smart Doorbell. It has a few dependencies to be installed, which I have explained in the description section.
from gpiozero import MotionSensor
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

from pushetta import Pushetta


import time
import os
import pygame
import smtplib

count = 0

pir = MotionSensor(4)
while True:
    if pir.motion_detected:
        print("Intruder detected!")
	time.sleep(0.5)
	count = count + 1
       	if count >= 10:
                print('Photo Captures now. Smile :) ')
                time.sleep(2)
		        os.system("fswebcam -S20 -r 960x720 --no-banner /home/pi/Drive/photo_%Y-%m-%d_%H:%M:%S.jpg")
	            os.system("fswebcam -S20 -r 960x720 --no-banner /home/pi/photo.jpg")

                print('Music Plays')
		        pygame.mixer.init()
                pygame.mixer.music.load("doorbell.mp3")
                pygame.mixer.music.play()
                while pygame.mixer.music.get_busy() == True:
                       continue

                print('Pushetta Notification')
                API_KEY="8761####################3449b2995ee8f405" //Your API Key
                CHANNEL_NAME="#########" //Your Channel Name ason Pushetta
                p=Pushetta(API_KEY)
                p.pushMessage(CHANNEL_NAME, "Yo !")

                print('Mail Composing')
		        fromaddr = 'ajmeraumang96@gmail.com' //Your From Address
		        toaddrs  = 'ajmera.umang6@gmail.com' // Your To Address
		
		#msg = 'Someones at your door!'		
                msg = MIMEMultipart()
                
                img_data = open('/home/pi/photo.jpg', 'rb').read()
                
                msg['Subject'] = 'Smart Doorbell'
                username = 'ajmeraumang96@gmail.com' //From Address emailID
		        password = '########' //From Address password

		        text = MIMEText("Someones at your door")
                msg.attach(text)
                image = MIMEImage(img_data, name=os.path.basename('/home/pi/photo.jpg'))
                msg.attach(image)

		server = smtplib.SMTP('smtp.gmail.com:587')
		server.starttls()
		server.login(username,password)
		server.sendmail(fromaddr, toaddrs, msg.as_string())
		server.quit()
		print('Mail Sent')
		time.sleep(3)

		print('Now Pushing images to google drive')
		os.chdir("/home/pi/Drive")
		os.system("gdrive push -quiet")  //Install gdrive separately
        print('Sync Complete')
		time.sleep(5)
                
    else:
		print("No Intruder ")
		count = 0
	

Credits

Umang Ajmera
1 project • 3 followers
A Computer Engineering graduate having an alacrity towards exciting IoT projects.
Ravin Shah
1 project • 1 follower
final year computer engineering student
Thanks to Circuit Basics.

Comments