Simple Raspberry Pi Home Security System
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
Hardware components
- Raspberry Pi 3 Model B
- Raspberry Pi Camera Module
- PIR Motion Sensor (generic)
Software apps and online services
- gmail account
- ssh connection
Code
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()
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.
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
Pingback: How To Setup Static IP Address on Raspberry Pi - Raspberry Pi
Pingback: Interfacing a light Sensor (LDR) with Raspberry Pi - Raspberry Pi
Pingback: Raspberry Pi GPIO Basics - IoTbyHVM - Explore TechBytes
Pingback: Getting Started with The Sense HAT - Raspberry Pi
Pingback: Redis : What and Why? - IoTbyHVM - Explore TechBytes
Pingback: IoT vs M2M | Difference between M2M and IoT - IoTbyHVM
Pingback: Setting up SPI on Raspberry Pi - IoTbyHVM - Explore TechBytes
Pingback: piCore (Tiny Core) Linux on Raspberry Pi - IoTbyHVM - Bits & Bytes of IoT
Pingback: Setup Docker on Raspberry Pi - IoTbyHVM - Bits & Bytes of IoT
Pingback: How to Run Ubuntu 18.04 or 18.10 on Raspberry Pi
Pingback: MQTT | What is MQTT | MQTT in Depth | QoS | FAQs | MQTT Introduction
Pingback: Arduino SPI Tutorial - IoTbyHVM - Bits & Bytes of IoT
Pingback: Raspberry Pi Introduction and Tutorials - OnionLinux