Instructables

Raspberry Pi Garage Door Opener

Picture of Raspberry Pi Garage Door Opener
breadboard.jpg
psu.jpg
relay.jpg
wifi.jpg
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.




 
Remove these adsRemove these ads by Signing Up
1-40 of 61Next »
troy.stanway18 hours ago

Hey I can get it working fine on GPIO 4 (7)..

But when I try to change the pin, I tried all the suggestions above and can't get it working on another pin? Help anyone?

PeteK2yesterday

Worked great for me. I even ziptied like the picture. Two caveats:

1) I postponed step 6 at first because it seemed like it wasn't necessary to test basic functionality. However, the "gpio write 7 out" was crucial; nothing happened until then.

2) 'gpio reset' hangs/crashes the pi. Any ideas?

i90m00 made it!1 month ago

Great guide! This provided the basis for my implementation. Thanks for the easy read, nice diagrams, and handy reference links. The only real difference with mine is that I chose to use webiopi (https://code.google.com/p/webiopi/) to access my GPIO pins through a RESTful interface. Then, I wrote C# wrapper classes around the REST calls so that I could consume the garage door functionality through an ASP.NET MVC application. I'm planning on implementing Google OAuth2 for authentication, so people I choose can sign in to the door opener with their Google accounts. :) Will post again when I get that part finished. Lastly, I also implemented door status monitoring using this guide: http://www.richlynch.com/2013/07/27/pi_garage_aler... Works great! I drilled holes in the top of the project box for ventilation, but I will continue to monitor the inside temperature as the months get hotter. Right now the CPU hasn't gotten above 55ºC at an outside temperature of 85ºF, but I will post again if the temperature ever becomes a concern with this design; the maximum CPU temperature is supposedly around 70ºC. Thanks again for the guide!

-Daryl

IMG_20140618_214947.jpgIMG_20140618_215008.jpgIMG_20140619_000822.jpgIMG_20140619_000842.jpgIMG_20140619_000852.jpg
duboisvb1 month ago

hello,

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 "Garage Opener" . I am not sure what to try . Can you advise me?

sorry, I figured it out . on to step 5

koaster made it!1 month ago

Great write up! Very inspiring. I read it for the first time about a week ago and have since completed the project! I did make a couple changes. First, I'm a Java programmer, so I replaced Apache and Python with Tomcat and Java. I also made use of the pi4j library. I found that I did not need the startup service you described. I was able to initialize the pin to HIGH/ON from application code without the relay activating too soon. Finally, rather than a website, I opted to expose a web service that I could integrate into an existing home automation application.

One thing that worried me was the fact that my opener has a wall panel with 2 buttons. One for door up/down and one to control the light on the opener. There is also a lock switch that disables the car remotes. All of these controls use the same two wires. I wasn't sure what would happen when I connected the relay to the opener. To test it out before hand, I shorted out the terminals that connect to the wall panel. The door activated, so I knew the relay should work and turns out it works just fine.

IMG_20140610_180626.jpg
scott-w8 months ago
Hello,
Thank you for the how to. Had to change a little to get it work for me.
Needed to move wire going to ping 7 to ping 12 ( GPIO 18 ). Had to update/change
garagerelay and index.php with
gpio -g write 18 1
gpio -g mode 18 out

I have also added to website, click-able video feed use to open/close door.
( not to good of local network.
Further plans:
lights switch from raspberry
door senor
add video from raspberry with motion detector

can you provide link, or code for clickable video feed?

Change the background line in the sytel.css file to

background-image: url("http://admin:password@192.168.1.24:1520/videostream.cgi");

dhankins3 scott-w6 months ago
I also had to modify for GPIO 4:
exec('gpio -g mode 4 out');
usleep(1000000);
exec('gpio -g mode 4 in');

It worked great named as "index.php" in the root of www, but I am working on other apps as well, so I would like to move into a subfolder (ie "garageopener"). When I move the files/folders, the page will load, but the relay no longer works. I'm a newbie, so I'm sure I've missed something stupid. Any suggestions? Thanks!
quartarian (author)  dhankins36 months ago
(removed by author or community request)
quartarian (author)  quartarian6 months ago
When you changed the code, you had to also change the physical pin you wired the relay to right? (I just want to make I did't mess up the diagram.)

Also, to fix the issue with the index.php file not being in the root directory, change line #24 from:

href='/?trigger=1'
to
href='?trigger=1'

That should do the trick.
quartarian - That is correct, I changed the physical pin i wired to the relay. Thank you for the quick response. I want to clarify that I also tried to move the "index.php" to this subdirectory named "garageopener", in addition to the other files. Though I made the change you suggested:
href='/?trigger=1'
to
href='?trigger=1'
I'm not having any luck. Unless you have another suggestion, I may just leave this as is, and try moving my other projects to subfolders (or use other names instead of "index".php. Thanks! Also, great work - my son and I gained a lot of knowledge based upon your work.
quartarian (author)  dhankins35 months ago

Hey Dhankins,

Sorry to leave you hanging. First off, I think it is super cool that you worked on this with your son. I hope I can do that with my future child.

Now about the problem - it's just a problem with the paths. The way I wrote it, all of the paths assume you are in the root directory. I was wrong about only changing the index.php file though. You need to change the other files as well (which I forgot about.)

Here is a quick primary that should allow you to understand what you need to change:
http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

quartarian (author)  scott-w8 months ago
Hello Scott,

I'm glad it worked for you! What code did you use for the clickable video feed?

-Matt
the720k made it!3 months ago

Excellent Instructable. I just finished setting up and installing my unit. We only have one remote garage door opener between the wife and I, and I have lost track the number of times I've had to drive back home at lunch to close the door I left open. Works perfectly, though I'm going to set up motion in a few days and point a webcam at the door so I can be sure it's closed.

Works perfectly on my Model B rev.1 board. I skipped the wifi adapter and just ran an Ethernet cable over to the DD-WRT router that I use as a repeater for the garage. GPIO 7 worked just fine, and this whole project went very smoothly. I had everything but the relay already on-hand, so this turned out much cheaper than buying a new opener, and a heck of a lot more convenient. Thanks again for a great how-to!

pi-garage-opener.jpg
the720k the720k3 months ago

Update: I've been using this thing daily for the past week, and it has been awesome. Super reliable and very handy. It's so nice to not have to go out to the car at night and close the garage door. One day last week, my wife called me at work and told me I had left it open. I have a point-to-point VPN between work and home, so I just pulled out the smartphone and closed it immediately. So nice. Still haven't gotten around to throwing the webcam into it, but I plan on doing that this afternoon.

jkaipa4 months ago

Relay to my garage unit doesn't seem to work. When I send signal to close the garage, I see the LED functioning on the relay unit, but no action.

Garage: Marantec 4500e

I tried with terminal 3 and 4 but no use. Nothing happens when you close the circuit. It seems the wall unit toggle button have some PIR functionality. Not sure how to handle. Please help.

wallstation__30092__92877.1372571955.1280.1280.jpg
quartarian (author)  jkaipa4 months ago

Hmmm, when the LED triggers, do you hear an audible click? When the relay triggers successfully it's actually pretty loud. If you see the LED light change but don't hear a click, either the relay is bad, it requires more than 5 volts, or your usb power adapter is'nt strong enough.

As a shot in the dark, I suspect it's the latter and you need a better charger.

jkaipa quartarian4 months ago
Thanks for your response Quartarian.

I did not hear any audio click. I am unsure if the 5 volts is being passed. Is there a specific recommendation on the input power voltage in my situation?

Thanks
quartarian (author)  jkaipa4 months ago

Well the power supply (aka cell phone charger) should probably be rated around 850mA or higher. If you have other ones for your cell phone I would try some gues and check.

jkaipa quartarian3 months ago

Thanks Quartarian. Your suggestion helped and its running great now.

appgaer5 months ago

Hi quartarian! This looks great!

Was wondering if you could help me :)

My garage door opener operates somewhat differently - it has 2 terminals which control both the door and the light. How can I set this up to work with it?

Here's the manual for it:

http://www.marantecamerica.com/pdfs/80400M4500eM47...

jkaipa appgaer4 months ago

Any luck with terminal 3 and 4?

appgaer jkaipa3 months ago

Yes! 3 and 4 did the trick!
Thanks guys!

jkaipa appgaer3 months ago

You are all really brilliants ---Thank you.

It worked.

quartarian (author)  appgaer5 months ago

Hello Appgaer, it looks like terminal 3 and 4 should do the trick. To test it, I would just try and short the connectors. If you garage door opens, than those are the right ones.

~Disclaimer~
If it breaks, no suing ;-)

tb55chevy3 months ago

I am looking at building one of these. Can it give me a display if I put in a switch to read if the door is open or closed and wire in somehow?

jnmoore4 months ago

Hi, I'm a newb trying to follow along... I purchased the parts but I'm having difficulty getting it all running. I just have some basic questions:

1) Do I need to adjust any Apache permissions to make this work?

