Make a Security System with a Raspberry Pi





From the moment I first read about the Raspberry Pi, I knew that I had to have one. For those of you who don’t know, the Raspberry Pi is a credit card sized computer capable of running Linux that sells from $25 to $35. The top model consists of a 700Mhz ARM processor with 512 MB of RAM. There is no hard drive on a Raspberry Pi. Instead, you install the OS onto a SD card. The incredible small size and price make the Raspberry Pi a delicious tool for small electronics projects.





Originally I used my Pi to run XBMC (an Apple TV/Roku Box alternative). However, I felt that I should be doing more with this incredible device. I did some brainstorming and came up with the idea to use my Pi, in conjunction with a cheap USB webcam, to make a Security System for my home.



The setup would consist of 4 camera's spread across the house, all being controlled by their own Raspberry Pi. These Pis’s would then send their stream over the WIFI to a base station. This base station would then collect the 4 streams and save them to a dedicated hard drive.





As I am writing this, I am about a third of the way through the project. Before I went any further, I figured I would share my progress. This way the system could be replicated by anyone else interested in this project. I realize not everyone is a Linux expert, so I will try and make this write up as straight forward as possible.



Let's start with the parts list. To start off you should have 1 Raspberry Pi, 1 SD Card, 1 webcam, 1 WIFI dongle, and a computer to act as a central hub/base station. In this tutorial I will be using a Mac, but a Linux box will work as well.





Once you have the necessary parts go ahead a visit this website and download the latest version of Raspbian. Raspbian is a flavor of Linux made specifically to run on the Raspberry Pi. Once downloaded, our next step is to open up Disk Utility and put the Raspbian image on the SD card.


As a side note, Disk Utility tends to act strange when you try to image an SD card. I received a slew of errors when I tried to do this for the first time. My recommendation would be to Google whatever errors you get. They tend to be common issues and therefore have a lot of online support.





Once the SD card has been loaded up, connect the Pi to ethernet, keyboard, mouse, and a monitor, Once that is complete plug in the power cable. Once the initial setup has been completed we will be able to remote into the Pi via SSH giving us the freedom to make the Pi mobile.





After a minute the pi should hopefully boot into the screen above. And this point you should change the default password as well as enable SSH. After you have finished you will be brought to the desktop of Raspbian. From there you should plug in your WIFI dongle and open up WIFI Config from the desktop.



Try to go through the setting and set up your WIFI dongle so that it connects to your local WIFI network. If you're like me, you have your network hidden by default. If this is the case, you probably won't be able to use this WIFI Config app. Instead, I found this trick to getting yourself connected to the network. First, open up the Terminal and type the following command.


sudo nano /etc/network/interfaces

This should open up the Interfaces document in Nano. From here make sure that the document is identical to the text below. Making sure of course to fill in your network SSID and password.


auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-scan-ssid 1
wpa-ap-scan 1
wpa-key-mgmt WPA-PSK
wpa-proto RSN WPA
wpa-pairwise CCMP TKIP
wpa-group CCMP TKIP
wpa-ssid "My Secret SSID"
wpa-psk "My SSID PSK"

iface default inet dhcp





At this point you should be able to restart your Pi and connect to the WIFI without any trouble. If not, Google whatever problems you are having. Again, there are plenty of resources out there to help you figure this part out. Once you have successfully connected to the WIFI, go to the Terminal and type this command to see what your current IP address is. We will need this in the next step.


/sbin/ifconfig


At this point you can unplug the keyboard, mouse, ethernet, and monitor as they will not be necessary anymore. From now on we will be using a separate computer to control the Pi. We can do this by making use of SSH. To get started open up the Terminal on either a Mac or Linux box. From there, type the following using the IP address of your Pi. You should then be prompted for the password that you assigned to the Pi after you first turned it on.



ssh "ip address"@raspberrypi




Once you've connected to the Pi you should see the following screen. At this point give your self a pat on the back because you're halfway done with Part 1. Next up we need to install some software that will let us stream are video feed over the network. Initially I chose to use some software called M-JPG Streamer (a free download). However I decided later that it would be much easier to use a program called Motion. Motion is also a free download and is much easier to setup. It also allows for your security camera to have a motion-detecting feature. But we’ll get to that more in part two. To download Motion, enter the following commands into the terminal.


cd~

sudo apt-get install -y motion



Motion works off of a config file that tells the program how it should behave. There are two settings right off the bat that we will want to change. To get to the config file, type the following.



cd /etc/motion

sudo nano motion.conf



From here go ahead and find the line that refers to Daemon and change it from OFF to ON. Then go to the line that says webcam_localhost = ON and switch that to OFF. Finally you'll want to go to a separate file and change one last line. In the file found below, find the line that "start_motion_daemon" and switch it to "yes"



cd /etc/default



At this point we are ready to start the Webcam Server. Once started, the video stream will be available by going to your PI's IP address in a web browser. The code to start the server is as follows. When the server is successfully up ad running your screen should look similar to the one above.


sudo service motion start"






At this point open up your favorite web browser and go to (http://"the Pi's IP address":8080/?action=stream). This should bring up a website that will allow you to view your stream live. And that’s it! You should now be able to put the webcam anywhere in the house and stream the video live to a computer. The next step is to write a program to automate the activity as well as record the feed. I will post the second part of the project as soon as I finish. Feel free to email me any comments, questions, or suggestions.




Newer Posts