A smart home security system with Raspberry Pi allows you to monitor and control your home security through your smartphone or computer. With some basic electronics knowledge and coding skills, I was able to build an automated system that sends me alerts whenever there's suspicious activity at home. My neighbors were quite impressed with its capabilities and even asked me to help them set up their own!

In this guide, I'll walk you through the components needed, how to assemble the hardware, write the software code, and set up remote access from your devices. Follow along to make your own next-level DIY smart home security on a budget.

Hardware Components

To build the core security system unit, you will need:

For remote access and control, you'll also need:

With these components, we can assemble a DIY smart security system with motion detection, camera recording, and notifications. Now let's look at how to put everything together.

Assembling the Hardware

Follow these steps to assemble the hardware components:

Set up the Raspberry Pi

  1. Install the Raspberry Pi OS on the microSD card. I prefer the Raspberry Pi OS Lite since we don't need the full desktop environment.

  2. Insert the microSD card into the Raspberry Pi and connect the power supply.

  3. Connect the Raspberry Pi to your home WiFi router using an ethernet cable or by configuring WiFi.

  4. Enable the Raspberry Pi Camera Module in the system settings if using the official camera.

Connect the motion sensor

  1. Place the PIR motion sensor on the breadboard.

  2. Connect VCC on the sensor to the Raspberry Pi 5V pin and GND to GND using jumper wires.

  3. Add a 1kΩ resistor between the DOUT pin on the sensor and GPIO pin 4 on the Pi. This prevents false triggers.

  4. Connect another 1kΩ resistor between DOUT and the 3V3 pin on the Pi.

The motion sensor is now connected! The DOUT pin will output a HIGH signal (3.3V) when motion is detected.

Add the camera module

Simply connect the camera module ribbon cable to the CSI port on the Raspberry Pi. The software will handle the rest later.

That completes the hardware assembly. Just plug in the power and the core of the security system is ready! Now we need to program its smart capabilities.

Software Programming

With Python and some Raspberry Pi-specific libraries, we can program the motion detection, camera recording, and notification functionality:

Import libraries

import RPi.GPIO as GPIO
import picamera
from time import sleep
from datetime import datetime
import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

This imports the Python libraries we need for hardware pins, camera module, timing, email notifications, etc.

Configure motion sensor pins

pirPin = 4 #PIR connected to this GPIO pin  
GPIO.setup(pirPin, GPIO.IN) #Set pin as input

Here we specify the GPIO pin connected to the PIR sensor and set it to input mode to read the digital signal.

Define camera module

camera = picamera.PiCamera()
camera.resolution = (1024, 768) # set resolution
camera.start_preview() # start camera

This initializes the camera module and begins a preview stream.

Function to detect motion

def detectMotion(pirPin):
  if GPIO.input(pirPin): 
    print("Motion Detected!") 
    return True #return True on motion
    return False

Simple function that returns True when the PIR sensor pin goes HIGH.

Function to capture image

def captureImage():
  timestamp ="%Y-%m-%d_%H-%M-%S")
  print("Image Captured")

Uses the camera module to capture an image file with a timestamped filename when called.

Function to send email alert

def sendAlert(imgFileName):
  msg = MIMEMultipart()
  msg['Subject'] = 'Security Alert!'
  msg['From'] = '[email protected]'
  msg['To'] = '[email protected]'

  imgData = open(imgFileName,'rb').read()
  image = MIMEImage(imgData, name=os.path.basename(imgFileName))

  s = smtplib.SMTP('', 587) 
  s.login("[email protected]", "password")

  print("Email Alert Sent!")

Uses SMTPlib to send an email with the captured image as an attachment. Credentials need to be configured.

Main program loop

while True:
  if detectMotion(pirPin):
    imgName = captureImage()

Continuously checks for motion. If detected, it captures an image, saves it, and emails an alert with the image attached. A slight delay prevents over-triggering.

This covers the core programming logic. Additional code can enhance the system with remote access, live streaming, automation rules, etc. But this achieves basic smart security capabilities!

Setting Up Remote Access

To view the camera feed and receive alerts from your smartphone or computer:

With these steps, you can remotely monitor your home security system and receive motion alerts from anywhere!

Closing Thoughts

Building your own smart security system with Raspberry Pi is an achievable weekend project that takes DIY home automation to the next level. With just a few common hardware components and some Python coding, you can construct an automated system that rivals professional setups at a fraction of the cost.

This project is also a great starting point to explore more advanced features like facial recognition, two-way audio, self-hosted storage, home automation integration, and more. Don't be surprised if your tech-savvy neighbors start asking you to build them a system too!

So empower your inner maker, tap into the potential of Raspberry Pi, and enjoy peace of mind knowing your home is protected with your own custom-built smart security solution. Just be ready to field inquiries from impressed neighbors who want security like yours!