2) Based solely on the comments here people seem to be conflicted on whether or not "exec('gpio write 7 0');" is the correct initialization for pin 7. Is the original index.php file given okay or does it contain typos?

3) If all else fails, is there a simple way to test if my relay even works or not? I'd hate to be wasting my time (and yours!) on a dead relay.

Thanks!

achild14 months ago

Hi quartarian,

This worked with no issues for me. What a great tutorial, and an
awesome project. I am seriously impressed. The only thing I would change
is the 777 permissions. You can make it executable without giving up
the farm. You can do a chmod +x /etc/init.d/garagerelay. This will make
it world executable, but not world writable. It may also make people
feel a little bit easier about it. Other than that no complaints. Works
excellent.

Thanks so much. This was not only cool for me, but much needed!!

Mike

revesm5 months ago

Thank you for this instructable. I was able to get it up and running in less than 2 weeks from the day I got my Raspberry Pi. I added SSL using OpenSSL and an Authentication Screen to my webpage and frankly, that is what took me most of the time. For those of you wanting to do the same, don't try to put your .htpasswd or .htaccess files in /var/www because Apache2 doesn't seem to like it. I created a new directory, created the files and then gave Apache2 access to the directory. I used Single User signon in Apache2. You'll then have to direct port 443 or 8443 to your Raspberry Pi from your router.

