Building a do-it-yourself (DIY) smart home security system with a Raspberry Pi and motion sensors is an excellent way to automate home security on a budget. With some basic hardware and free open-source software, you can create a system that detects motion and sends you notifications.
Overview of Raspberry Pi Home Security System
The Raspberry Pi is a small, inexpensive, single-board computer that runs Linux. It has input/output pins that can interface with electronic components like motion sensors.
To build a security system, I will use:
- Raspberry Pi - The brain of the system running software to detect motion and send notifications
- Motion sensors - Detect movement and trigger the Raspberry Pi
- Camera module (optional) - Capture images when motion detected
- Breadboard - Connects components to the Raspberry Pi
- Jumper wires - Wires for breadboard connections
- SD card - Stores Raspberry Pi operating system and software
- Power supply - Powers the Raspberry Pi
With these components, I can detect motion and receive mobile notifications anywhere. I can also view camera footage for visual verification.
Step 1 - Set Up the Raspberry Pi
The first step is preparing the Raspberry Pi.
-
Install the Raspberry Pi OS on an SD card. The Raspberry Pi Imager software makes this easy.
-
Insert SD card into Raspberry Pi and connect keyboard, mouse, monitor, Ethernet cable, and power supply.
-
Boot the Pi and run
sudo raspi-config
to set up Wi-Fi, enable SSH for headless access, and perform other basic setup. -
Update the OS packages:
sudo apt update
sudo apt full-upgrade -
Reboot Pi to apply updates.
With basic setup complete, it's time to install the software needed for motion detection and notifications.
Step 2 - Install Motion Software
There are a few open-source software options for turning the Raspberry Pi into a motion detecting camera. I will use Motion, a highly customizable program with mobile push notifications.
To install Motion:
sudo apt install motion
Now Motion needs to be configured. I'll modify /etc/motion/motion.conf
with these settings:
daemon
on - Motion will run continuously as a background processstream_localhost
off - Disable live video stream from Pi itselfwebcontrol_localhost
off - Disable Motion web interfacewidth
andheight
- Camera resolutionframerate
- Frame rate for capturing videopre_capture
- Number of frames to buffer before motion detectedpost_capture
- Number of frames to buffer after motion stopsgap
- Minimum time between detectionstext_changes
on - Log only changes to the camera imagepicture_output
- Store images in a subfolderffmpeg_output_movies
on - Record video clips when motion detected
I can also set parameters like sensitivity and motion detection areas.
Step 3 - Add a Camera Module
The Raspberry Pi camera module enables our security system to capture images and video when motion is detected.
To set up the camera module:
-
Carefully connect the ribbon cable to the camera port on the Raspberry Pi.
-
Enable the camera in
sudo raspi-config
or withsudo modprobe bcm2835-v4l2
. -
Test the camera with
raspistill -o test.jpg
.
With the camera connected, Motion will automatically use it for capturing media. The resolution and frame rate can be configured in motion.conf
.
Step 4 - Connect a Motion Sensor
Motion sensors allow the system to detect movement and trigger the camera.
PIR sensors (passive infrared) are common affordable motion detectors perfect for DIY home security:
-
Connect the PIR sensor to ground, 5V power, and a GPIO pin on the Raspberry Pi.
-
Enable GPIO pin for Motion in
motion.conf
withon_motion_detected
. -
Adjust PIR sensor mode and sensitivity as needed.
Now the motion sensor will trigger Motion software whenever movement is detected.
Step 5 - Set Up Notifications
Receiving notifications on your phone when motion is detected is easy with Motion.
-
In
motion.conf
, enablesqlite3
database support to store event logging. -
Install a plugin like
motioneye
orpushover
for push notifications. Configure API keys. -
Enable desired notification types in the plugin configuration file.
With notifications configured, you will get alerted any time the motion sensors are triggered.
Advanced Options
Some advanced options for enhancing your Raspberry Pi security system further:
-
Add multiple cameras around your home for full coverage. Set up each camera separately in Motion.
-
Connect a spotlight or siren to a GPIO pin to activate when motion detected.
-
Store media and data on external NAS instead of the SD card for reliability.
-
Set up automated off-site backups like rsync to another server.
-
Configure port forwarding on your router for remote access from your phone/computer.
-
Train a machine learning model to detect people specifically in camera images.
The possibilities are endless for building on the core motion detecting functionality!
Conclusion
Setting up a home security system with Raspberry Pi and motion sensors is an achievable DIY project for automating peace of mind. With Motion software handling motion detection, camera integration, media capture, and notifications, I have an inexpensive and customizable system to watch over my home. This can be scaled and enhanced over time by adding components and leveraging Motion's advanced configuration options. Let me know if you have any other questions!