DIY Door Alarm With Text Alerts
by KJMagnetics in Circuits > Raspberry Pi
4165 Views, 17 Favorites, 0 Comments
DIY Door Alarm With Text Alerts
Make your own door/window alarm with some simple electronics, magnets and Raspberry Pi. The Raspberry Pi is used to text or email you when the door is opened!
Materials Needed (links included):
Raspberry Pi (here is the kit we used)
Neodymium Magnet - We use a 3/8" x 3/8" x 1/2"
Random length of wire
Make the Sensor
The first step is easy. Simply put the reed switch leads into a small breadboard, mounted to the inside frame of a door or window.
A reed switch is a magnetically activated switch. The distance at which it is activated depends on the switch specs and size of the magnet. It might take some testing to get it right. You want the switch to be closed when the door is closed.
Next, glue or tape the neodymium magnet near the switch. The magnetization direction of the magnet must be parallel to the switch.
Make the Alarm
Now that we have a working, no-contact sensor setup, we can use a Raspberry Pi to create an alarm. The Pi monitors the condition of the reed switch and notifies us whenever the door opens.
You can find great Raspberry Pi instructions online, but here is a summary of what we did:
We hooked up the Pi like a PC to check if it works. We plugged in:
- A power cable, into the tiny connector marked "Power In"
- A display cable from the HDMI port into a monitor
- A keyboard and mouse into the two USB ports
- A 8GB microSD card with the Raspberry Pi NOOBs Full Desktop distribution.
We used VNC viewer to connect the Pi remotely from our desktop PC. That way, we didn't need a keyboard, mouse, and monitor wired up to it. We were able to simply power the Pi and mount it.
Hookup Diagram
The Pi is powered into a nearby wall outlet. It's also connected with a 40-pin GPIO cable (included in the kit we linked earlier).
The reed switch is connected to the breadboard and to the Pi as shown in the wiring diagram. We also attached the buzzer to make a sound with the door is open.
Make the Pi Email or Text You
We then created a Python Script that runs continuously on the Raspberry Pi, monitoring the door. We set it up to start the script automatically whenever the Pi boots up. That way it's not effected by a power outage!
You can download a copy of the script here.
When running, the script checks the status of the reed switch roughly 5 times per second. When the door opens, it emails an alert and sounds the buzzer. It keeps buzzing until the door closes.
The alert sends a text message or email to whatever address we specify. (see video)
Short Video of How It Works
Check out the video to see it in action! This is a relatively simple and fun project. It can be used as a DIY alarm system for other things too--like if the float on your sump pump is rising, you'll get an email saying there is water in your basement!