jadams435 months ago

I am trying to us these step to make a three button garage door open the button are up, down, and stop I am new to program the raspberry pi and was wondering if you could help me figure it out and I would like to be able to turn a light on to

rgviewer5 months ago

I am trying to do this and but don't know if I did something wrong. When I go to the ip address on my phone I just get this big grey button across the screen. I thought it was supposed to be a web site that looked like a genie garage door opener. Not sure if this is right or not. I am viewing on an android phone if that matters. Also I am using raspberry model B so I assume the gpio pins are different.

quartarian (author)  rgviewer5 months ago
Nope that is right. I was lazy with the interface lol. fgomes7 implemented what you are looking for though. He might be might give you his css if you ask nicely.

Here is the documentation for the pins:
http://wiringpi.com/pins/
mwolfson106 months ago

Works like a charm!!! Installed on 1/9/14. Total time for me was about two weeks. Had to also switch Pin 7 to GPIO 4. Other than that, your instructions were invaluable.

quartarian (author)  mwolfson105 months ago

Congrats! I'm glad it worked for you :-)

Srungi6 months ago

it's done :-) now with control button's for the 8relay.... here are my index & js
first the light go on then the door open ;-)

<pre>
<?php

if(isset($_GET['trigger']) && $_GET['trigger'] == 1) {

error_reporting(E_ALL);

exec('gpio write 2 0');

usleep(1000000);

exec('gpio write 2 1');

exec('gpio write 8 0');

usleep(1000000);

exec('gpio write 8 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 2) {

error_reporting(E_ALL);

exec('gpio write 2 0');

usleep(1000000);

exec('gpio write 2 1');

exec('gpio write 9 0');

usleep(1000000);

exec('gpio write 9 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 3) {

error_reporting(E_ALL);

exec('gpio write 2 0');

usleep(1000000);

exec('gpio write 2 1');

exec('gpio write 7 0');

usleep(1000000);

exec('gpio write 7 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 4) {

error_reporting(E_ALL);

exec('gpio write 2 0');

usleep(1000000);

exec('gpio write 2 1');

exec('gpio write 0 0');

usleep(1000000);

exec('gpio write 0 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 5) {

error_reporting(E_ALL);

exec('gpio write 2 0');

usleep(1000000);

exec('gpio write 2 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 6) {

error_reporting(E_ALL);

exec('gpio write 3 0');

usleep(1000000);

exec('gpio write 3 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 7) {

error_reporting(E_ALL);

exec('gpio write 12 0');

usleep(1000000);

exec('gpio write 12 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 8) {

error_reporting(E_ALL);

exec('gpio write 13 0');

usleep(1000000);

exec('gpio write 13 1');

}

else if(isset($_GET['trigger']) && $_GET['trigger'] == 9) {

error_reporting(E_ALL);

exec('gpio write 14 0');

usleep(1000000);

exec('gpio write 14 1');

}

?>

<!DOCTYPE html>

<html>

<head>

<title>Garage</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />

<script src="http://xxxxxxxxxxxxxxxxxxx.de:81/videostream.cgi?user=rasp&pwd=rasp&resolution=8&rate=3" style="width: 300px; height: 220px;" >


<div>

</div>

<div data-role="footer">

<h4>by Srungi</h4>

</div><!-- /footer -->

</body>

</html>
</pre>

<pre>

$(document).ready(function() {

$('a#G1').click(function(e) {

e.preventDefault();

$.get("/?trigger=1");

});

$('a#G2').click(function(e) {

e.preventDefault();

$.get("/?trigger=2");

});

$('a#G3').click(function(e) {

e.preventDefault();

$.get("/?trigger=3");

});

$('a#G4').click(function(e) {

e.preventDefault();

$.get("/?trigger=4");

});

$('a#Light').click(function(e) {

e.preventDefault();

$.get("/?trigger=5");

});

$('a#B').click(function(e) {

e.preventDefault();

$.get("/?trigger=6");

});

$('a#B1').click(function(e) {

e.preventDefault();

$.get("/?trigger=7");

});

$('a#B2').click(function(e) {

e.preventDefault();

$.get("/?trigger=8");

});

$('a#B3').click(function(e) {

e.preventDefault();

$.get("/?trigger=9");

});

});
</pre>

IMG_1195.JPG
quartarian (author)  Srungi5 months ago

Awesome! Good work Srungi.

Srungi7 months ago
....Then it's only changing the php and script to more 3 buttons.

That's my problem ;-)
quartarian (author)  Srungi6 months ago
Hello Srungi, I'm glad everything worked for you! You will need to do three things to add additional ports:

1.) Wire the additional GPIO pins the the relay obviously ;-)
2.) Change the start up script to initialize the additional pins
3.) Edit the index.php file to give you extra buttons as fgomes7 mentioned. 

Here is a simple framework for that, though I'll leave the CSS to you.
<pre>
<?php
        if(isset($_GET['trigger']) && $_GET['trigger'] == 1) {
                error_reporting(E_ALL);
                exec('gpio write 7 0');
                usleep(1000000);
                exec('gpio write 7 1');
        }
        else if(isset($_GET['trigger']) && $_GET['trigger'] == 2) {
                error_reporting(E_ALL);
                exec('gpio write 1 0');
                usleep(1000000);
                exec('gpio write 1 1');
        }
        else if(isset($_GET['trigger']) && $_GET['trigger'] == 3) {
                error_reporting(E_ALL);
                exec('gpio write 2 0');
                usleep(1000000);
                exec('gpio write 2 1');
        }
        else if(isset($_GET['trigger']) && $_GET['trigger'] == 4) {
                error_reporting(E_ALL);
                exec('gpio write 3 0');
                usleep(1000000);
                exec('gpio write 3 1');
        }
?>
<!DOCTYPE html>
<html>
        <head>
                <title>Open Garage Doors</title>      
                <script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>   
                <script type="text/javascript" src="/js/script.js"></script>
        </head>
        <body>

                <a href='/?trigger=1'>
                  Door #1
                </a>
                <br/>
                <a href='/?trigger=2'>
                  Door #2
                </a>
                <br/>
                <a href='/?trigger=3'>
                  Door #3
                </a>
                <br/>
                <a href='/?trigger=4'>
                  Door #4
                </a>                               
                <div class="iframe">
                </div>
        </body>
</html>
</pre>
1-40 of 61Next »