Instructables
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 85Next »
Panais953 days ago
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???
Panais953 days ago
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???
jeff.cartwright.562 made it!24 days ago

I did the happy dance too! As a newbie, I documented everything I did and ended with 27 steps. I added several new steps and expanded on the ones I did understand. It took 3 weekends, but only part-time. Most of the time spent was documenting all of the steps (and about 3 hours typing in the wrong command, expecting a different result). Many of the new steps were just setting up the Raspberry Pi.

One addition was improving the UI, see image. I used paint to add the Raspberry Pi logo to a Genie opener. The Raspberry Pi logo lights up when the button is pushed.

Other additions are: #19 add dynamic DNS, so I don't have to remember the IP address; #21 generating two way self signed SSL certificates; #22 installing client-side certificates on an android, apple or PC/MAC browser; #23 blocking all ports on the Raspberry Pi; and #24 disabling port forwarding on the wi-fi router. These steps prevent anyone on the internet from opening your garage door, while eliminating the need to enter a password.

remote-press.jpg

Hi jeff.cartwirght.562,

I am interested in your setup, especially the certificates for authentication. I feel like I saw your project somewhere before but cannot find it now. Is your project published anywhere or would you mind sharing it?

Thanks!

This was the best source: MakeThenMakeInstall. And here is a cut-and-paste from my version. Items in angle brackets should be replaced with your values. For example, <Raspberry Pi IP> = 192.168.1.76

Step 25: Creating server/client certificate pair using
OpenSSL

SSL facilitates encryption and trust allowing a web browser to validate
the authenticity of a web site. However, client SSL certificates can be used to
authenticate a mobile or laptop device to a web server.

A server/client certificate pair prevents unauthorized users from
opening the garage door. For a client device to open the garage door, it must
have the client certificate installed.

Also, you might to create a unique client-side cert for each device or
user, which would allow you to revoke a license at a later date.

Open a
terminal window on the Mac (I used a MacBook, but any computer is fine) and login

$
ssh pi@<Raspberry Pi IP>

login:
<Password>

Generate
Certificate Authority (CA)

Before creating server/client
certificate, setup a self-signed Certificate Authority (CA), which can be used
to sign the server/client certificates. Once created, the CA cert will act as
the trusted authority for both your server and client certificates (or certs).

$ sudo openssl req -newkey
rsa:4096 -keyform PEM -keyout ca.key -x509 -days 3650 -outform PEM -out ca.cer

pass phrase = <Password>

Generates: ca.cer, ca.key

Generate
Apache server SSL key and certificate

Generate server.key:

$ sudo openssl genrsa -out server.key 4096

Generate a certificate generation request.

$ sudo openssl req -new -key server.key -out
server.req

Use the certificate generation request and the CA
cert to generate the server cert

$ sudo openssl x509 -req -in server.req -CA ca.cer
-CAkey ca.key -set_serial 100 -extensions server -days 1460 -outform PEM -out
server.cer

Clean up – now that the cert has been created, we no
longer need the request.

$ sudo rm server.req

Install the server certificate in Apache

Copy the CA cert to a permanent place. We’ll need to
specify our CA cert in Apache since it is a self generated CA and not one that
is included in operating systems everywhere.

$ sudo cp ca.cer /etc/ssl/certs/

Copy the server cert
and private key to permanent place.

$ sudo cp server.cer /etc/ssl/certs/server.crt

$ sudo cp server.key /etc/ssl/private/server.key

Activate the SSL module in Apache.

$ sudo a2enmod ssl

Activate the SSL site in Apache

$ sudo a2ensite default-ssl

Disable the HTTP site

$ sudo a2dissite default

Edit the config file for the SSL enabled site and add
the lines below:

$ sudo nano /etc/apache2/sites-enabled/000-default-ssl

SSLCACertificateFile /etc/ssl/certs/ca.cer

SSLCertificateFile /etc/ssl/certs/server.crt

SSLCertificateKeyFile /etc/ssl/private/server.key

Apply the config in Apache.

$ sudo service apache2 restart

Right now if you visit your https site, you will get
an SSL error similar to “SSL peer was unable to negotiate an acceptable set of
security parameters.” That is good – it means your site won’t accept a
connection unless your browser is using a trusted client cert. We’ll generate
one now.

