Raspberry Pi Home Security System with Camera and PIR Sensor

Detecting motion with PIR sensor and sending the Raspberry Pi Camera image as email.

Home Security System with Camera and PIR Sensor

Things used in this project

Hardware components

Software apps and online services

  • gmail account
  • ssh connection

Story

screenshot code

Schematics

Connect Pin 3 of Raspberry Pi(5V Power) to the Power pin of the sensor.
Pin 5 of Raspberry Pi (GND) to the GND of the Sensor
And Pin GPIO23 of Raspberry Pi to the output Pin of the sensor(of course one can use different GPIO but then one should change to Python code)

Schematics

Code

It is a simple python code just change the emails as you have. I have kept 10 seconds of delay after the image is captured. so the next movement will only be detected after 10 seconds. one can change to time with their requirements.
from picamera import PiCamera
from time import sleep
import smtplib
import time
from datetime import datetime
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import RPi.GPIO as GPIO
import time

toaddr = ‘TO_EMAIL'
me = ‘FROM_EMAIL'
Subject=‘security alert'

GPIO.setmode(GPIO.BCM)

P=PiCamera()
P.resolution= (1024,768)
P.start_preview()

GPIO.setup(23, GPIO.IN)
while True:
if GPIO.input(23):
print(“Motion…”)
#camera warm-up time
time.sleep(2)
P.capture(‘movement.jpg')
time.sleep(10)
subject=‘Security allert!!'
msg = MIMEMultipart()
msg[‘Subject'] = subject
msg[‘From'] = me
msg[‘To'] = toaddr

fp= open(‘movement.jpg',‘rb')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)

server = smtplib.SMTP(‘smtp.gmail.com',587)
server.starttls()
server.login(user = ‘FROM_EMAIL',password=‘PASSWORD')
server.send_message(msg)
server.quit()

Read More Detail  : Raspberry Pi Home Security System with Camera and PIR Sensor


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top