Hello Everyone!

This instructable explains how I setup a Raspberry Pi to open my garage door using a smarthphone. While this has been done before, I thought I'd post my solution. This was my first hardware project and instructable ever and I'm sure I made some mistakes. So, when you find one let me know! 

Project Overview:
What we will be doing is turning the Raspberry Pi into a small web server. When you access the webserver from your browser of choice, you will have a big button that triggers the garage door via a relay. We will wire a very basic circuit to the Pi's GPIO pins and upload a website that triggers the circuit. When the relay is triggered, it closes the circuit hooked up to the garage motor and opens the garage.

Why would anyone want to do this?
Well, my garage door opener was broke and this was cheaper than replacing the other system. As an added plus though, you could wire up additional sensors and be able to make sure your garage is closed remotely if your were so inclined.

Shopping List:
I consider myself pretty cheap, and I tried to keep the costs minimal. All of the items are available on prime.

1.) Raspberry Pi - Model A - $32

2.) Wifi Adapter - $10

3.) PSU - $5

4.) 5v Relay - $6

Total: $53.00

You will also need an sdcard >= 2GB and some wires, but I had extra of each.

Step 1: Install and Optimize Rasbian (for our purposes)

This first step is to install an operating system to your rpi. I'm a bit of a debian fanboy, and had an extra 2GB sdcard, so I went with a shrunk version of Wheezy. The image I used can be found here:


For full instructions on installing an OS to your PI and other images, visit http://www.raspberrypi.org/downloads.

On Ubuntu, I used gparted to format to fat32, and dd to write the img.

After you install the OS, plug in a usb keyboard and hook up the raspberry pi to a monitor. Assuming you are using Wheezy, on the first boot rasp-config will automatically run. You should use this tool to stretch the parition and enable ssh (under the advanced menu on newer versions I believe).

After I installed my img, I also removed the GUI to free up some space. (If you have a large SD, you can skip this.) To do this type these commands:

$ sudo apt-get remove --purge x11-common
$ sudo apt-get autoremove

This removes all packages that depend on X11 which is pretty much all of the GUI.

