Perhaps the most significant part of my automation system is the security suite that I have built. What stated as an LED that turns on when my door is opened has now tuned into a fully functioning alarm that takes pictures, makes noises and even emails me! Accompanying this is the RFID card reader and a key switch for dead-locking the system.
Everything is controlled and detected through the Raspberry Pi's GPIO Pins with a combination of the built in SPI and I2C interfaces as well as standard GPIO inputs and outputs. Below is the most recent 'pinout' of the Pi which shows everything that is currently connected.
Being somewhat organized I have made some custom jumper wires to go from the Pi to box outside my room so that I can easily plug and unplug connections as required. This is achieved through the use an Ethernet cable as well as a telephone (power) wire. All of these run round underneath my carpet to the door of my room and give me a total of 18 wires to use. The Ethernet cable was bought as a spool of 50m (150ft) so that I could just cut it to the required length and solder some terminals on the end. I am currently in the process of crimping RJ45 Jacks to the ends of the cables so that the system can be more modular and I can connect/disconnect everything more easily.
As you can see, some of the wiring is still quite messy however throughout the process of making everything more modular it should clear up a bit and be more elegant to see! All of the hardware is in a 'box' of my bookshelf which is in the corner of my room meaning that it allows pretty easy access for when I need to add more to the system or more often than not fix something that I have broken. Usually I will only have the server running when I am at home unless I am showing what it can do to someone else and I need remote access to it. Although I do have the full security system that can alert me whenever someone comes in, it is more of a proof of concept and a demonstration that I am in fact able to build such systems.
So onto the Security System and how it works... Outside my room a project box is mounted on an old speaker stand and this houses all of the circuitry for for RFID reader and the I2C IO expander. This is connected to the Pi, as mentioned before, with the use of an Ethernet cable and a telephone cable too.
There is a program that is constantly running in the background to check the status of the door (Is it opened or closed), checking if there is an RFID card being swiped, if the system is armed or not, if the system is paused or not etc. This program is mostly made up of interrupts, functions and methods and really needs to be tidied up soon as I add more and more too it. None-the-less the code works well and the program starts just after the system boots meaning that it is always running. In addition to this it will not play any sounds however if the time is after 23:00 as this would just get annoying after a while and usually the system is off at this point anyway.
How It Works
As you can see the program is quite long for what it is actually doing, coming in at just over 400 lines of code, however it ended up this long as I tried to make it as modular as possible for the ease of debugging when things go wrong and for adding to/updating its features in the future. As I tend to add small parts to the program I occasionally have to go through the entirety of the code to clean up any global variables and unused lines that I have been too lazy to remove before. The program does work however and only tends to crash if the RFID reader is not connected for some reason or if the Pi cannot communicate with the I2C IO expander. In the future I intend to simply wrap all of the code that could go wrong in "Try" and "Except" blocks so that if something doesn't work then there can be contingency plans in place so that it can keep running without too much interference or disruption.
Check back soon for more updates....