Sentry - Raspberry PI home monitor

This is a project I have been working on during my spare time. Sentry is a home security box (and software written in Python) I built to monitor our apartment, at least in theory. In practice it was an excuse to learn a bit more about electronics on the hardware side.

What you'll need

The required gear:

  • Raspberry PI. I used the model B+, but I think any model would do.
  • Raspberry PI camera. With or without the filter, doesn't really matter. I you want to add some infrared LEDs you could make the camera see in the dark!
  • Magnetic sensor. You could use any kind of sensor really, but I opted for something reliable.
  • Two buttons. For controlling the unit. Momentary.
  • Two LEDs. For displaying status. I actually opted for these buttons that included LEDs.
  • Resistors. I used 2 x 1k Ω and 2 x 10k Ω.
  • Sentry software. You can find the Sentry software hosted on GitHub. If you have a working knowledge of Git it's highly recommended to clone the repository. Sentry uses the RPIO library by Chris Hager. This library replaces the official RPI Python library. You can install it manually on the PI or use a virtual environment.

Optional gear:

  • Raspberry PI case. Not required if you just want to experiment, but recommend if you want to install the unit permanently. Since my buttons were quite large I had to go for an expandable case.
  • Network connection. Either Ethernet cable or a tiny WIFI USB card.
  • Prototyping board. I highly recommending using one of these to make sure everything works as expected before starting with soldering. It's really cheap and worth the extra time.
  • Perma-proto board. Definitely not needed, but makes it very easy to transfer you prototype to a permanent state. I found it very useful.

Hardware schematic

The hardware setup for this project is really simple. Just two LEDs, two buttons and the magnetic sensor needs to be hooked up. Below you will find the wire schematic.

Wiring diagram

Ports with hash tagged values (e.g. #23) denotes GPIO ports on the Raspberry PI. Note that this is only the default ports, you can reconfigure to your own liking. Resistor values for the LEDs can of course be changed if you desire other light intensities.

Breadboarding

Before starting to solder I found it incredibly useful to use a temporary board (or "breadboard") to make a working prototype. Here's what it looked like all wired up. Note the buttons I used has 4 connections, two for the button and two for the built in LED.

Proto board setup.

Not the neatest wiring job in the world, but it worked!

Software

Once you have the prototype wired up, it's time to test the software. Make sure you have installed RPIO and downloaded Sentry on the PI. Start the sentry application by

> sudo python src/sentry.py

By default, access to the PIs GPIO ports are restricted, so you'll need to run the application as super user, or alternatively change the access privileges for the GPIO interface in /dev.

Sentry uses configuration files, and the GPIO ports are fully customizable. You can set all ports in sentry.config in the io block.

"io" : {
        "enabled": 1,
        "magnetic_pin": 23,
        "on_button_pin": 18,
        "off_button_pin": 17,
        "on_led_pin": 12,
        "off_led_pin": 5
},

Change the ports to reflect you own setup. Many other parts of Sentry is configurable, see the documentation on GitHub or readme.md. If you are unsure about the hardware setup you can also use RPIOs rpio-curses in order to verify the ports are getting correct signals.

For Sentry you should also enable debugging output by setting debug in the logging category to 1. This will give you valuable clues if anything is not working.

Finalizing the build

Once you are satisfied the hardware works as desired, it's time to make you prototype permanent. I used a Perma-Proto board, which is a board with similar layout as the breadboard, which simplifies transferring you prototype.

The finished perma proto board.

I used the modular board from ModMyPI, and drilled holes in the lid for the buttons and camera.

Breakdown of the modular case.

Here's the final assembled build.

Case assembled

That's it. Please let me know if you like the project or have any problems with the software. I'm new at the hardware thing, and Python is definitely not my primary programming language so there's bound to be issues.