Introduction: IoT Garage Door V2
A year or so ago, I hacked a Belkin WeMo switch and coupled the WIFI board to an Arduino Uno along with a little code and sensors to create a way to control my garage door. The system worked well as I could not only control the door, but I could see the door's state in the WeMo App on my iPhone. The only problems were that the parts were fairly expensive ($50 for the WeMo and $20 for the Arduino + sensors) and the sensors (magnetic reed relay or hall effect) were difficult to install reliably in the garage.
So I set out to simplify the design. I wanted to reduce the price and also make the installation something a typical homeowner might be able to do.
The new design uses an internet development chip/system called the Particle Photon. The system is essentially an arduino type processor coupled to a WIFI chip on a single board the size of a couple of postage stamps. The Photon is just $20 compared to $70 for the first design.
(the image shows both the v1 and v2 systems on the same breadboard - v1 is on the right, v2 on the left)
But the real chore with the first system was installation. Mounting sensors for "door open" and "door closed" was a pain. Drilling, screw, mounting, running wires across the garage, etc. And the reliability of the reed sensors was not great as their tolerance for working properly was just a few millimeters.
So I looked into proximity sensors. I tried some ultrasonic ones but they were fairly expensive. They worked just fine but the price point was a bit high. I settled on an IR sensor made by Sharp. It runs about $14 from Sparkfun for a single unit which is not bad. So in total parts we are down to $34 and a much simpler design as the IR sensor can be co-located with the Photon CPU/WIFI chip cutting down on the garage wiring. And the IR sensor does not need anywhere near the same exacting alignment as the reed or hall effect sensors do.
Step 1: What to Buy
- Particle Photon (w/ headers) $19: https://www.sparkfun.com/products/13774
- Sharp IR Proximity Sensor: $14: https://www.sparkfun.com/products/242
- 5V Buzzer (opt. - makes beep before the door moves) $2: https://www.sparkfun.com/products/7950
- NPN Transistor TO-220 package <$1: available all over the place
You can use a Relay instead $2: https://www.sparkfun.com/products/100
- Resistor <$0.50: a couple of hundred ohms is good.
- Jumper Wires, breadboard, 5V USB or other power supply with USB Micro cable (>500ma)
- ~50 ft of Garage Door (or any) two pair wire for connecting your system to the two contacts that make the door actuate
Step 2: Circuit Diagram and Explanation
The main system is comprised of the parts in blue in the diagram. The Photon and the IR Proximity Sensor. The proximity sensor gets power (5V and Ground) and its analog signal out goes to pin A0 on the Photon. The D0 output of the Photon is used to simulate a button press for your garage door motor. It connects to the base of the NPN transistor through a ~200 ohm resistor. The emitter is tied to ground along with one contact of the garage door actuator contacts. The collector is connected to the other garage door actuator contact and left to float until D0 goes high and drives the transistor on for 800ms pulling the collector to ground which simulates a button press to the garage door.
If you choose to implement a buzzer (a good idea for garage doors that move on their own!) then the buzzer is connected to ground (negative lead) and the positive lead is connected to D1 on the Photon.
Note: you could also add a bright LED that could flash on/off with the buzzer for situations where sound is not enough to warn people that the door is about to move. This may require another NPN transistor to drive a high power LED much like the U1 transistor drives the garage door contacts (similar circuit).
PS: The diagram seems to show lines going off the left edge. Don't worry about that. I had another system hooked up to this. And you can leave off the Diodes (D1 and D4) as they are not needed since we are building just one system here.
Step 3: Mounting Location Considerations
1. Choose a mounting location which will provide a reliable difference in proximity measurements when the garage is open vs closed.
2. The best location is one that will tell you definitively that the door is all the way closed vs partly closed.
I choose a location above the door near the opening of the garage - just above the big spring. This location will show the door as being very close to the proximity sensor when fully open or any part of partially open. The only time the proximity sensor will show a reading of "far away" is when the door is all the way closed (the top of the door will clear the sensor when the door closes all the way). There are likely other places you can mount it like off to the side, but I like the top front position.
Step 4: Code for Photon
The code for the Photon is fairly simple and is available on github.
1. Initialize the system by reading the IR Sensor several times and averaging the result. Move the door. Read the IR sensor several more times and again average the result. Then take the first set of readings and average with the second set to yield the open/close threshold. A reading above that indicates that the door is close to the sensor (which in my mounting location means the door is open). A reading below indicates the door is far away (or closed in my case).
2. Run a loop that looks at the state of the IR Sensor. If a change in Door State occurs (door was open and is now closed or visa-versa), Publish an Event to the Particle Cloud system. IFTTT can see the event and with the right IFTTT recipe (more on that later) an IOS Push Notification can tell you the door just opened or closed.
3. The Tell function listens for commands from the Particle Cloud. Currently I have a number of commands defined for the Tell function including TOGGLE, OPEN and CLOSE as well as CHECK STATUS. These functions can be called easily from IFTTT using the DO button App (more on that later) or via a standard IFTTT recipe that could CLOSE the door at 11pm at night or open/close as you come and go via geofence triggers.
- Open will open the door. If the door is already open, this command is ignored
- Close will close the door. If the door is already closed, this command is ignored
- Toggle will change the door state - If open, it will close and visa versa
- Status will check the status of the door and publish an event to the particle cloud as to whether the door is open or closed.
Step 5: IFTTT Recipies for Notifications
The IFTTT App on your mobile device can be configured in many ways.
1. The most important recipe to created is the one that publishes IOS Notifications (or Android) so that you can see when the door changes from OPEN to CLOSED or CLOSED to OPEN. I called by IFTTT recipe "DoorStatus" and you can see screenshot for how you configure the recipe.
2. Another recipe I like to use is using the IOS Geofence to trigger the door to open or close. A picture of my recipe (well, with a different address) is shown for reference. You would need one for leaving your house and likely another for arriving home. A suggestion is to set the leaving geofence to be a little bigger circle than the arriving to prevent issues when you walk the dog near your house and the door going up and down a bunch :-)
3. Lastly, another idea for IFTTT recipes is to automatically close the door at 11pm. My recipe is shown above for this as well.
There are many other options as well. For example, instead of closing the door when you leave home, you could use the Life360 App channel in IFTTT to only close the door when the LAST PERSON leaves home. And likely many others. Feel free to share your ideas in the comments.
Step 6: DO (IFTTT) App Recipies
IFTTT released the "DO" App for IOS and Android in 2015. Basically it is IFTTT but simplifies things to be more like an App or Button. I use DO to TELL the garage door to do things - like OPEN, CLOSE, or TOGGLE. To be honest, I rarely use these recipes as my geofence mostly handles the door automatically for me.
But one recipe in the DO App is important and that is the CHECK command which tells your Particle to check the status of the door and publish the status as an event. Using this you can check the status of the door (open or closed) whenever you want.
We have a be nice policy.
Please be positive and constructive.