Introduction: Raspberry Pi Surveillance Camera With Email Alert

Security is major concern now days and there are lot of technologies present today to keep your place secure and monitored. CCTV cameras are very useful to keep an eye on your house or office. Although prices of these types of cameras have been reduced significantly since their beginning but still IP cameras, which have ability to send and receive the date over the network, are very expensive. In this Instructable we made a small surveillance camera which will send an email alert, if the camera detects any motion in front of the camera

Step 1: Gather the Components

1.Raspberry Pi camera / webcam

2.raspberry pi 3

3.Motion sensor

Step 2: Programming Your Raspberry Pi

python will be good choice to Program raspberry Pi, so did we...

code:

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 = 'xxxxxxxxxxx@gmail.com' # receivers email id

me = 'xxxxxxxxxxx@gmail.com' # senders email id

Subject='security alert'

GPIO.setmode(GPIO.BCM)

P=PiCamera()

P.resolution= (320,240)

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 = 'xxxxxxxxxxx@gmail.com',password = 'xxxxxxxxx') #email id and passwords of senders

server.sendmail(me, toaddr, msg.as_string())

server.quit()

P.stop_preview()

Attachments

Step 3: Running Python Code and Troubleshooting

connect PIR sensor pins to

1.PIR vcc to rpi-2(Physical Pin)

2..PIR gnd to rpi-6 (Physical Pin)

3. PIR out to rpi-16 (Physical Pin)

(Physical pins count will start from 1-40 see the picture)

" FOR MORE INFO PLEASE SEE THE PICTURES "


copy the code on to the rpi-desktop

then open terminal

  • cd Desktop/
  • sudo python codce1.py

that's it

troubleshooting

1.if you found any indentation error while executing python please download the code from the attachment code1.py

2.if you find black / grey screen instead of video feed in Pi

type the following command in terminal

sudo modprobe bcm2835-v4l2

3.make sure you have added proper gmail credentials, then run the python code

Attachments