Transparent Communications
Transparent Communications

How To Make a Cheap CCTV System With The Raspberry Pi

Raspberry Pi CCTV | Transparent

Comprehensive CCTV systems can often be quite expensive particularly for smaller projects or just for home use, so this post was created to inform you on how to set-up a fairly cheap alternative using the Raspberry Pi, a webcam and some open source software.

This isn’t the best security solution in the world but it’s definitely a fun project to get stuck in to and does work well for people looking for a simple security solution.

The end result will be a Raspberry Pi running Minibian (a lightweight version of Raspbian) and Motion – a command line based tool that detects and records motion. All of this will be hooked up to an everyday USB webcam that provides both a live stream in your browser of choice and snapshots/video recordings when motion is detected.

Hardware Needed:

  • Raspberry Pi (I used the B model, however B+ should work fine too)
  • USB Webcam
  • Ethernet cable (Wifi dongle can be used too but some additional set-up will be needed)
  • 5V power supply for Raspberry Pi
  • SD card for Raspberry Pi

Software Needed:

  • Minibian image for Raspberry Pi
  • Motion
  • SD Card Formatter
  • Win32DiskImager (assuming you are completing this tutorial on Windows)

So let’s dive straight into it…

 

Format SD Card

The first thing you need to do is format your SD card ready to install the the Minibian image onto it.

To do this I use SDFormatter. Simply choose the right drive letter for the SD card, click ‘Options’, change ‘Format Size Adjustment’ to on and set ‘Format Type’ to ‘Full (Erase)’.

SDFormatter | Transparent Communications

Then click format and wait for it to finish.

 

Download Minibian

Next you need to grab yourself a copy of the Minibian image ready to move over to your Rapsberry Pi.

MINIBIAN is a minimal Raspbian-based Linux image for Raspberry Pi.

The main focus is to have a small, updated and stable distribution that is fully compatible with official Raspbian “wheezy” image, without GUI and unneeded tools.

So this image is perfect for embedded projects, or wherever you need to use all RPi resources for your specific tasks.

(Taken from the Minibian About page)

It is perfectly possible to use other images if you please but I have chosen Minibian as it is nice and lightweight so most of the Raspberry Pi power can be focussed on the CCTV system itself.

You can find the Minibian image here.

 

Install the Minibian image of the SD card

Now you need to install the Minibian image onto your SD card. I will explain briefly how to do this on Windows with Win32DiskImager. If however you are on Linux here is a nice tutorial of how to write the image to the SD card or alternatively here is a quick tutorial for Mac users.

Install and open Win32DiskImager as an administrator (right click run as admin) and point it toward the Minibian image file. Then make sure that the correct drive letter is selected for your SD card. I’ve added an image below of the configuration to help.

Win32DiskImager | Transparent Communications

Once you’ve done this simply click the write button and wait for the success message.

 

D-Link Landing Page | Transparent Communications

 

Plug everything in and SSH into your Raspberry Pi

Once you have successfully written the Minibian image to your SD card it is now time to plug everything in, connect to your Raspberry Pi and start setting everything up, almost done!

So, attach the Ethernet cable, SD card, USB webcam and finally the power supply. Give it a second to boot up and then you can connect via SSH.

To connect to the Raspberry Pi we must first find the IP address of the machine. There are many ways to do this either through your router or through lucky guess work but to make things simple I usually just use the run only version of Advanced IP Scanner.

Next we are going to need Putty (if on Windows) to connect to the machine. After you have that installed simply add the IP address of your Raspberry Pi to the ‘Host Name (or IP Address)’ field (as shown below), then click open.

PuTTy | Raspberry Pi CCTV

In the above example you can see that my Raspberry Pi’s IP address is 192.168.1.7, yours may well be different.

Now all you need to do is type in the default username/password which is root/raspberry.

 

Resize the SD Card

Next we quickly need to resize the SD card so that as much space can be utilised as possible. Here is a link to an easy tutorial on how to get this done.

 

Time to update

Run the following to update the system:

apt-get update

 

Install and configure Motion

 

To install Motion run:

apt-get install motion

 

Edit /etc/default/motion and set “start_motion_daemon” to yes

nano /etc/default/motion

 

Find ‘start_motion_daemon’

start_motion_daemon yes

 

Now we need to configure Motion to do what we want.

nano /etc/motion/motion.config

This is a link to my configuration file if you want to use it as a template or of course you can use the default config and go from there.

If you do use my one as a template there are many settings that you might want to adjust for yourself. I will first let you know what this config file is set-up to do, then I’ll run you through the main settings that you may want to change.

This configuration is set-up to:

  • Take a snapshot and save it as a .jpeg every hour on the hour.
  • Record and save any detected motion as a video.
  • Make a time-lapse by taking an image every minute and saving it as a file per day.
  • Have a live stream that you can access locally in your browser at the Raspberry Pi IP address.

There is more to it than this but this covers the main purpose of the webcam. I’ve also edited the directory paths so that all of these are sectioned up into neat folders arranged by date (all of this is in the DD/MM/YYYY format so if you are not in an area that uses this format bear this in mind).

 

Make /media writable

All of the snapshots and videos are going to be saved in the /media directory so it is important to double check that the folder is writeable. To do this we use the following command:

chmod -R 755 /media

 

Edit config

Here are the main settings in the configuration files that you might want to play around with a little.

The width of recordings / live stream:

width 768

I’ve set this to 768 but that is entirely up to you.

The height of recordings / live stream:

height 576

Target directory:

The target directory for saving recordings. You may want to change this to be an external HDD or possibly a USB but do remember to double check the permissions of the new directory if you do decide to change it.

target_dir /media/

Maximum number of frames to be captured per second:

framerate 100

Amount of frames to capture before and after motion is detected:

pre_capture 2
post_capture 2

 

That’s about it for the main ones as everybody will want a different set-up. If you want to look into it some more here is a link giving you a comprehensive list of all the config options.

 

Set-up FTP

Finally, we want to set-up FTP access so that it is nice and simple to download and view all the videos/images on the Raspberry Pi.

Here is a very quick tutorial on how to do this and will get you up and running in no time at all.

 

Take a look at the webcam live stream

Looks like that is all for now. If you want to access the live stream of your webcam simply head over to your Raspberry Pi’s IP address using port 8081 (as defined in Motion’s config file). For example mine would be 192.168.1.7:8081.

 

A couple of handy links for further configuration:

Overclock your Raspberry Pi:

http://haydenjames.io/raspberry-pi-2-overclock/

Making a new user:

http://www.tecmint.com/add-users-in-linux/

Changing root’s default password:

http://www.wikihow.com/Change-the-Root-Password-in-Linux

And lastly, if you are looking for a more comprehensive but still greatly priced CCTV system with much less configuration then be sure to take a look through some of our great security packages.

If you need any help with this tutorial or have a general question feel free to comment below!

 

Tagged with:     , ,

About the author /


The guy in charge of many website type things at Transparent Communications - a leading supplier of IT, networking and audio-visual equipment.

Post your comments

Your email address will not be published. Required fields are marked *