Raspberry Pi 2 Security System

Last week I got myself a Raspberry Pi 2, the credit-card sized computer-on-a-card that can run a number of operating systems and comes with a 900MHz CPU, 1GB RAM, Ethernet port, HDMI output, 4 USB sockets… it’s an amazing little gadget.

You can install a number of different operating systems on it via a MicroSD memory card which essentially takes the place of a hard drive. There’s a version of Debian Linux designed for the Raspi 2 called Raspbian which is pretty easy to install.

My first project idea was to make myself a little security camera for my apaprtment. It would be able to detect when I wasnt in the room, and automatically activate a motion sensing app that would use the external camera I bought for the Raspi to take photos/video of motion that occurred, upload that to Dropbox and notify me by email.

A lot of the scripts that other people have developed to handle the various aspects of this project were written in Python, so once I had the OS and devices, drivers etc installed that’s what I had to install next.

My Raspi 2 came with:

– Spy Cam
– Wifi USB Dongle
– Bluetooth Dongle
– 32GB MicroSD card

My first stop was setting up Python and OpenCV following this excellent tutorial: Basic motion detection and tracking with Python and OpenCV

Followed by this tutorial, which carries on from the first and develops a motion detection script: Home surveillance and motion detection with the Raspberry Pi, Python, OpenCV, and Dropbox

I also use this Dropbox Uploader BASH script to sync the contents of a folder on my PI’s desktop to my Dropbox folder: Dropbox-Uploader

This is because Adrian’s Python home surveillance script requires you to authenticate with Dropbox every time you run it, the BASH script doesnt.

The next piece of the puzzle was geofencing. This article Raspberry Pi Bluetooth In/Out Board or “Who’s Home” shows you how to detect your mobile phoe via Bluetooth and then poll it every 60 seconds to see whether it’s still in range or not.

Once I’ve combined all of these scripts into one what I should have is a script that detects my phone and stays connected to it, and when I leave the area it starts the motion detector script. If movement is detected, I will be emailed and the images of whatever caused the movement uploaded to Dropbox for me to see (I am keen to see if I can notify myself more directly than via email, perhaps a tweet?). Once I re-enter the vicinity, the motion detection script is stopped.

Of course this is a project that you almost dont want to see work – the joy of it all working and delivering an alert to me will of course be overridden by the fact some intruder set it off!

Once I have the whole system cobbled together and working I’ll post the code for anyone who’s interested.