In today’s era, home security is becoming increasingly prominent feature. Security is primary concern everywhere and for everyone. Every person wants his home, industry etc. to be secured. The aim of our project is to design and implement affordable, flexible and fast monitoring home security system using a Raspberry Pi and a Passive Infrared (PIR) motion sensor. In this project we use motion detection to trigger video recording via the Raspberry Pi camera module.
A Passive Infrared (PIR) sensor interfaced to the Raspberry Pi which detects when a human (or any animal) moves in front of it, and signals this detection to the Raspberry Pi. The Raspberry Pi than triggers the video recording via the Raspberry Pi Camera module. Meantime the notification about the detection will be sent to us via an email. Once a notification is received, we can log into our Raspberry Pi remotely and view the recorded video and if found something theft is going to happen we can raise an alarm through an active buzzer to intimate others and hence we can secure our home.
SMART HOME SECURITY SYSTEMPython
#!/usr/bin/env python # encoding: utf-8 import os import smtplib from email import encoders from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart COMMASPACE = ', ' def main(): sender = 'email@example.com' gmail_password = '9620955777' recipients = ['firstname.lastname@example.org'] # Create the enclosing (outer) message outer = MIMEMultipart() outer['Subject'] = 'mail' outer['To'] = COMMASPACE.join(recipients) outer['From'] = sender outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' # List of attachments attachments = ['/home/pi/image/image1.jpg'] # Add the attachments to the message for file in attachments: try: with open(file, 'rb') as fp: msg = MIMEBase('application', "octet-stream") msg.set_payload(fp.read()) encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file)) outer.attach(msg) except: print("Unable to open one of the attachments. Error: ", sys.exc_info()) raise composed = outer.as_string() # Send the email try: with smtplib.SMTP('smtp.gmail.com', 587) as s: s.ehlo() s.starttls() s.ehlo() s.login(sender, gmail_password) s.sendmail(sender, recipients, composed) s.close() print("Email sent!") except: print("Unable to send the email. Error: ", sys.exc_info()) raise from gpiozero import MotionSensor from picamera import PiCamera from datetime import datetime camera = PiCamera() pir = MotionSensor(4) while True: pir.wait_for_motion() print ("motion detected") camera.capture('/home/pi/image/image1.jpg') filename = datetime.now().strftime("/home/pi/videos/%Y-%m-%d_%H.%M.%S.h264") camera.start_recording(filename) pir.wait_for_no_motion() camera.stop_recording() main()
from gpiozero import Buzzer from time import sleep buzzer = Buzzer(17) while True: buzzer.on() sleep(1) buzzer.off() sleep(1)
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!