Building a simple Door Alarm (28 Days of Hacking: Day 26)

Well I am officially three days behind schedule due to some projects and exams. I hope tonight I can knock out three new posts. The first of which is a door alarm. To do this, I am using a reed switch which is magnetically controlled. If there is a magnetic field, it will pull the switch closed, creating a short between the pins. That’s great, but we want a device that can alert us if someone has opened the door. Therefore, we need to track state and the easiest way to do this, in my opinion, is with a set reset latch. This gives us the ability to clear the fault.

We can use a circuit like the one shown below. There are many other ways to do this, but this was the first one that came to mind. The pulse is provided by the microcontroller the circuit interfaces. Using this design, we can reduce the sampling rate since the door state is persistent. From the software side, we can sample maybe once every 10 or 15 seconds and check Q, we can take some corrective action such as pushing an alert to my phone. Then we probably want to clear the fault, so we provide a short pulse to the reset pin on the homemade SR Latch. In this case, Q goes high when the door is closed, and low when it is open. Just tap the other side of the SR Latch for the opposite effect. My rationale for building it this way was in the event of a failure of the reed switch, which is pretty fragile, Q will remain low, making it detectable.

So let’s build and test it! I wired it up to a breadboard and used my eraser to test the reed switch. I will be putting it on a perforated board and hooking it up to a door for integration into the automation network I am building.

If we close the "door":

And if I move the magnet away, the state persists:

Now if I pulse the reset pin, the LED shuts back off.