Hello Visitors, Today i am telling you How to make a simple mini project, Raspberry Pi Home Security System with Camera and PIR Sensor.
In this tutorial we are capturing image when motion is detected with Raspberry Pi camera and sending that image as email notification. I have used python to write the script. You should have two email accounts (I have used gmail), to send and receive emails. I have connected PIR sensor on GPIO 23. If your gmail uses SSL certificates you might need another port that 587.
Things used in this project
- Raspberry Pi 3 Model B
- Raspberry Pi Camera Module
- PIR Motion Sensor (generic)
Software apps and online services
- gmail account
- ssh connection
It is a simple python code just change the emails as you have.
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_address' me = 'FROM_EMAIL_address' Subject='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()
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.
I am always looking forward to discussion about the project and comments, suggestions, etc.
You may like also:
- Best OS for Raspberry Pi
- Raspberry Pi Home Security System with Camera and PIR Sensor tutorial
- Setting up a Raspberry Pi headless
- Raspbian – OS For Raspberry Pi
- ROCK Pi 4 : Overview | Installation