Garage Door Project

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.

 

IMG_20151016_090117

Parts list:

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.

s-l1600
(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:

Capture

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!

 

Published by

Kyle

I am a software developer that likes tinkering in the garage. I hope you like my projects and have fun reproducing them.

21 thoughts on “Garage Door Project”

  1. Nice writeup! Could you add some more information about the sensor which detects if the door is open or closed? Which sensor is it, where did you put it and if its reliable. Also, are you having any problems with power surges? Read that some people have their gate open when the power comes back on. Thanks!

    1. I am using these reed switches http://www.ebay.com/itm/160658469146?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT (updated the article with picture and description). They are very reliable and I put them at the top of the door.

      I have not had any problems with power surges or the doors opening on their own yet, and I have been running it for a few weeks now. The door does open if there is a power outage when the power comes back on, this is due to how the relays cycle when the photon is turned on, but in my code, I have added a check after the board boots to close the doors if they are open. It is in the code that I have posted. I know it is a bit of a workaround, but it works for now.

      Hope this helps.

    1. I guess I don’t understand the bridging of the relays. I thought it was maybe to spread the load of the current across the relays or something, but I still don’t understand why you would do it as these are 10A relays that should be fine in this application. It was all code as you will see with the latest updates I made today. If you have an explanation for the bridge let me know, I would love to learn more about it.

  2. I have updated the code to fix the problem with the power outage doors opening. I also changed the wiring on the relays slightly moving the connection to the open side of the relay. If you check the code you will see that I swapped the LOW/HIGH states of the relays and I also set the relays to HIGH in the setup. This sets the start state to HIGH and the relay open.

    I also updated the web to remove the input boxes so that now when you click the button it doesn’t pop up the keyboard on mobile.

    Hope this is helpful. Have fun!

    1. You can also get around this problem and set the output state of the photon to match the relay behavior by using a NPN transistor to control the relay board input signal. I used D0 -> 1k ohm resistor to the base of a 2N3904. Then relay board input signal on the collector of the transistor, and ground connected to the emitter of the transistor. This will fix any power cycle issues and invert the active LOW behavior of the relay board.

  3. I have began playing with a photon and came across your project. It is well done. I have copied the code for the photon, compiled and loaded it into the processor and it is running. I have also copied the HTML code and updated the device id and access token. However, it always says no connection. I can’t seem to figure out why I don’t get a connection. I am not very good with HTML. Any clues you could give me to get it going? Am I missing a library or something like that?

  4. So I assume that you are getting the slow blue blinking light on the photon, that means that the code is running on the device. If that is the case then the libraries you need are all there since it compiled and loaded on the photon. (I also assume that you were successful in loading the code on the photon from the online IDE and it is not still running the tinker code…)

    That out of the way, if that is all working you need to check that the value is correct for the device ID and access tokens are correct. You can get these from the cross hairs (target device) and cog (settings) on the bottom left of the IDE page. As long as you are putting these values in the variables:
    //key is the same as your ‘access token’
    var key = “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
    //device_id is the same as the ‘core id’
    var device_id = “XXXXXXXXXXXXXXXXXXXX”;
    You should be working… That is kind of the beauty of this code, it is very generic and really pretty straight forward. There isn’t much to check to make it your own.

    If you are still having problems then is might be related to the key, if you have ever clicked the button to reset the access token in the ide, then you may have disconnected your device from the ide. It might take an intervention to get it back up. I have run into this before and it took reflashing tinker from the particle app (phone), and then flashing it again.

    The important thing is that you see the message:
    “Flash successful! Please wait a moment while your device is updated…” at the bottom of the browser when you flash using the IDE.

    The next thing to check would be the read switches. The value -1 is returned (NO CONNECTION) when the check for the door states is not one of the possible combinations.

    int statusCheck(String command){
    int status1 = digitalRead(reed1);
    int status2 = digitalRead(reed2);
    if(status1 == LOW && status2 == HIGH){
    return 1;
    }
    else if(status1 == HIGH && status2 == LOW){
    return 2;
    }
    else if(status1 == LOW && status2 == LOW){
    return 3;
    }
    else if(status1 == HIGH && status2 == HIGH){
    return 0;
    }
    else{
    return -1;
    }
    }

    You might check the wiring to see if you have the reed switch correctly wired and then if that looks good, check that it is returning correctly. If you only have one door this code would also obviously need to change.

    I hope this helps and you get it working soon. It took me some tinkering to figure some of this out, so hopefully you’ll get it soon. Let me know if you have any other questions.

    Good luck!

  5. Thanks, for the comment. It probably is to do with the limit switches. I have it running but haven’t connected anything up yet to simulate the door switches. I will mess with it tonight if time permits.

    Thanks again for sharing.

  6. Kyle,

    Couple questions:
    What’s with the dates and Months in your code? What is the purpose of that?

    I dropped your code in Particle Build, immediately ran “verify” and it failed in multiple lines.

    I’d love to use it but I just can’t get off the starting line.
    It look exactly what I’m looking for, just stuck out of the gate.

    I’m currently using a Moteino solution but the upkeep and connection issues with the Pi at 433Mhz is never ending.

    Thanks

  7. The month and date are there to determine daylight savings time. There is a bit in the code that tells it to close the door if it gets left open over night.

    What are the errors that you are running into? Maybe I can help debug them?

    1. Kyle

      Thanks for the help. In full disclosure as I mentioned above, I’m also using a Photon on this project. Do you have a version of this written for the Photon?

      We discussed the months and dates: You mentioned it’s so the door doesn’t stay open all night. I took this section out, my door has a timer on it and closes if we forget about it.

      The error is in the StatusCheck “IF” statement:
      black_garage_door.cpp:80:1: error: stray ‘\342’ in program
      Spark.function(“status”, statusCheck);
      The code (as you know) says:
      if(statusCheck(“check”) ==1 ) {
      relay1Pulse(“pulse”);
      }
      else if(statusCheck(“check”) == 2) {
      relay2Pulse(“pulse”);
      }
      else if(statusCheck(“check”) == 3) {
      relay1Pulse(“pulse”);
      relay2Pulse(“pulse”);
      }

      Thanks again for your willingness to debug a few lines.
      Lane

      1. This could be a copy paste thing… The \342 is the the “ character. It is possible that particle doesn’t like this and wants ” instead (I notice wordpress is doing some prettification of this character even in this response) . I know, crazy right?

        If you just delete the quotes and retype them it will probably work. Give it a try and let me know.

        BTW, this was written for the photon. If you are wondering the “Spark.function” is just the older way to say “Particle.function”. I have since changed it in my code, but they both work on the photon.

        Thanks

  8. Terrific use and modification of the original project, my hat is off to you sir.

    I’m going to emulate your setup on my one garage door and have all parts ready to go. I’m hoping you’ll have a few minutes to answer a few questions for me (and probably many others):

    REED SWITCH WIRING QUESTIONS – (my questions will be based by defining the two halves) : (A) = no screws, no wire, stays on moving garage door (B) = 3 screws, wire(s), COM/NO/NC, remains stationary

    1) For (B) – I’m assuming you wired into but unclear if you also wired into and/or ?
    2) For (B) – Assuming you wired into , and/or , where did you wire into on the other end? Did you wire into the garage door opener, relay or Photon board/pins?

    GENERAL SETUP

    I’m assuming you wired up two doors, at least that’s what it seems. Will you kindly comment on your setup IF you only had to wire one door? I want to be sure that I understand clearly what is and what is not needed and your answer will help immensely.

    GENERAL USE

    You mentioned you ditched the APP portion of the project for a web-based solution. What is your method to accessing the garage door without an APP? Do you have to go to a webpage each time to open/close the door(s)?

    Lastly, I’m not sure if you are a community member of Instructables.com but I’m certain this community could benefit greatly by your project. As a paid member of Instructables.com, I would be honored to post your project on that site for everyone to vote, on your behalf. There are many contests with great prizes and knowing that community, I think you have a great opportunity to win something nice! Again, I’d be happy to post on your behalf and provide proper credit for the project.

    Thank you again for considering a response to my questions, I (and many others), would be grateful! Please let me know about the Instructables submission.

    Andrew

    1. So I have two doors that I control with this. If you only have one, you would put one of the two leads from the read switch(B) to the 3v3 power port on the photon and the other to D1. I’m not sure if you can tell from the picture, but I use D0,D1(opener,reed switch) and D3,D4(opener, reed switch) for the two doors. If I read what you are saying correctly, do you have 3 wires on your read switches? If so, you might have a different one than the ones I bought (I don’t sell them).

      So, since you got the one with three screws… This is the difference:
      reed switch image
      It appears that you are getting an option to use the normally closed (NC) lead or the normally open (NO) lead. In my case I used normally open switches. You will need to play around with the orientation of you switch in order to get it to close when your door is closed and the magnet(A) is next to the switch(B).

      So, if you are only connecting one door, you could just leave D3/D4/one of the 3v3 wires off. The rest of the connections would need to be made.

      The app didn’t work that well for me. I just created a shortcut to the web page I created on my phone that takes me straight to the page (Code included in this project description). I would make sure that you put it somewhere that is password protected. My web host has the ability to password protect directories. It takes just as long to load the page as it would the app and they both need internet access to get the state of the doors and send the commands. I have an android phone, but you can probably do this on an iPhone.

      Hope this helps and let me know if you have any other questions. I don’t mind your sharing this with others if you want. That’s why I posted it. YEAH SCIENCE!

      1. Outstanding! Thank you very much for your detailed response, very, very helpful. I’m off for the next week and will be completing this project tomorrow! I’ve been watching your irrigation system project and will be tackling that next 🙂

        Great stuff here, I’ll be sure to spread the genius and provide proper credits, links and references!

        AP

  9. This is one of my first Particle Photon projects. I read your project and decided it looked like a great “turnkey” project to cut my teeth on.

    Unfortunately I’m having a newbie experience. When I cut and paste the photon code you provide into my build.particle.io page and try to flash it, I get a horribly long list of errors (if you email me, I can send you the entire list so I don’t spam this comment). I can’t begin to figure out what I’ve done wrong.

    Any guidance you can provide would be greatly appreciated.

        1. It went to a comcast.net email that is part of your profile. That said, my thought was that it might have been a copy paste issue as the lines that were failing in the compilation shouldn’t have failed as some of them were just declaring your hooks for the functions. I would take the a look at the code here Code here. and check it against the code you have in your build.particle.io ide.

          Hope this helps, sorry for the delayed response.

Leave a Reply

Your email address will not be published. Required fields are marked *