This project was inspired by a project on makezine where they used a Particle Photon to open a garage door via an android/iphone app. I liked the idea and decided to give it a try. Once I got it working, I decided to make my own modifications. I ditched the app to use a web interface instead (found an example here). I found a few problems that I resolved, I think it worked in the makezine article because they were using the older spark core io chip.
First lets talke about the Photon that I used. It is a really cool little device that includes wifi and an online ide can be used to program the board. They use c++ style code with an extensive set of libraries. I am not a hardware guy so this was new to me and if I can figure it out, you can too.
Next lets talk about the hardware setup.
- Relay shield – $6.79 (another option would be a One Relay shield – $3.99)
- Particle Photon – $19+$5 shipping
- Wires – $6.99
- Mini Breadboards – $6.98 (6 pack)
- USB cord and 500mA DC converter (had them already)
- A couple of garage door openers and doors 🙂 (already had them)
Total cost: $6.79 + $24 + $6.99 + $6.98 = $45
depending on how you count the wires and breadboards it would really be closer to $32.
The pins used for the relay shield inputs are D0 and D3. The relay is hooked up to the vin and gnd on the photon and the doors are hooked up one to each realy on the relay shield. There are two reed switches (got them on ebay) that are used to check the state of the doors and they are hooked up to the 3v3 power and the D1 and D4 pins respectively.
(GE R4.7 Resistor Surface Mount Door Window Wireless Alarm Reed Switch)
Next we talk about the code. There are two different things you need to code to get this to work. First you need to setup the photon to read and write to all of these pins. That code can be found here. You’ll notice that the photon sets the reed switch pins to input_pulldown which allows for the digital read on the pin to determine the state of the doors. These will read as HIGH when the door is closed.
Now we go to the web interface:
This code can be found here.
In this code there are ajax calls to call the particle methods. You set your external calls inside the Spark.function calls to set the external name. You can see from the java script in the example above that there is a check for the sate of each door and the status box will indicate which doors are open not just that a door is open/closed.
I added a bit of extra code on the photon to check the state of the doors and if they are open in the middle of the night (we forgot to close them), they will close. I have also added a button on the bottom of the page to disable this functionality in case I am out in the garage at night and want them to remain open.
Again thanks for all those that put code and diagrams up on the web to help me come up with what you see here.
Enjoy the project!