Raspberry Pi Security System

Submitted by matty on Wed, 02/07/2018 - 00:22

I've taken an interest to Raspberry Pi and wanted to see if I could make a security system with one.  I wanted to start simple, one Pi with a video camera and motion sensor.  Starting out, I flashed the 32gb sd card with a copy of the Raspbian operating system, which is a Linux flavor of Debian.  I was pleased to see that there are many libraries for Raspberry Pi written for Python, one of my favorite programming languages.  Getting it set up was easy, it was pretty much plug and play for the camera libraries and motion sensor.  Then I just had to devise a way for it to record when someone walks by, and store/send images.  I will probably change the code completely with further experience coding for Raspberry Pi, but for now I have an end product that does what I want on a basic level.  The code can be viewed on my github repository here: https://github.com/pcrats33/spyer/blob/master/spyer.py

Certain configuration values, such as e-mail smtp server login credentials and where to send pictures to are stored in a separate file not followed by Git.  Also I was able to use a hashing encryption to store the password in another file.  If you wanted to use the code, just create the files where it reads the information, or hardcode those values.  Videos are created in 20 second chunks within a temporary directory and then moved to a captures directory.  This allows for another program to sync these videos to the cloud.  Whenever motion is first detected an e-mail is sent with a still picture capture.  The essence of the code is an infinite loop with delays that checks for motion and turns the camera on or off accordingly.  For future versions I plan to incorporate a phone interface so that I can turn it on/off remotely rather than with the power cord.  The script is ran in the /etc/rc.local script, so all that is needed is for the Pi to be plugged in and it will start the spy cam script.  I found working with the Raspberry Pi enjoyable and easy, and it inspires imagination to a myriad of projects well beyond a spy camera.