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>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>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>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>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>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
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>I know this is an old thread - but I am trying to get rid of the Gray button and make it prettier. Anyone have any idea how to do that?</p>
<p>Thank you for the instructions. I used them to assemble the device and wrote small customizable service that can be run on the device and controlled remotely via android app. </p><p><a href="https://github.com/sshlyk/switch-server" rel="nofollow">https://github.com/sshlyk/switch-server</a></p><p><a href="https://github.com/sshlyk/switch-android" rel="nofollow">https://github.com/sshlyk/switch-android</a></p><p>It is very flexible and you can configure separate relays to act as a switch that turns something on/off or you can make it pulse and use it as garage door opener. All devices are seen on in the app and you can controled individually.</p><p></p>
Can you integrate this http://pimylifeup.com/raspberry-pi-webcam-server/
I made this, worked the first time.<br><br>How would I merge this so video is on the same screen as the Garage button? http://pimylifeup.com/raspberry-pi-webcam-server/
<p>What about muilti function wall buttons that do lights and other stuff?</p><p>I saw on another site that said open/close is just shorting the pair. Lights put a Capacitor in series, etc</p>
Hi. Can i do this without internet connection Or with a Bluetooth?
<p>Worked like a charm!</p><p>I have an IP camera in the garage and added it to the web page, just above the button. </p>
<p>hello,</p><p>i am new to linux and the Pi but I have followed your instructions thru step 4.and all seemed to work but when I go the the page I do not have button just a blank page which is titled &quot;Garage Opener&quot; . I am not sure what to try . Can you advise me?</p>
<p>sorry, I figured it out . on to step 5</p>
<p>Can you advise me on how you got this to work? I am having this issue as well.</p>
<p>AWESOME INSTRUCTABLE!! thank you . I would like to add an older logitech orbit webcam i have laying around to the webserver. is this possible and where do i start? </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>
Please help me. My garage khas two buttons one to open and one to close and I can only open it. How to add another button to use the other relay???
<p>Mine too but i got it worked out. you still need help?</p>
<p>Yes I kind like to know, I have in fact 3 , open close and stop, guessing Im able to relay 2 for close ? and 1 for open </p>
<p>I know I'm a bit late, but links to Image looks not to work, and the ones I found just make a 56Mb drive out of my 2GB SD card anybody have the right files ? and like to share</p>
<p>Perhaps this ?</p><p><a href="http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian/images/2013-05-25-wheezy-raspbian-shrunk/" rel="nofollow">http://ftp.jaist.ac.jp/pub/raspberrypi/raspbian/images/2013-05-25-wheezy-raspbian-shrunk/</a></p>
<p>Im a bit late to this, but like to make it, but I look not to be able to download the <a href="http://raspberry.mythic-beasts.com/raspberry/images/raspbian/" rel="nofollow">http://raspberry.mythic-beasts.com/raspberry/images/raspbian/</a> I did find the noobs image but it need a lot bigger SD card than the 2GB anybody have the Image or advice ?</p>
<p>I made this and connected it to my Chamberlain garage door opener today. It works great.<br><br>I used an old internal CD-ROM audio cable to connect the Pi to the relay. I took off one end and used its crimped-on female pin connectors to attach it to the GPIO header on the Pi. The original four pin header connector on the other end fit perfectly on the relay.<br><br>Next I'd like to add a sensor to tell me if the garage door is open or not. I'm thinking a cheapo magnetic sensor you use to detect open windows and doors in a home security setup, or even just a simple switch attached to a GPIO input. It could show as a green/red indicator on the garage door opener web button.</p>
Hey, I made it too! Thanks for the instructions. I have one issue. I noticed after a few minutes of stand by and I try to return to the page, it times out. I'm wondering if something is going into stand by or something else may be wrong. It takes me a couple tries before I can get back on. Any thoughts?
One thing that just occurred to me is I had it booting to the GUI. Seems to be doing good now after changing it.
The wireless adapter was going on stand by and the following fixed it. BTW, my adapter is a EDIMAX EW-7811Un<br><br>Create the new file<br>$ sudo nano /etc/modprob.d/8192cu.conf<br><br>Add the following <br>options 8192cu rtw_power_mgnt=0<br><br>Then<br>Reboot<br><br><br>Looks like it's working
Correction: /etc/modprobe.d
<p>I just finished the garage door opener portion last night. Thanks for a well done instructable! Today, I am adding motioneye to use the camera as a way to see if the door is open or not. Still working on that last part.</p>
<p>Do you atttach new wires from the terminals on the garage motor to the pi or do you use the ones coming from the opener on the wall?</p>
<p>Which wires do you attach to the relay, the ones on the garage door motor or the opener on the wall?Also, do you need more wires to connect the pi to the garage door motor again since you are going between the connection of the door opener on the wall to the motor?</p>
Has anyone written a .php and code for the ability to control both relays? As in dual garage buttons?
<p>I also would like to have this possibility. The .php and java script are written in comments somewhere below. The last and only problem I have is changing the start up script to initialize the additional pins. I was working on that four hours with no luck. I have two buttons on my web site and both working only on first relay. </p><p>Can anyone post changed script to work with second relay?</p>
<p>Are you using your buttons to execute a python script IE: Garageleft.py and Garageright.py? </p>
<p>I am using only one script which starts automatically on start up. I believe one script is enough. I just didn't changed as I should to work with second relay and I have no idea how to do it.</p>
<p>I just found out that I've done mistake in .php. Now everything works fine and thanks to comments below adding new relays is very easy. Thanks!</p>
<p>Great! Did you add a line to set the GPIO pin that was on the second relay to high, then low to get everything going?</p>
<p>I just added lines</p><p>/usr/local/bin/gpio write 2 1<br>/usr/local/bin/gpio mode 2 out</p><p>in start up script. You also have to change .php and java script file. Srungi posted them in comments.</p>
<p>Can you please give some more details on the web page? can you upload the code for the web page? I am using html css and javascript to create the web page but still I'm unsure how to control it.</p>
<p>All of the webpage information (including the zip file with the entire web page contents) are in step 4.</p>
<p>BASE HOME AUTOMATION KIT</p><p><a href="http://www.ebay.co.uk/usr/raspberry-solutions?_trksid=p2047675.l2559" rel="nofollow">http://www.ebay.co.uk/usr/raspberry-solutions?_trk...</a></p>
<p>BASE HOME AUTOMATION KIT</p><p><a href="http://www.ebay.co.uk/usr/raspberry-solutions?_trksid=p2047675.l2559" rel="nofollow">http://www.ebay.co.uk/usr/raspberry-solutions</a></p>

About This Instructable


231 favorites


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