Generate a private key for the SSL client.

$ sudo openssl genrsa -out client.key 4096

Use the client’s private key to generate a cert
request.

$ sudo openssl req -new -key client.key -out
client.req

Issue the client certificate using the cert request
and the CA cert/key.

$ sudo openssl x509 -req -in client.req -CA ca.cer
-CAkey ca.key -set_serial 101 -extensions client -days 365 -outform PEM -out
client.cer

Convert the client certificate and private key to
pkcs#12 format for use by browsers.

$ sudo openssl pkcs12 -export -inkey client.key -in
client.cer -out client.p12

[SKIP for now] Clean up – remove the client
private key, client cert and client request files as the pkcs12 has everything
needed.

$ sudo rm client.key client.cer client.req

Step 26: Add Client-side certificate to devices

Lastly, import the .p12 file into your browser.

To copy client.p12 from the Raspberry Pi to a Mac,
open a terminal window and enter the command:

scp pi@<Raspberry Pi IP>:client.p12
/Users/<your MacBook username>

Double click the file to import into the operating
system’s keystore that will be used by IE and Chrome.

For Firefox, open the Options -> Advanced ->
Certificates -> View Certificates -> Your Certificates and import the
certificate.

For Android phones, the browser must be Chrome.

Email client.p12 as an attachment

Open the email on the Android phone and save the
attachment to downloads

Go to home screen and open settings

Security

Credential Storage

Install from device storage

Open the client.p12 file

Enter passphrase: <Password>

Use the awful, default name

For Apple phones, email the cert and double click on it,
then follow the directions.

Email client.p12 and ca.cer as attachments

BobB89 days ago

am I able to use a raspberry pi type B or does anyone know where to find type A. I am new to this and am unable to find where you purchase the type A.

JamesK617 days ago

Great instructions!
I did have an issue where the relay would just stay on after pressing the butotn (constant red light) and I couldn't get the button (or even the physical garage buttons) to work again without manually entering "/etc/init.d/garagerelay start" into my ssh session with the pi. I'm not sure if this is just because I have a very old garage door opener or what, but I fixed this by editing the php to this -


exec('gpio -g write 4 out');

usleep(1000000);

exec('gpio -g write 4 in');

exec('/etc/init.d/garagerelay start')

;

after that, it worked like a champ!

scott-w1 year 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
dhankins3 scott-w11 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)  dhankins311 months ago
(removed by author or community request)
quartarian (author)  quartarian11 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)  dhankins39 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/

Call me silly, but i followed all that "relative path" stuff, still broken.

I've got my light tied to GPIO 6 and the opener on GPIO7.

As soon as i place into sub-folders, even after changing paths, it does not work.

This is a simple thing i am sure... can you clearly identify ALL CHANGES needed to make a system that looks like this work:

/opener/index.html

/light/index.html

I changed the "/?trigger" in index.html and script.js, removing the leading "/" - still broken.

I can only make this work for one or the other . it has to stay in the root folder and only way to make the light work is to edit the GPIO # from 7 to 6.

HELP! i want my light to work.

scott-w rfc7911 month ago

Hello,

I am not totally sure. But your issue could be the / in front of each directory/sub-folder. It maybe trying to look for then under / ( root directory ) and not current directory.

I am also going to hook up my light of these days.

scott-w

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");

quartarian (author)  scott-w1 year ago
Hello Scott,

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

-Matt
rfc791 made it!1 month ago

Now to get it to work in SUBFOLDERS! GRRRRR i got a second relay i can trigger my light with, but this thing is not happy anywhere but root.

GaragePi.jpg
OsirisV1 month ago

Great tutorial. Quick question. Everything is working fine but it appears that the Genie series 3 openers don't activate by shorting out the wall opener pins. Has anyone seen this. Will I have to connect my relay to the PCB of the wall control?

Thanks

joeoz2 months ago

I have wired up my Raspberry Pi to the first module of my Songle relay board. When I click on the big button on the web page I can hear a clicking noise on the relay and see the red led light up. Unfortunately I am having a hard time figuring out how to wire up the relay to the PCB on my garage remote. I have figured out the switches on the remote which trigger the garage door open but I am struggling to find the solder points on the back of the PCB where I can solder my wires to.

Also can I use CAT 6 wires to wire the relay to the remote?

My garage door is Gliderol and I have attached pictures. Can some one please guide me on how to get this right. Many thanks in advance!

Remote_Front.JPGRemote_Back.JPGGarageDoor_Relay.jpg
al_carr2 months ago

Poop.

Great idea,, been looking for something practical to do with one of my Pi's. I cycle a lot and this will eliminate the need to carry an opener or park outside and run inside to close the door... all this after trying to call a head and not have my wife or daughter answer either their cell phones or the home phone.

Got it all setup but the webpage doesn't seem to want to trigger the relay.

Tested using cli, "gpio" command work to toggle GPIO7 up and i can hear the relay clicking.

Using the web page I get the big button but when i press it nothing happens. Monitoring GPIO7 it stays high when I click the big button.

Not sure how to troubleshoot this further. Any ideas of what I might have done to mess this up. :-)

thanks,

Al

al_carr al_carr2 months ago

I've implemented a work around by putting in a script that toggles GPIO 7 for 1 second and then put that script in my .bashrc. So all I have to do is open my SSH app on my phone and select my raspberry pi the door opens.

Still would like to know how to trouble shoot the original issue for the learning experience if anyone has ideas.

thanks,

Al

ErikF22 months ago

Don't know the specifics but the jquery.min.js in the zip file wouldn't work with my IOS 8.02. Hence I deleted that line and replaced with the google api of <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> worked like a charm after that.

AndrewD42 months ago

I followed the instructions almost to the T, and it worked awesome. When the door first opened I did the happy dance. I purchased some female to female breadboard jumpers for making the connection to the relay that worked great. Thanks for this instructable!

kpfeif3 months ago

Hi. Thanks for this great writeup...I hope somebody can solve a little problem I'm having.

I have the Model B, Rev 2 PI. I've added the script to init.d as indicated, but alas, the web interface will not trigger the relay. If I SSH into the PI and manually run /etc/init.d/garagerelay start 7 and then run the gpio write 7 1 (or 0), the relay switches just fine. There's got to be something either wrong with the startup script or the gpio commands within index.php. I've set the parms in both to 7, which does work when I issue commands directly.

Permissions problem, perhaps? I don't have to run gpio... from any specific directory, so I wouldn't think it's a path problem.

kpfeif kpfeif3 months ago

I answered my own question. The problem was with how I locked the web page down with .htpasswd and permissions. I didn't set up the user ID for pi in htpasswd. I simply added a new htpasswd for the user "pi" and it works just perfect. Now all I have to do is hook it up to the door tomorrow. I'm also going to add another webpage and gpio output to drive the second relay so I can close my second garage door.

flowin1193 months ago

alright so I am new to this as well and I have everything setup correctly but now I am unsure of how to actually make this open the garage door. Any assistance would help, thanks in advance and sorry for the noob question.

quartarian (author)  flowin1193 months ago

Most garage doors a triggered by shorting two terminal points. Once you find those terminal points on your garage door motor, you wire the relay to them.

doniel_73 months ago

I am new to instructables and cannot find the

GarageOpener.zip file download? Where can I get this file?

Idk if you found it yet @Doniel_7 but its at the bottom of step 4. There is a link that will download it.

I'm lost too, can't find the file.

thank you.

quartarian (author)  Fefetron3 months ago

As flowin mentioned, it is at the bottom of step 4. Here is a direct link though:

http://www.instructables.com/files/orig/FAO/O1ZT/HMMFCJE7/FAOO1ZTHMMFCJE7.zip

torvaga made it!4 months ago

Nice writeup, and easy to follow. I had to swap the GPIO from 7 to 4 and then it worked like a charm (Got a Rev B 512 Pi). Having an issue with my WiFi i assume, because it doesn't work each time. I'll try to wire connect with TP before I come naging around here again. Great work man! =)

2014-08-08 18.04.52.jpg
PeteK24 months ago

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!6 months 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
duboisvb6 months 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?

duboisvb duboisvb6 months ago

sorry, I figured it out . on to step 5

koaster made it!6 months 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
the720k made it!8 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
1-40 of 85Next »