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


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'


P.resolution= (1024,768)
GPIO.setup(23, GPIO.IN)
while True:
    if GPIO.input(23):
        #camera warm-up time
        subject='Security allert!!'
        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = me
        msg['To'] = toaddr
        fp= open('movement.jpg','rb')
        img = MIMEImage(

        server = smtplib.SMTP('',587)
        server.login(user = 'FROM_EMAIL',password='PASSWORD')


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:


Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!

%d bloggers like this: