Security cameras can be expensive to purchase and install. However, with a Raspberry Pi mini computer, you can build your own low cost motion detecting security camera to monitor your home or office. In this comprehensive guide, I will walk through all the steps required to set up your own DIY security camera using a Raspberry Pi.

What You Will Need

To build your Raspberry Pi security camera, you will need the following components:

Installing the Operating System

The first step is to install an operating system onto the Raspberry Pi. This will allow us to operate the Pi and camera module.

I recommend using Raspberry Pi OS, the official operating system optimized for the Pi's hardware. Download the Raspberry Pi Imager from the Raspberry Pi website to easily install Raspberry Pi OS onto your microSD card.

With the SD card inserted into your computer, open Raspberry Pi Imager and:

  1. Choose Raspberry Pi OS as the operating system
  2. Select your SD card drive
  3. Click "Write" to install the OS

Once complete, insert the microSD card into the Raspberry Pi.

Setting Up the Camera Module

Now we need to hook up and configure the camera module.

Attach the camera module to the CSI port on the Raspberry Pi. It only fits one way, so line it up carefully.

Enable the camera in Raspberry Pi configuration settings:

  1. Launch Raspberry Pi Configuration from the main menu
  2. Go to the Interfaces tab
  3. Enable camera support

Test the camera from the command line:

raspistill -v -o test.jpg

This will take a photo and save it as test.jpg so you can confirm the camera works.

Capturing and Storing Footage

With the camera operational, we can now set up continuous video recording. The Raspberry Pi will store captured security footage on the microSD card.

Install Motion to handle video recording:

sudo apt install motion

Configure Motion by editing /etc/motion/motion.conf:

Restart Motion to apply the changes:

sudo service motion restart

Motion will now continuously capture video and store it in the target directory when motion is detected.

Adding Motion Detection

Obviously, we don't want our security camera recording non-stop. Let's add a motion sensor so it only records when movement occurs.

A PIR (passive infrared) motion sensor is easy to connect to the Raspberry Pi.

Wire it up:

Enable GPIO 4 as an input in /boot/config.txt:


Set Motion to trigger on GPIO 4:

Now the camera will detect motion when the PIR sensor is triggered!

Viewing the Live Feed Remotely

To view the security feed remotely, we can stream the video over the local network.

Install a streaming server like ffserver:

sudo apt install ffmpeg ffserver

Configure ffserver by editing /etc/ffserver.conf:

Start ffserver:

sudo ffserver -f /etc/ffserver.conf

You can now view the live stream by visiting:



Building your own Raspberry Pi security camera is an inexpensive way to monitor your home or office. With these steps, you can set up motion-activated recording, remote streaming, and more. Some additional features you may want to add include:

The Raspberry Pi platform makes an extremely versatile and customizable security camera solution. With a DIY approach, you can build exactly the features you need without paying for expensive pre-made systems.