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:

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.

  1. Install the Raspberry Pi OS on an SD card. The Raspberry Pi Imager software makes this easy.

  2. Insert SD card into Raspberry Pi and connect keyboard, mouse, monitor, Ethernet cable, and power supply.

  3. Boot the Pi and run sudo raspi-config to set up Wi-Fi, enable SSH for headless access, and perform other basic setup.

  4. Update the OS packages:

    sudo apt update
    sudo apt full-upgrade

  5. 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:

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:

  1. Carefully connect the ribbon cable to the camera port on the Raspberry Pi.

  2. Enable the camera in sudo raspi-config or with sudo modprobe bcm2835-v4l2.

  3. 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:

  1. Connect the PIR sensor to ground, 5V power, and a GPIO pin on the Raspberry Pi.

  2. Enable GPIO pin for Motion in motion.conf with on_motion_detected.

  3. 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.

  1. In motion.conf, enable sqlite3 database support to store event logging.

  2. Install a plugin like motioneye or pushover for push notifications. Configure API keys.

  3. 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:

The possibilities are endless for building on the core motion detecting functionality!


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!