$10 DIY Wifi Door Sensor
SimpleIOThings is the easiest and cheapest way to build DIY IoT projects with no coding or soldering required!
This tutorial will teach you how to build a Wifi Door Sensor for about $10 dollars. You won’t have to code anything, and you won’t have to solder or buy expensive electronics equipment. Any services you are asked to use will be 100% free. Its that easy. Lets get started!
Some doors are meant to stay closed. For example your freezer door needs to stay closed to keep your energy bills down. Pet owners need to keep the door closed so their four-legged/winged companions don’t wander outside. Whatever door you need to keep an eye on, a wifi enabled door sensor can help you send a smartphone notification, SMS, email, and even an automated phone call when its been open too long.
The cool thing is, you can build one of these for about 10 dollars. I know you’ve seen these types of tutorials on the internet before, and usually they say something like, just buy a breadboard, soldering iron, breakout board, serial adapter, etc. etc. and after you’ve spent about $50 dollars you can build a cheap Internet of Things (IoT) device. Well, sorry internet. We nerds sometimes forget that most people don’t really have these things lying around. That’s why I built this website around the idea that IoT devices can be built without coding knowledge, soldering, or complicated prototyping.
Its a good idea to buy your parts first because on the sites where the merchandise is cheapest (Ebay or Aliexpress) shipping times are rather lengthy. Depending on where you live in the world, it might take some time for your components to reach you so its better to do this sooner in the process than later. Here’s a list of things needed for this project. FYI, I’ve included some affiliate links to the cheaper places you could buy these components. I’ve done my best to ensure the ads display the lowest price goods that are relevant to this project, and if you buy through them you’ll be helping me maintain this site. Thanks! 😉
(FYI, if you’re just seeing text below with no images, its probably because you have an adblocker on. I know ads suck, but in this case they were actually a creative way to continuously update the page with the lowest cost parts. Prices change, so if I used static links and pics, the link would quickly become outdated. Please consider turning off adblock for this site for the best experience.)
ESP8266 Development Board (~$3 @ AliExpress; Nov 2017)
AliExpress.com ESP8266 Development Board
MC-38 Sensor (~$2 for 1 sensor, less if you buy in bulk; Nov 2015)
These are tools recommended to build the IoT device in this tutorial.
Great. Now like I said, its gonna take a while for your stuff to get to you, so in the meantime lets setup some digital infrastructure that we can use once your stuff arrives.
Note: This is our third tutorial! You should be noticing a pattern by now, which is that steps 2 – 4 are pretty much the same for every device. If you already know how to do all the basic stuff, skip to step 5, where I start to talk about some stuff specific to this project.
STEP 2: Setup Your IFTTT Account & Recipes
The Wifi Door Sensor, and all of the devices on SimpleIOThings, uses a service called If This Then That (IFTTT). You can find a full tutorial on how to sign up and configure digital communications for your IoT devices in the Getting Started: Setup IFTTT post. Once you completed it, you should have completed the following:
- Signed up for an IFTTT account
- Downloaded the IFTTT App
- Connected to the Maker Channel
- Recorded your Maker Key
- Organized Maker Events (Triggers) that lead to IFTTT Actions.
Okay! We’ve got some really nifty digital infrastructure setup for your project. Soooooo…its gonna take a while before you get all this stuff…so its probably best to bookmark this page and come back after it’s all arrived. See you in a few weeks!
Oh hi there! Welcome back. I know its been a while. Maybe the seasons changed in your part of the world. Governments may have risen, switched hands, entered alliances, broken alliances, fallen, and then risen again. Yea…it takes a while to get your stuff. But now that it’s here, lets start building!
You can find a full tutorial on how to load firmware onto your ESP8266 Development Board on the Getting Started: Setup ESP8266 Dev Board post. After you’re done with this tutorial you should have completed the following.
- Connect your ESP8266 Dev Board and Install Drivers
- Load Firmware onto Dev Board using ESP8266Flasher.exe.
- Connect to Dev Board using LuaLoader.
STEP 4: Install Sensor Specific Software to your Dev Board
Great! Now your dev board speaks Lua and its ready to start communicating with the world and run programs. Now it just needs specific instructions or programs to be useful for your specific use case. Lucky for you, I’ve already written the programs needed to get your device up and running. Full instructions on how to program your device with specific settings for your use case can be found on the Getting Started: Loading Device Software Via LuaLoader tutorial page. In this tutorial you should have completed the following:
- Download the latest SimpleIOThings.zip file from the Downloads page.
- Extracted the zip file and run the SensorSetup.bat file.
- Input your information into the command prompt to enter user and device specific information (IFTTT Maker Key, the Maker Event name, the device’s location info, etc).
- Entered “2” for the Sensor Type Number, identifying this sensor as a “continuous read” sensor (i.e. one that reads the sensor’s current state, and triggers an alert if a specific state [like an open door] is detected for more than a threshold determined number of seconds).
- Enter input thresholds, input timeouts, and interval between notifications as prompted.
- Uploaded device specific files to your ESP8266 Development Board using LuaLoader.
- Set the Wifi Network Name and Password for your ESP8266 Development Board.
All the way back in step 1, we talked about gathering materials. Now that you have everything in hand and your board is programmed, get all your materials together in one space.
Some suggestions on how to mod your enclosure can be found here at Getting Started (5): Modding Your Enclosure. After completing this tutorial you should have completed the following:
- Created an opening in the rear of the enclosure for the microusb power cable.
- Created an opening in the front of the enclosure for the jumper wires.
Now go ahead and unplug your dev board (there is almost no electrical danger to you from touching the dev board while plugged in, but might as well err on the side of safety).
Grab your two jumper wires. You can see that at the end of each wire is a plastic housing covering some metal. We’re gonna remove that plastic housing. Grab a needle or safety pin, and find a small tab in the plastic housing. Lift up on the plastic tab. Once lifted up, you should be able to smoothly remove the wire from the plastic housing.
Now, grab the MC38 sensor that you bought. Note that there are two halves to it. The side with the wires is the actual sensor, while the side without wires is actually just an enclosed magnet. The sensor half contains something known as a reed switch. A reed switch is either normally open or normally closed, and when it comes in range of a magnet, the switch inside will close or open to break or create a circuit.
Okay, so grab the sensor, and then note that the exposed wires. If the wires aren’t exposed, you’ll need to strip off some of the wire insulation. Once you’ve removed the jumper wire housings, and grabbed the MC38 sensor wires, the ends of the four wires should look like this.
One of the guarantees I make at the beginning of each tutorial is that the project won’t require any soldering. Since we have to connect these female jumper wires to these exposed sensor wires, we’re gonna use a technique called “crimping.” Crimping is a way to join wires by using a pliable metal housing that you can compress with pliers to create a firm connection.
Insert your exposed sensor wire end into the remaining metal housing end (the part that was under your plastic housing. It should look like this:
Once the wire is fully inserted, use your pliers to “crimp” down on the metal housing, but not that hard! Hard enough to bend the metal to create a good connection, but not so hard it cuts through the metal housing and the wire. It should look like this:
Once your wires are successfully crimped, we also want to make sure that the two metal housings on separate wires do not touch one another. To do this, use duct tape or scotch tape to insulate your exposed wires.
Now grab your dev board, and observe the names of the pins on the board. Go ahead and plug your jumper wires into the “GND” and “D2” pins on the right hand side. It should look like this:
Everything should now look like this:
Just a quick note for those of you who are interested in the electronics. When setup this way the door sensor, when opened, is acting as a bridge between the D2 pin and the electric ground (-). That way when the magnet is pulled away from the sensor, it grounds the D2 pin, registering a change in electrical signal which the chip detects as a sensor input. Pretty cool! Great, the electronics are all setup. Pretty simple right?
Alright, now you can put your electronics into the enclosure. Plug your usb cable into the dev board, and make sure your jumper wires are well positioned before you close the project box.
And we’re done!
Your sensor should now be fully operational. Give it a test run by separating and it should trigger whatever you’ve set it up to do, whether that’s a smartphone notification, SMS, phone call, email, etc.
I installed mine on my fridge. Every once and a while I position my frozen foods poorly. This pushes open the fridge door, everything in my fridge ends up thawing overnight. I built this sensor to tell me when my fridge door is open too long, but you can use it for your front door, a window, etc.
I hope you enjoyed building a super simple Internet of Things device. Hopefully you will be able to use it for something useful, or use it to do something fun. If you enjoyed this tutorial, consider donating at the link below. Thanks for reading!