Have you ever left your house and wondered "Will someone try to break in while I'm away?" This project will alert you if someone opens a door by using ultrasonic distance measuring.
Building the DeviceI was one of the lucky few who received a free Sparkfun ESP8266 Thing Dev Board by submitting my idea for the Cayenne IoT contest.
I started by connecting the HC-SR04 module to the ESP8266 Thing. The trigger pin connects to pin 12 and the echo pin connects to pin 13. Connect VCC and GND accordingly. It is optional to instead use a lithium ion battery and charger to power the device instead of a micro usb cable, but if you're gone more than 3 hours it will lose power. Connect an LED to pin 4 to see if it's armed.
In order to use this project as an alert device I used the Cayenne service from MyDevices. To get started, I created an account for Cayenne. Next, I clicked "New Device" and selected the ESP8266 as the board type. I named the device "Door Monitor" and copy/pasted the credentials into my code. For the alert to work there needs to be a widget that monitors a channel and triggers whenever it goes above a threshold. I selected "Add New" -> "Device/Widget" -> "Custom Widgets" -> "Value". I named it "Distance" and then set the device to "Door Monitor". The data type is proximity, with the unit being centimeters. The channel number I set is 1. After setting it up I selected "Add Widget".
So now I had a way to measure and report distance, but how about arming and disarming the alarm. You wouldn't want a text every time you came inside your house. That's where a toggle switch comes into play. Select "Add New" -> "Device/Widget" -> "Custom Widgets" -> "Button". I set the name as "Toggle", the device "Door Monitor", data type as "Digital Actuator", unit as "Digital (0/1)", channel as 2, and the icon as a padlock. Lastly, I added the widget to my dashboard.
Now it is time to create a custom trigger that will text you whenever the door is open. Click on the settings wheel on the toggle widget and select "Trigger". Name the new trigger anything you like. I named mine "Alert Me". Drag over the Door Monitor device from the left into the "If" box, and then select the distance widget to check. Measure from the door to where the device will be in cm and select "Sensor below" and then that distance. Now if the door opens and a person comes through it will shorten the distance. Feel free to adjust this number if needed. Click "setup notification" and check "Send Text Message". Enter in your phone number into the box. Lastly, click "Save" on the bottom right corner.
Using ItThe device is finished! To use it, simply copy/paste in your credentials into the included code file, along with WiFi information. Clicking the toggle button on the Cayenne dashboard should arm/disarm the alarm. Arm it whenever you leave the house and disarm it right before you enter back in.
Comments