<p>Hi there. Thanks for the tutorial. I built something similar but I wrote the server code in nodejs. Since I start the node server at boot I could add the initialisation code for the pins (to make sure the door stays closed at startup) inside the nodejs script. No need for a separate bash file.</p>
<p>THANK YOU for posting this - what a great system and guide! I built this two years ago and just had to re-build it due to an SD card failure. </p><p>Mine wouldn't work until I added a &quot;-g&quot; to the two commands in the /etc/init.d/garagerelay scripts as such:</p><p># Turn 7 on which keeps relay off<br>/usr/local/bin/gpio write -g 7 1</p><p>#Start Gpio<br>/usr/local/bin/gpio mode -g 7 out</p><p>I vaguely remember having to do the same thing 2 years ago. You might want to edit the instructions to include the -g, which as you probably know tells the Pi to refer to the GPIO pin number, and not the &quot;actual&quot; or numeric pin number. </p><p>Also, one other tip. The photos you show are for an older RPi Model A, which is fine. Personally I'm running on a Model B. You may want a note saying to refer to your own pin-out diagrams (and specifically the GPIO pins) if anyone is using a more modern Pi 2 Model B or B+, or even a Pi 3 Model B... </p><p>Thank you again - I am running this to provide access to an entire Club so they can open the access gate from their phones via wifi when the RF-remotes won't reach the base station. Now... the next project is for me to turn it into an app instead of &quot;just&quot; a local web server! (Hah, that's what I said ~2 years ago too...!)</p>
Also, I had to initialize GPIO as off, or zero, not 1 as in the example. After rebooting the relay was pegged and connected (causing the remote to trigger and open the gate), so I manually issued the gpio -g write 7 0 command, fixed the startup script with the &quot;0&quot;, and rebooted to confirm that it worked... which it did! Thanks again, and I hope some of this helps others as well!
<p>Thanks to the author for the great instructable, it really helped me get started! Additional tweaks I implemented were adding two reed (magnetic) switches to inform the pi when the door is either fully open or fully closed. My web page displays the status of the door in real time (via websockets), regardless whether the door is controlled by the app or other openers. I also have it send me a text message if the door has been left open for more than 5 minutes. I found node.js a good language to use for the software- it can host the website, control the door, listen to the sensors, send text messages and emails as you like when events happen, all from one running app.</p>
<p>Hi ChrisG212,</p><p>Iam looking for the exact same functions. Any chance you could share yours ?</p><p>Thanks in advance.</p>
<p>I will plan to create an instructable when I get time since it is too many details to include in the comments area. I will provide a link here when I have completed it.</p>
Oh Nice ! I'm looking for this too, can you share please ? :)
<p>This is exactly what I am trying to do! Could you provide any more information please ChrisG212? Any help will be great</p>
<p>Completed the project but just one little issue that I found.I have a LCD garage door remote that has time/temperature and light option and when I leave it connected to the garage door and when pressing the button through the web interface the relay clicks all the time but sometimes the garage door won&rsquo;t open. When I remove the stock garage door remote wire from the garage door system everything works perfectly.I am assuming there is an issue with the flow of current and if I assume if I use a regular push button then it wont be an issue but in this case it is a LCD remote that has features on it and all running on one wire to the garage door. Anybody seen this issue and if so what did they do to fix it, I have a craftsman die hard garage door opener. Would I need an resitor somewhere? </p>
<p>I have a problem. when I type in: sudo chown -R pi:root /var/www into the ssh, nothing happens. no folder is created or anything :( plz help</p>
<p>So I set up and follow the instructions to do the Garage Opener. When I got through all the steps I wanted to test it and make sure it was getting the power when pushing the button. So before hooking it up to the Garage Opener I attached a small LED light to the wires and it appears that the LED is ALWAYS dimly lit/on. When the button is pushed, the LED gets brighter. Should I be concerned that the Pi is always pushing out some power?</p>
<p>Can anyone tell me why this happens. If the power in the house blinks, or goes out and comes on later, as the RasPi reboots the door will open with out a command from me. There have been times I come home and garage is open and i didnt do it, but can see the power blinked or went out. </p>
<p>Power spikes, line conditioner on the net router will help</p>
<p>See step #6 for explanation and potential solution.</p>
<p>I think, but don't quote me, if you used Pi GPIO pin 5 (wiring pin 9) instead of GPIO pin 7 (wiring pin 7) you wouldn't ever have the issue at all, because that pin has a fixed 1.8 KOhm pull up resistor on board.</p>
<p>This system needs a pull up resistor between the output pin(s) and pin 1 on the pi (3v3) to pull that pin high when the pi is starting up. That will fix the problem. Your step 6 will probably work about half the time. (if it works every time for you, there's someone else in the world that will find it works none of the times.)</p>
<p>If I plug the Raspberry Pi into the same outlet as the garage door opener head unit, are the power fluctuations (when the opener motor starts and stops) bad for the Pi? Has anyone else used that outlet without issues?</p>
<p>That called endrush, its caused when a motor or valves are energized.</p><p>You can get an in line filter/line conditioner from Radio Shack or electrical supply (MOV)</p>
<p>Would this interfere with a multi-button Wall Panel where you can not only open and close the garage door, but also turn on light, or place your unit in lock mode? If i had a single button opener on my wall this would be straight forward. Please advise if you have any more insights here. thanks and great job! this is pretty darn cool.</p>
<p>If you have a multi-button wall opener, it probably connects by two wires to the garage door opener. You can connect your relay to the same two terminals on the garage door opener. It seems like when you press a button on the wall opener, it sends pulses to the garage door opener, but if you just short those terminals by closing your relay for a second or so, it makes the door open or close. The wall opener will still work normally, including the light switch.</p>
I having a Chamberlain multi LCD wall button with motion sensor. It also tells if power has been restored or battery backup is charging. Does time and temp and lights.<br><br>I went directly to the ceiling unit. I think the wall button LCD doesn't like being shorted. I sometimes get a message on the LCD saying something is miss wired. So I may need to add leads to actual button or solder leads on a wireless remote.<br><br>Anyone have any thoughts?<br>
<p>Oh. Another not-as-tricky option (now that I've looked at your wall button thing) is to crack open the button itself and just find the two wires that go to the actual button itself, intercept those and connect them together briefly, see if that gets your door moving. There are probably eletronics of some sort between the wires that go to the button box on the wall and the wires that go to the actual button itself. At the end of the day, that physical button probably just latches two wires together for a bit. Plus, if you screw it up, those wall button devices are under $40.</p>
<p>Your best bet is finding two terminals at the opener that are for a normal open button. There's no telling what they are sending down the wires to any kind of fancy wall button control module- it could even be some kind of data and not a simple open/short operation. </p><p>If your model just doesn't have any other easy way to attach a normal button, your next best option (and this is a tricky one) is to figure out on the inside of the opener which relay is flipping to cause the motor to go. The rest of it (open vs close, stop when you hit the top or bottom) should be mechanically controlled-- between the fancy controller parts and the mechanical up/down/stop/start parts should be a single relay (maybe two) that kick off the open or close procedure. If you can find those (look for relays, measure their input voltage when the system is doing different things) and if you can control power to those externally (note that they likely are 120v coils so please don't kill yourself) then you can control the up/down. </p><p>This will void your warranty. Don't operate appliances of any kind with covers removed. 120 volts is enough to kill you if it hits you the right way. And remember kids, have fun!!</p>
<blockquote>Most relays including the one I purchased, operate like this - when the signal is ON the circuit stays off. When the signal is OFF then the circuit is on.</blockquote><p>I'm totally new to this and don't understand this part. I assume you have either NO or NC terminal connected to the garage door opener. If normally when the signal is ON, the circuit stays off and vice versa, can't you just switch the garage door connection from NO to NC or NC to NO?</p>
<p>Here's the thing about GPIO ports on a pi, or an arduino, or just about anything that has a GPIO port. They [typically always] start up as INPUT, not OUTPUT, which means they are waiting for you to ask if they are &quot;high&quot; or &quot;low&quot; (3 volts or 0 volts, or 5 volts or 0 volts usually, this depends on what system. High and low can mean a lot of different things here, but low is almost always zero volts referenced to the other voltage.) </p><p>Let's say that for the purposes of explanation our system uses +3 to mean high and 0 volts to mean low. Since the pins are just sitting there waiting for you to ask if it's high or low, they don't have 0 volts on them and they don't have +3 volts on them either, they are what we call &quot;floating&quot;. Now sometimes, it will be closer to high and sometimes it will be closer to low, but there are a lot of variables that can affect this (like static in the air even!) so if your relay knows to turn itself &quot;on&quot; when it sees 0 volts (low) and &quot;off&quot; when it sees +3 volts (high) and your pin is &quot;somewhere between 0 and +3&quot; then it might be close enough to one end to turn it on or close enough to the other end to turn it off. </p><p>So it doesn't matter if you use the NC or the NO, even if you reverse the logic in the software to make one way on and the other way off, you're still going to have this &quot;I'm not in an output mode yet so I'm somewhere between high and low&quot; problem and you're not really going to know for sure if the relay is going to be on or off. For our purposes though, we really should have it set up so that the relay is off *most* of the time, and just clicks on to &quot;press the button&quot; as it were.</p><p>The way we fix this, in electronics terms, is to &quot;pull it down&quot; or &quot;pull it up&quot; with a resistor. That's the fancy term, usually a &quot;pull-up resistor&quot;. It sounds complicated, but the reality is, you just connect the pin over to 0 or to +3 with a resistor. Just about any resistor will do. The resistor will drag that pin &quot;high&quot; or &quot;low&quot; (depending on if you connected the other end to high (+3) or low(0) when the pin would otherwise be in a floating mode. A lot of relays have a pull-up resistor built in, a lot of systems with GPIO pins have a way to &quot;turn on&quot; a pull-up resistor built into the hardware so that you don't even have to physically wire one in. But what about if the resistor is pulling your output pin to +3 and you need it to go to 0? That's easy, when you &quot;write&quot; to the pin and tell it to go to 0, that 0 has a resistance that is much much less (like, about 0 ohms) than whatever resistor you've put in so your resistor basically does nothing. It's like you trying to whisper to someone at a rock concert. (your whisper is the pull up resistor and the concert is the near zero-resistance connection that the system made when you said to go LOW.) Then when you write to the pin and tell it to go to +3 that resistance is also much much less than whatever resistor you've put in so it ignores the resistor then too. So the only time your pull up resistor does anything really is when the pin is in a state where it isn't high and it isn't low (remember, when it's &quot;floating?&quot;) so that resistor prevents the float.</p><p>In the author's case, it seems like most of the time (enough of the time) his float is in a certain direction so he's just counting on that to not change. But you really need a pull-up (or down) resistor (or a way to enable one built into the pi?) to make for sure you know if that pin is high (+3) or low (0). </p><p>On another note- if you're going to try this, you really need some basic security on the web server running on the pi. I guess if your home wifi is secured with something real (not WEP!) then that's a good start but you're basically giving access to your garage door to anyone with your home wifi password. Or anyone who plugs into your home wifi... which would probably be someone inside your house already... but this really should have an extra layer of security. I'm not a pi wiz or an apache wiz but since we're talking ethernet and mac addresses there's probably a not-too-complicated way to tell the pi not to talk to anyone except your known devices, by mac address. (mac addresses can be spoofed, but that takes more work than anyone who wants access to your garage is going to do unless you're keeping gold bars in there?)</p><p>If the pi uses 5 volts on it's GPIO (but I think it is 3) then change every +3 above to +5! :)</p>
<p>Well, I will share my Index and others files, as I added 2 relay to close door, you still need to make pin work at the start, also I have not yet tested, but trigger's working and returning the 1 and 2 </p><p>&lt;?php <br> if(isset($_GET['trigger']) &amp;&amp; $_GET['trigger'] == 1) {<br> error_reporting(E_ALL);<br> exec('gpio write 7 0');<br> usleep(1000000);<br> exec('gpio write 7 1');<br>}<br> else if(isset($_GET['trigger']) &amp;&amp; $_GET['trigger'] == 2) {<br> error_reporting(E_ALL);<br> exec('gpio write 2 0');<br> usleep(1000000);<br> exec('gpio write 2 1');</p><p> }<br>?&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br> &lt;head&gt;<br> &lt;title&gt;Garage Opener&lt;/title&gt;<br> &lt;link rel=&quot;apple-touch-icon&quot; href=&quot;apple-touch-icon-iphone.png&quot; /&gt;<br> &lt;link rel=&quot;apple-touch-icon&quot; sizes=&quot;72x72&quot; href=&quot;apple-touch-icon-ipad.png&quot; /&gt;<br> &lt;link rel=&quot;apple-touch-icon&quot; sizes=&quot;114x114&quot; href=&quot;apple-touch-icon-iphone-retina-display.png&quot; /&gt; <br> &lt;link rel=&quot;stylesheet&quot; href=&quot;/css/style.css&quot; type=&quot;text/css&quot;&gt;<br> &lt;meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot;&gt; <br> &lt;script type=&quot;text/javascript&quot; src=&quot;/js/jquery-1.10.2.min.js&quot;&gt;&lt;/script&gt; <br> &lt;script type=&quot;text/javascript&quot; src=&quot;/js/script.js&quot;&gt;&lt;/script&gt; </p><p> &lt;/head&gt;<br> &lt;body&gt;<br> &lt;div class='awrap'&gt;<br> &lt;a href='/?trigger=1'&gt;<br> Open<br> &lt;br/&gt;<br> &lt;a href='/?trigger=2'&gt;<br> Close<br> &lt;/body&gt;<br>&lt;/html&gt;</p><p>$(document).ready(function() {<br> $('a').click(function(e) {<br> e.preventDefault();<br> $.get(&quot;/?trigger=1&quot;);<br> $('a').click(function(e) {<br> e.preventDefault();<br> $.get(&quot;/?trigger=2&quot;);</p><p> });<br>});</p>
<p>Thanks for posting this. I do see two button, but they both trigger the same relay for me. Any ideas?</p>
Perhaps you got the PI pin's mixed up, the code look for input related to pins and then use that to fire the relay, each one have number, in my case 1 and 2<br><br>Some time back I made this now, but Im happy to share my files with you if you need,
<p>I figured it out. I had to modify the index.php that you posted. Below is what I am using.</p><blockquote>&lt;?php<br>if(isset($_GET['trigger']) &amp;&amp; $_GET['trigger'] == 1) {<br>error_reporting(E_ALL);<br>exec('gpio write 7 0');<br>usleep(1000000);<br>exec('gpio write 7 1');<br>}<br>else if(isset($_GET['trigger']) &amp;&amp; $_GET['trigger'] == 2) {<br>error_reporting(E_ALL);<br>exec('gpio write 2 0');<br>usleep(1000000);<br>exec('gpio write 2 1');<br><br>}<br>?&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Garage Opener&lt;/title&gt;<br>&lt;link rel=&quot;apple-touch-icon&quot; href=&quot;apple-touch-icon-iphone.png&quot; /&gt;<br>&lt;link rel=&quot;apple-touch-icon&quot; sizes=&quot;72x72&quot; href=&quot;apple-touch-icon-ipad.png&quot; /&gt;<br>&lt;link rel=&quot;apple-touch-icon&quot; sizes=&quot;114x114&quot; href=&quot;apple-touch-icon-iphone-retina-display.png&quot; /&gt;<br>&lt;link rel=&quot;stylesheet&quot; href=&quot;/css/style.css&quot; type=&quot;text/css&quot;&gt;<br>&lt;meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot;&gt;<br>&lt;script type=&quot;text/javascript&quot; src=&quot;/js/jquery-1.10.2.min.js&quot;&gt;&lt;/script&gt;<br>&lt;!-- &lt;script type=&quot;text/javascript&quot; src=&quot;/js/script.js&quot;&gt;&lt;/script&gt; --&gt;<br><br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div class='awrap'&gt;<br>&lt;a href='/?trigger=1'&gt;<br>Door 1<br>&lt;/a&gt;<br>&lt;br/&gt;<br>&lt;a href='/?trigger=2'&gt;<br>Door 2<br>&lt;/a&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br>$(document).ready(function() {<br>$('a').click(function(e) {<br>e.preventDefault();<br>$.get(&quot;/?trigger=1&quot;);<br>$('a').click(function(e) {<br>e.preventDefault();<br>$.get(&quot;/?trigger=2&quot;);<br><br>});<br>});<br>});</blockquote>
<p>Works great! Just wish it would work outside of my WiFi. I don't want to open any TCP ports for security reasons. </p><p>Great project!</p>
Hi everyone. I have this project done but can't get the garage door to open. When I hit the button on my smartphone I can see the wifi adapter light activate as well as the indicator light on the relay. I do not hear the relay click when this occurs. I am using the provided canakit 2.5 amp power adapter so i dont think this is an issue of lack of power. Your input and ideas are welcome<br> Thank you<br>
<p>does anyone know how to change the code for raspberry pi II? I have the raspberry pi 2 and what file do I go into to change the PIN numbers?</p>
<p>I receiving the following message</p>Not Found<p>The requested URL / was not found on this server.</p>Apache/2.4.10 (Raspbian) Server at 192.168.1.XXX Port XXnot sure what i am missing everything went well until i got to test the page
<blockquote>Most relays including the one I purchased, operate like this - when the signal is ON the circuit stays off. When the signal is OFF then the circuit is on.</blockquote><p>I'm totally new to this and don't understand this part. I assume you have either NO or NC terminal connected to the garage door opener. If normally when the signal is ON, the circuit stays off and vice versa, can't you just switch the garage door connection from NO to NC or NC to NO?</p>
<p>i am using rasp pi 2 for this - added VNC, VLC and smoother items. The server however isn't really populated and only gives me the index. I plan on adding other prefer to it as well. but need to have the server for IP/WIFI control first. Any help is great.</p>
<p>I need the software package/code for raspberry pi 2 version 1</p>
<p>This Is My Finished Garage Automation System.</p><p>Ended up installing RPi-Cam-Web-Interface and adding Buttons to it.</p><p>This come with a authentication page built in.</p><p>Just added a Cron job to automate turning on and off the christmas lights!</p><p>Great Fun these boxes.</p>
<p>What is the difference between your relay module and this one? other than the obvious 2 additional channels?</p><p><a href="http://www.microcenter.com/product/437826/4_Channel_5V_Solid_State_Relay_Module_BoardOMRON_SSR_AVR_DSP_Arduino" rel="nofollow">http://www.microcenter.com/product/437826/4_Channe...</a></p><p>Can I use it in the same fashion as you have without the need of additional power sources or other parts? Yours seems so simple, but I read others who used this part had to provide additional transistors and what not.</p>
<p>I deleted the index under .git and replaced it with the new index.php and I am still getting the following message</p>It works!<p>This is the default web page for this server.</p><p>The web server software is running but no content has been added, yet.</p><p>Does anyone know what I am doing wrong?</p><p>Thanks</p>
<p>My guess would be that you need to configure the PHP extension on the web server. In Apache, the httpd.conf file has this line</p><p>&lt;IfModule dir_module&gt;<br> DirectoryIndex index.php index.php3 index.html index.htm<br>&lt;/IfModule&gt;</p><p>You need to make sure the right file names / extensions are in there.</p>
I managed to use this Instrucables and one from PiMyLife to have video on same page as garage door button .<br><br>http://www.instructables.com/id/Raspberry-Pi-Garage-Door-Opener-with-streaming-vid/
<p>Super cool. Thanks for sharing!</p>
<p>i want to control a relay from openelec so i can remotly turn off my lights with a press of my remote will this work with openelec?</p>
<p>Good article. Now I can control my garage door using a web-interface. A few additional things I did was to password protect the page, and add mechanism for knowing the state of the door (open or close).</p>
<p>How would you create a password to protect the website?</p>
<p>Use a simple php script. Something like this.. </p><p><a href="http://www.phptoys.com/tutorial/creating-password-protection.html" rel="nofollow">http://www.phptoys.com/tutorial/creating-password-...</a></p>
Hi <br>I have a question i'm doing a university project and need just a door lock to open and close via smart phone more like an web app open, close nothing to fancy, but i only want it open close via battery so do i need a relay and how can i by pass it ? <br> <br>Thanks
<p>If you do not like to control your device via web interface, you can try Android app</p><p><a href="http://www.instructables.com/id/RaspberryPi-Android-Switch-Home-automation/" rel="nofollow">http://www.instructables.com/id/RaspberryPi-Androi...</a></p><p>Keep original setup but skip web-server part.</p>
Great instructable!<br>I have been using my Raspberr Pi controlled garage door for months without any issues.<br>I am now trying to understand the code but I am struggling. I deleted the original images uploaded to /var/www and uploaded my owm image but I still get the gray button. So I am confused what it's doing.<br><br>Would some one be kind enough to give me a line by line rundown of the code in index.php so that I can understand and learn how everything fits together.<br><br>Many thanks in advance.<br><br>Joe

About This Instructable




More by quartarian:Raspberry Pi Garage Door Opener
Add instructable to: