Garage Door Opener with iPhone App

mattb97, That might be a good thing to look at. My opener stop working a few months ago, and I haven’t repaired it, but it looks like I may have damaged the breakout board, possibly by pulling too much current to the transistor. The board still functions, but the voltage doesn’t switch high enough to flip the relay. I guess I should get back into this project one of these days… Too many projects, too little time.

Could you connect an IMP directly to the remote of the opener? If so would the program coding be any different? I want to try and implement this process to open a dog kennel. The actuator uses a 315mhz remote control.

You could… assuming the remote had a physical button… you could use a relay to “push” the button. The code wouldn’t be different, you would just have to disassemble your remote and wire the relay to the button.

attached is the schematic of the relay…any and all insight is greatly appreciated. I definitely want to tap into the module and bypass the 315mhz reciver.

It looks like you just need to set up a relay circuit with an Imp, and connect the relay to the correct pins. Connect the Common and NO pins on the relay to those on the receiver, and you should be good to go. It will work exactly like a garage door, I presume. I have example code on my GitHub page for using with Pitchfork. You could also connect sensors and then always know what state it is in. My example code uses two sensors so that it knows if the door is completely open or completely closed, you may only need one.

I guess I should update Pitchfork so the Garage Panel can be changed to any type of door you like… or maybe I’ll just add another panel.

I probably posted this somewhere else, but here is a pic of my current garage door opening circuit… hardware from Adafruit and RadioShack.

At the terminal blocks, three of the pins are tied to GND, one to a DIGITAL_OUT Pin to switch the relay, and two DIGITAL_IN Pins to read the position sensor switches.

thank you for the in depth info! i will give this a shot, and let yall know how it turns out! Is there a specific relay I should get (assuming 5v)? Do I need to install any transistors?

Here is a schematic for your circuit… made for an Arduino, but will work with an Imp.
Use a 1K resistor, a standard 5V relay, a 1N4001 diode, and a transistor similar to a 2N2222, or 2N3904. Connect your Imp pin configured as DIGITAL_OUT to the resistor, and VIN to 5V…assuming you power the April with a 5V power supply… and the rest of the circuit as shown.

http://makezine.com/2009/02/02/connecting-a-relay-to-arduino/

thank you! I was just looking over that schematic right beofre you sent it. and comparing it to the picture you have posted above. Are all three of your leads from your 2N2222 soldered into the same hole???

No. Your emitter needs to be connected to GND, your BASE will be connected to the 1K resistor that goes to the Imp, and your collector will be connected to the side of your relay coil that isn’t going to +5V.

My transistor is connected across three different traces on the perf board.

ok…So I got everything put together for the most part… Does the device get power from the USB plugin and power the entire unit? Or do I need external power source other than the usb power?

Pin 9 is what is going to send the power to the actuator correct? Do i need to remove the code referring to pin 7 and 8 if i am not using the extra sensors?

downloaded your app, and right now i am testing the led project just to get a hang of everything…for some reason I can turn the LED on and off in the internet, but not with the app. Any ideas?

If you are using an April board, and powering it with 5V at the Mini-USB connector, then you have all the power you need. The Imp runs at 3.3V, and the April has a Buck regulator onboard that regulates the 5V down to 3.3V. However you still have 5V available to use at the VIN pin. If you are using a 5V relay, then connect VIN to the side of the relay coil marked +5V on the circuit. You shouldn’t need any additional power.

Any of the 6 pins on the April board can be configured as a DIGITAL_OUT, I used PIN 9 because it was convenient for the circuit that I built. You will need to pull out various bits of code, including checking the sensors if you don’t have those.

The best way to troubleshoot with the Imp is to log things to the console with server.log(); Did you add an API-Key to the app and to your agent code? Which panel are you using? Garage door? When you press the button do you see anything happen in the Imp log? If you don’t get anything, check the URL in the app. You should see the console log request.body, and the API-Key at the Agent.

At the device, the code that switches the relay only switches it closed for 1 second, and then back open. This mimics a momentary “push”, and maybe be hard to see.

If I get a chance today, I’ll strip the agent and device down to just opening the door. The code posted isn’t going to work correctly for you, because it expects to get signals from the sensors.

If you want to test with an LED, use the Control Panel in Pitchfork and load the code I have on GitHub, and use one of the switch controls.

Then add the lines indicated to actually flip on the LED:
agent.on("switch1", function(a) { local data = ""; if (a == "1") { // Add the line below hardware.pin9.write(1); data = "Switch 1: On"; } else if (a == "0") { // Add the line below hardware.pin9.write(0); data = "Switch 1: Off"; } agent.send("switch1", data) });

I just noticed that the control panel code was truncated for some reason and updated it.

i wasnt exactly sure where i was supposed to get the API key. So i did not add that to the code. i was using the control panel, but with your additional code i see why it wasnot working. I slowly pulled out bits of code until i stopped getting errors, but I may or may not have pulled out too much code. I also think i might need to rewire my board, I built it exactly how you had yours, which now i see probably will not work, since i dont have the additional sensors installed yet.

In case you have not noticed, I am a noob at the electronics side of things. thanks for being patient!

No worries. Others have helped me learn what I know, and I like to pass it on.

An API-Key is basically just a password for your agent’s API. (The code that the iOS app talks to.) It is entirely for security, and here is how it works. You create an API-Key in your agent code in a string variable, and it can be anything you want, but the longer and more complex the better. When you send a command from one of the Pitchfork controls, the API Key is sent to your agent in the HTTP headers. (You put the same Key into the Pitchfork settings). Notice this line in the agent code:
if ("api-key" in request.headers && request.headers["api-key"] == apiKey)
That line looks to see if an API Key has been sent, and if so, does it match the API-Key variable? If it does, your control is executed. If it does not, the program runs the “else” statement, which in my example, sends and SMS message with Twilio. You don’t need to do that, it’s just nice to get an alert if someone is attempting to access your Imp.

As far as the hardware goes… there are connections on the bottom of the board as well, that you can’t see, so it might not be best to try to follow it exactly… just as a reference. Also your relay likely has a different pin out. Make sure your circuit follows the schematic you have, and make very sure that your transistor is in the correct way. A mechanical relay will click when it is switched, so you’ll know for certain if it is working.

Give me a bit, and I’ll make agent and device code that doesn’t have sensors included, and post it on GitHub.

I just posted agent and device code for use with no sensors. I did leave necessary code in the agent, because the Pitchfork app expects to get a door status when you open that control. It does that automatically, without you pressing any buttons. You will always get an “Unknown”, or whatever you put in that variable for door state. That code should work properly for you. If you have problems, look at the console logs, and see where things are getting stuck. I have quite a bit logged at each part of the program for that purpose.

An easy way to get a good API-Key is to sign up for a Xively developer account. Then create a test Feed. You can create as many API keys for a feed as you like, so just have it create one, copy it somewhere and then delete that key… or just make something up. Let me know how you make out.

Ok so after looking at the schematic this is what I think it should be… How far off am I?

I’d need to pinout on your relay to know for sure, but I can see a few things that need to be changed.

The diode needs to be connected across the coil pins on the relay. There should be a white bar on the diode or something like that. Connect that side of the diode to the relay coil pin that is also connected to 5V(VIN), and the other side of the diode to the relay coil pin that is connected to the transistor collector. I assume your green and blue wires are coming from Common and NO on your relay, and that is correct, those will go to your opener circuit.

I guess I am confused, because if I move the diode, it will interfere with P9… Do i need to change it to look more like yours? I found head on photo of your device so i can see all of the connections.