Raspberry Pi as low-cost HD surveillance camera

Project by

Home surveillance is becoming very popular as people feel the need to keep an eye on their surroundings when they are away at work or some other place. A disadvantage of conventional surveillance systems is that they are very costly. With the emergence of cheaper computing solutions it must be less costly to set up a high definition home surveillance system. One such solution is using Raspberry Pi which can record videos on motion detection. The recorded videos can be streamed online.

Raspberry Pi

Raspberry Pi is a small single-board computer. Small in sense that it has the size of a credit card. It is very much large if the range of applications is taken into account. It was developed by the Raspberry Pi Foundation founded in 2009 and released in 2012. Originally developed to promote computer education in schools Raspberry Pi quickly became popular as a tool to implement numerous applications including a small fully functional laptop.

Operating Systems

Raspberry Pi runs several Gnu/Linux operating systems out of the box. All popular Gnu/Linux operating systems like Debian, Fedora, Gentoo, Arch Linux and Ubuntu runs on Raspberry Pi. The Raspberry Foundation recommends the use of Raspbian, a Debian based operating system maintained by the foundation. This project is written keeping a Raspberry Pi running Raspbian because it is very popular and well documented. BSD based operating systems Free BSD and NetBSD are also known to run on Raspberry Pi.

Raspberry Pi Model-B

Raspberry Pi comes in different models. This tutorial is written considering a Raspberry Pi Model B. This model comes with a 512 MB RAM and sports two USB ports and a 100 MB Ethernet port. It has been used in various applications by hobbyists, gamers, bit coin miners and many others.

Raspberry Pi Camera Module

The Raspberry Pi camera module is built to work perfectly with Raspberry Pi devices. It supports high definition video capture and photography. It sports a fixed focus 5 MP camera that can shoot videos at 30 and 60 fps on 1080p and 720p resolutions respectively. This is sufficient for home surveillance applications. A home surveillance system set up using Raspberry Pi can not just capture and record video but also to stream it live using a web browser.

Other hardware requirements

Other than the Raspberry Pi and the camera module setting up a surveillance system requires some other hardware also. The surveillance system needs a camera housing of appropriate size that can house the camera module and the Raspberry Pi. Installation of operating system, which in this article is Raspbian, requires a micro SD card. A Wi-Fi USB adapter makes live streaming possible and a power supply is certainly indispensable.

Steps to set up home surveillance using Raspberry Pi

Step 1:- Installing Raspbian

To install Raspbian the micro SD card is to be prepared properly with the help of a PC. There are GUI tools for various operating systems to make this process easy. A good example is the Fedora Arm Installer for Fedora and Windows. The micro SD card with the operating system is to be inserted in the slot and the Raspberry Pi is to be connected to a LAN cable, a monitor and a USB keyboard. Once everything is set up power supply is provided. The operating system starts booting displaying a guided installation setup. For implementing a surveillance system it is necessary that SSH and camera are enabled so that the device can be controlled without the keyboard and the monitor and the camera module becomes functional. 

Step 2:- Updating software

It is recommended to update the software by entering the following commands in the terminal.

Commands to update Raspberry Pi:-

sudo apt-get install rpi-update

sudo rpi-update

Command to update packages:-

sudo apt-get update

sudo apt-get upgrade

Step 3:- Connecting to Raspberry Pi from another computer.

The Raspberry Pi is now set up and ready to be accessed from another computer. To connect to the Gnu/Linux console of Raspberry Pi from a computer running Windows software named PuTTY can be used. The same can be accomplished on a computer running Gnu/Linux with the help of a few terminal commands. You need to become a member of the dialout group and then use a terminal emulator like GtkTerm to connect to the Pi by entering the correct port name and baud rate. 

Commands for Gnu/Linux:-

Checking dialout group - ls -l /dev/ttyUSB0

To check if current user is in dialout group – id

Add current user to dialout group - sudo usermod -a -G dialout username

Step 4:- Enabling Wi-Fi

The network interfaces of Raspberry Pi can be edited using text editor nano to enable Wi-Fi.

To open network interfaces: - sudo nano /etc/network/interfaces

Lines to be inserted into the file:-

allow-hotplug wlan0

iface wlan0 inet dhcp



Terminal window

terminal window

To reboot Raspberry Pi – sudo reboot

Step 5:- Assembling Hardware

The hardware must be assembled carefully. The Raspberry Pi must be placed properly so that it does not tumble inside the camera mounting. The hardware inside the mounting can be hidden without disturbing the view of the camera using a dark paper that has a hole. A red LED glows to indicate the camera is active. This can be turned off by editing a configuration file in the boot directory.

Step 6:- Enabling motion detection

Motion detecting can be enabled in Raspberry Pi by installing software like motion. If motion is used a custom build supporting Raspberry Pi camera module has to be installed. The motion detecting software needs to run continuously and hence motion will have to be run as a daemon. The log file of motion is to be made available to auto start user by moving it to a directory outside the home directory of current user.

To install motion: - 

sudo apt-get install motion

To install custom build:-

cd /tmp

sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev

wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz

To unpack tarball: -

tar zxvf motion-mmal.tar.gz

To update motion: -

sudo mv motion /usr/bin/motion

sudo mv motion-mmalcam.conf /etc/motion.conf

t motion configuration :- sudo nano /etc/motion.conf

Lines to be added:-

daemon on

logfile /tmp/motion.log

Enabling motion daemon: - sudo nano /etc/default/motion

Change the line: - start_motion_daemon=yes

Edit motion configuration: - sudo nano /etc/motion.conf

Lines to be added:-

daemon on

logfile /tmp/motion.log

Step 7:- Modifying the video recording

The video being recorded and stream can be modified to suit the requirements by setting appropriate values for resolution and frame rate. Surveillance cameras need very small frame rates and need not be very long. The live stream can be protected from unauthorized access by making it password protected.


width 1280

height 720

framerate 2

pre_capture 2

post_capture 2

max_mpeg_time 600

ffmpeg_video_codec msmpeg4

stream_localhost off

stream_auth_method 2 


Step 8:- Saving video to a shared folder

To save memory of the microSD card the video being recorded can be saved to a shared folder in the personal computer. The details of the shared folder are to be inserted into a modified fstab configuration file in Raspberry Pi. The shared folder can be set as the target for the video recording after rebooting the Raspberry Pi. 

Step 9:- Streaming the video

The video can be streamed by entering an appropriate URL on a web browser that bears the port address. Enabling a dynamic domain service lets the video to be streamed from anywhere.

Related Items
Suggested Products