Scared you've left the garage door open when you leave the house? Want to be notified of intruders when you're at work? How about a simple text or e-mail notification when someone enters a room, opens a safe full of valuables, or raids your private beer fridge?

Look no further! The Magnetic Door Spy system is exactly what you're looking for!

The Wi-Fi Magnetic Door Spy system is a an ESP8266 (arduino) board connected to a magnetic door sensor that constantly checks to see if the circuit (magnets) are closed. If they are, all is well. If not, it will fire off an alert to a cloud dashboard over your wireless network - which can be configured to send you a text, email, or a slew of other actions using the IFTTT platform.

This tutorial will walk you through the process of purchasing the parts you need, putting them together, uploading code to the board, then creating the alerts using Adafruit's IO Dashboard connected to IFTTT recipes.

Read on for details!


Original sketch code by Todd Treece @ Adafruit.com

Tweaked code & design by Josh King

Step 1: Materials Required

You will need the following to build a Magnetic Door Spy system:

  • Adafruit Huzzah ESP8266 Breakout Board - The brains of our project. (Link)
  • USB to TTL Serial Cable - Needed to communicate to the board. (Link)
  • Tiny Breadboard - What we'll plug everything into. (Link)
  • Magnetic Contact Switch - Sensor used to determine if something is open or closed. (Link)
  • 3.7V Lithium Ion Battery - I recommend a slightly bigger battery here. (Link)
  • Micro Lipo USB Charger - Used to charge/recharge our battery. (Link) (Or more expensive fancy one)
  • Some wire - Here's a good bundle if you don't have any. (Link)
  • 1M Ohm Resistors - needed for our design. (Link)
  • 220k Ohm Resistors - needed for our design. (Link)
  • Hammond Black Box - needed to enclose our design. (Link)
  • A soldering iron - One suited for electronics with an ST tip works best. (I use this one)
  • Rosin Core Solder - Just make sure it has rosin core/flux to prevent needless corrosion/oxidation. (Link)

While you technically don't NEED the following, I HIGHLY suggest you get these to make your life easier for this project (and most electronics projects in general):

  • Helping Hands - This will make your life a lot easier when soldering and connecting things (Cheap one) (Super fancy one)
  • Solder tip cleaning wire and holder - Makes it easy to brush off extra solder after every joint. Pretty cheap too. (Link)
  • Circuit Board Vise - I almost consider this a need, but not quite. Use this to make your life easier when soldering, wiring, or doing any kind of activity on your boards. (Link)
  • Solder Sucker - this makes it easy to remove excess solder or solder mistakes from boards. Super useful. (Link)
