Having a smart home security system that can detect and alert me of intruders is something I have wanted for a long time. As smart home devices get cheaper and more advanced, DIY home automation is now within reach for the average tinkerer. In this guide, I will walk through how I built my own Raspberry Pi based security system that sends me alerts when it detects motion or someone opening doors/windows in my house.

Selecting Components

The core of my DIY system is the Raspberry Pi microcomputer. The Raspberry Pi works well for home automation projects because it is inexpensive, runs Linux, and has GPIO pins to connect sensors and other hardware. For my project, I chose the Raspberry Pi 3 Model B+ for its good balance of price, performance, and connectivity options.

In addition to the Raspberry Pi, I used the following main components:

Setting up the Raspberry Pi

With my components gathered, it was time to setup the Raspberry Pi. I installed the latest Raspbian OS using NOOBS for ease of setup. Raspbian provides a Debian Linux environment optimized for the Raspberry Pi hardware.

I enabled SSH and connected my Raspberry Pi to WiFi to allow controlling it remotely via SSH. A remote connection makes development easier.

A key setup step was enabling the Raspberry Pi camera module. I added camera_auto_detect=1 and camera_vflip=1 to /boot/config.txt and rebooted to activate the camera module.

Connecting Sensors

Next I connected the motion sensor and door/window sensors to the GPIO pins on the Raspberry Pi.

The motion sensor has 3 pins - VCC, GND, and OUT. VCC and GND were connected to the Raspberry Pi's 5V power and ground pins respectively. The OUT pin was connected to GPIO 4 to allow detecting when motion is sensed.

The door/window sensors were wired similarly, with the VCC and GND connected to power and ground, and the OUT pin connected to GPIO 17.

Capturing Camera Footage

To capture footage on motion detection, I wrote a Python script that checks the state of the motion sensor.

import RPi.GPIO as GPIO
from picamera import PiCamera

pir_sensor = 4
camera = PiCamera()

GPIO.setup(pir_sensor, GPIO.IN)

while True:
if GPIO.input(pir_sensor):
print("Motion Detected!")

This initializes the camera module, and when motion is detected, begins a 5 second preview recording from the camera.

Sending Alerts

Finally, I wanted my system to proactively alert me on intrusion detection. I used Pushover to send push notifications to my phone when the sensors are triggered.

My Python script sends a Pushover request like:

from pushover import Client

client = Client("myapptoken", "userkey")
client.send_message("Intruder alert!", "Motion detected in kitchen!")

Now I immediately get an alert on my phone anytime one of the sensors is set off.


By leveraging a Raspberry Pi and basic sensors, I was able to create an inexpensive but powerful home security system. The project combined physical computing hardware with software scripting to monitor activity and send notifications. This is just the beginning - there is a lot more I could do to expand my DIY smart home security. Some ideas are adding facial recognition to the camera module, deploying more sensor types, and creating a web interface to view system status. The possibilities are endless!