Raspberry Pi Security System with Pi Camera and Motion Sensor

Create your own security camera using Raspberry Pi Camera

Introduction

Do you want to know who always enter your room when you’re not around??‍♂️??? This project will help you to capture an image or record a video whenever it detects any motion.

Video

This video shows how to get make a simple security system that can capture an image or record a video using Raspberry Pi.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python3 sample program for capturing an image. You can use it with Thonny Python IDE.

from gpiozero import MotionSensor
from picamera import PiCamera
import time
from time import sleep
pir = MotionSensor(4)
camera = PiCamera()
camera.rotation = 180
while True:
pir.wait_for_motion()
print("Motion detected!")
camera.start_preview(fullscreen=False, window = (1250,10,640,480))
filename = "/home/pi/Desktop/" + (time.strftime("%y%b%d_%H:%M:%S")) + ".jpg"
camera.capture(filename)
pir.wait_for_no_motion()
camera.stop_preview()

view raw
security_image.py
hosted with ❤ by GitHub

This is python3 sample program for recoding a video. You can use it with Thonny Python IDE.

from gpiozero import MotionSensor
from picamera import PiCamera
import time
from time import sleep
pir = MotionSensor(4)
camera = PiCamera()
camera.rotation = 180
while True:
pir.wait_for_motion()
print("Motion detected!")
camera.start_preview(fullscreen=False, window = (1250,10,640,480))
filename = "/home/pi/Desktop/" + (time.strftime("%y%b%d_%H:%M:%S")) + ".h264"
camera.start_recording(filename)
pir.wait_for_no_motion()
camera.stop_recording()
camera.stop_preview()

view raw
security_video.py
hosted with ❤ by GitHub

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
Tutorials of Cytron Technologies Scroll to Top