<p>I love it! Straight forward and simple!</p><p>I would love to have a notification when the door is closed again, can you help me with the code?</p><p>So basically what I would love to do is:</p><p>Keep it in deepsleep until the switch is interrupted.</p><p>As soon as the interruption is made, send the value to adafruit and ramp up the checking interval</p><p>As soon as the connection is closed again, send the changed value to adafruit and ramp down the checking interval to the initial one.</p><p>Can you help me with that? Thanks!</p>
<p>Hey there! To do what you're asking, you'll need to keep track of the state of the door. A de-bounce to drive that action would probably work. Here is a write-up on how something like that would work! CHEERS - and I'm so glad you like the project!<br>https://www.baldengineer.com/arduino-de-bounce-a-button-with-micros.html</p>
<p>Thanks!</p><p>I got it to work. Instead of De-bouncing, I am actually using the eeprom to write the last state (if the state has changed) and then compare the last state with the actual state. </p><p>This way I receive now a 0 if closed and a 1 if opened - but only, if it the value has changed.</p><p>Again, great and easy project, a perfect start to get into the ESP8266 board!</p>
<p>excellent! Wood you mind sharing your sketch or a copy paste of the code you used? I'm sure it would help others who want to accomplish this!</p>
<p>Of course!</p><p>Basically what it does is comparing the current door state with a previously stored one in the EEPROM.</p><p>To make sure the EEPROM is not written each and every time, it will only be written upon a change of the door state. </p><p>This is quick and dirty, but it works smooth. </p><p>I am actually using this to check if my vacuum cleaning robot has come back to his charging station. I do receive a text as soon as he starts his cleaning process and another one when he is back - sometimes he gets stuck under some furniture and that way I know if I need to look for him ;)</p><p>Thanks again for this!</p><p>Here ist the part of the code:</p><p>int door_status = EEPROM.read(5); // read out the saved value out of the EEPROM</p><p> if(digitalRead(PIN13) == LOW &amp;&amp; door_status == 1) </p><p> {</p><p> Serial.println(&quot;Door is closed.&quot;);</p><p> door_closed();</p><p> EEPROM.write(5, 0);</p><p> EEPROM.commit();</p><p> } </p><p> else if(digitalRead(PIN13) == HIGH &amp;&amp; door_status == 0) </p><p> {</p><p> // door is open so let's send something to Adafruit IO.</p><p> Serial.println(&quot;Door is open&quot;);</p><p> door_open();</p><p> EEPROM.write(5, 1);</p><p> EEPROM.commit();</p><p> } </p><p> else</p><p> // if nothing has changed, we do not do anything.</p><p> {</p><p> Serial.println(&quot;Nothing Changed.&quot;);</p><p> }</p><p> // we are done here. go back to sleep.</p><p> Serial.println(&quot;zzzz&quot;);</p><p> ESP.deepSleep(SLEEP_LENGTH * 1000000);</p>
<p>Thank you so much for sharing! :)</p>
A very nice instructable.
<p>Thank you sir! Glad you enjoyed :)</p>
<p>Hello, nice project. Do you know if any esp8266 compatible will work?</p><p>Any of these </p><p>http://www.banggood.com/search/esp8266/0-0-0-1-3-45-0-price-0-0_p-1.html?sortType=asc</p>
<p>Yes, any of them will work. Try and get one of the newer stand-alone boards though, not a shield (otherwise you'll need something like an arduino uno etc as well). <br><br>Also, make sure to adjust the pinouts appropriately. They are different on different models of boards. You will also need to possibly adjust the board type when using a non huzzah board.</p>
<p>WOW.</p><p>First, thank you for this quick reply.Is this one </p><p><a href="http://www.banggood.com/Geekcreit-Doit-NodeMcu-Lua-ESP8266-ESP-12E-WIFI-Development-Board-p-985891.html?rmmds=cart" rel="nofollow">http://www.banggood.com/Geekcreit-Doit-NodeMcu-Lua...</a> </p><p>a standalone? I think it is. I am newbie!</p><p>Second, I voted this project :) hope you win!! </p>
<p>Yup, that one will work! Thank you for voting that means a LOT to me! :)</p>
<p>Thank you! I really like this project!</p>
<p>Hey guys - if you're reading this tutorial and like it, please feel free to click the vote buttons! I'm trying really hard to win the IoT Builder competition in particular. I will use the prizes to continue making quality Instuctables like this one :) Thank you!</p>
<p>Thank you very much for the tip.</p>
<p>You're welcome! enjoy!</p>
<p>How long will it work on battery?</p>
<p>Depends on the battery size you use. Unfortunately it still uses about 20mA on transmit when waking from deep sleep, so it could be many months to a year or more if you use a battery big enough.</p>
<p>I'm concerned that the SSID, Username, and Password are not encrypted. </p>
<p>Hi there @RobertG179 - the traffic is firstly encrypted over your wifi - hopefully you're using WPA2. It is encrypted secondly by the IFTTT and Adafruit servers. Rest easy.</p>
<p>Good to know. I was a bit concerned after all the IoT vulnerabilities. </p>
<p>No problem - cheers!</p>
<p>Nice little tools and pics on how to do this. </p>
<p>Thanks glad you like it :)</p>
Very nice. Could be just what I need for the basis of a door/window monitoring system to protect my parrot from escapes. Do you think IFTTT could be used to send an alert only if a master door is opened? I'd like it to warn me when I open the birdcage door that e.g. a window is open that he could escape from. It doesn't need to alert me that a window is open when the birdcage is securely closed!
<p>You absolutely can use this for exactly that purpose. Good luck!</p>

About This Instructable




Bio: It's dark. You are likely to be eaten by a grue.
More by esper2142:PiE-Ink Name Badge The Super Easy Micropython ESP8266 Windows Guide. No Guesswork Required! Illuminated Arrow Pen 
Add instructable to: