Overview

One of the things I've noticed about home security systems is how expensive they are! The monetization model for home security is to not worry about making money on the hardware but sell the monitoring service at high rates. This is needed to support call centers for monitoring all the devices on a 24x7 basis. I'd love to have an alarm system, but they're prohibitively expensive. We Makers can certainly do better!

The goal of the system is to detect doors or windows opening. If you don't expect the door or window to open, you know something is up. This tutorial only talks about the door/window sensors and the alarm sequence. There are all kinds of things you can add to this alarm system once you have it constructed: smoke/fire sensors, carbon monoxide detectors, and security cameras, to name a few.

Here's the design for the sytem:

Now, here's how it works. The reed switch (Adafruit product ID 375) is a normally open switch. This means that when the magnet is not close to the wired switch there's no connection between the two wires. When the magnet is close to the wired switch the switch closes and current can flow.

There is one analog pin on the ESP8266, whether it's the Feather, the breakout, or some other ESP8266-based device. The input voltage on that pin is one volt, maximum. Since the Feather provides 3.3v, we need a voltage divider to limit the input voltage to the 0-1 volt range.

The analog pin, which is connected to an analog-to-digital converter, will see a value of one volt when the door or window is closed. This means it reads 1024. When the door or window is opened, the voltage will drop to something "close to" zero, modulo the natural float fluctuation in the line. This means the digital reading on the line will be something less than 50.

There's a timer set on the ESP8266 that wakes up every second and reads the analog pin. It's already connected to the wireless network (the file init.lua does that for us - more on that later) so we don't have to worry about managing the connection. It opens a connection to a local MQTT broker running on a Raspberry Pi 3 that's also on the local network. It inserts the sensor ID and the analog pin reading into the MQTT topic queue. 

Then there is a Python program running on the same Raspberry Pi. It subscribes to the alarms topic on the MQTT broker and reads the sensor IDs and ADC values. This is the program that actually keeps track of the current state of each sensor in order to detect state changes. When the door or window goes from open to closed, it generates an "INFO" event. When the door or window goes from closed to open, however, the program generates an "ALARM" message. Where does that message go? Why, into an Adafruit.IO text feed, of course! This gets the alarm message out of the local network and into the cloud where it can be processed by other systems.

Finally, there's an If This Then That (IFTTT) recipe that looks for ALARM events in the Adafruit.IO topic queue. When it sees one, it texts the alarm message to the pre-configured phone number (which happens to be my cell phone).

Putting it all together, when a door or window opens I get a text on my phone and iWatch that tells me which door/window has opened. If it's not expected, I can take appropriate action.

Next: What You'll Need

Last updated on 2016-06-23 at 07.36.22 AM Published on 2016-06-23 at 10.55.31 PM