Introduction: Raspberry Pi Garage Door Opener

Picture of Raspberry Pi Garage Door Opener

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)

Picture of 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

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.

Step 2: Setup Wifi Via the Command Line

The next step is to setup your wifi from the command line. This will allow us to control the pi remotely via ssh.

Here is a great guide for Wheezy:

Since we are using the Model A with only one usb port, you will need to set up the configuration with your keyboard, shutdown the pi, insert the Wifi Dongle and then start it backup. This may take a little guess and check.

The command to shutdown the pi is: sudo shutdown -h 0

If all goes well, once you set it up and reboot, your pi will be given an IP address by your router. You can find this IP address by either hooking the pi up to an hdmi monitor and looking at the boot log, or logging in to your router and looking at the DHCP table.

Step 3: Install Software

Now that we have the wifi setup, we are going to download and install the necessary software to our pi. Since our usb port is now being used by the wifi dongle, we will do this via ssh.

If you are using Ubuntu, open up the terminal and type ssh pi@[Your Pi's Ip address]. If you are using Windows, you can download Putty. On OSX, you can also just ssh from the terminal. Again, the default password on Wheezy is raspberry.

Once your a logged in, download, compile, and install Wiring Pi. This software allows us to control the GPIO pins on the pi. Here is a step by step guide for that:

Once Wiring Pi is installed, you will want to install Apache and PHP via these commands:

$ sudo apt-get update
$ sudo apt-get install apache2 php5 libapache2-mod-php5

Once this is done, you will have a working webserver! To verify that, just type in your pi's ip adress in a browser. You should see Apache's default website which says "It Works!".

Step 4: Upload the Garage Opener Website

Picture of Upload the Garage Opener Website

Now that we have a working webserver, we are going to upload a website to it. I've created a very basic one that will trigger the relay we will wire in the next step.

Here are two ways to do that:

Dowload the to your desktop. Open up your terminal, and type the following commands:
$ sudo rm /var/www/index.html
$ sudo chown pi:root /var/www
$ exit
$ cd ~/Desktop
$ scp pi@[YOUR PI'S IP ADDRESS]:/var/www
$ cd /var/www
$ unzip
$ rm

Any OS
Download Filezilla. Using Putty or another ssh terminal:
$ sudo chown -R pi:root /var/www

Start filezilla. Log into the raspberry pi with these credentials:
Host: sftp://[YOUR PI'S IP ADDRESS]
Username: pi
Password: raspberry

Then upload all of the files from to /var/www. Also, delete the existing index.html.

Some Technical Notes (for those interested):
The website uses jQuery to post to itself (via AJAX) when a user clicks on the big button. I did this so that if you refresh the page it doesn't trigger your garage to open.

If your using an iPhone (or the latest dev version of Chrome on Android) and add this website to your home screen, it should work like an app without the browser chrome. (It will still only work when your on your home wifi though :-P )

Step 5: Wire the Circuit to the Pi!

Picture of Wire the Circuit to the Pi!

Now for the fun part - we wire the relay to the pi! For the code I provided (step 4 and 6) I used GPIO pin 7. You can use whichever one you want, but be sure to change the code.

Below is a diagram and my wired pi mounted on cardboard with zip ties. I used an old floppy disk ribbon cable for easy testing of ports and just left it connected.

Step 6: Create a Startup Service

Picture of Create a Startup Service

This step is important.
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. So what happens if your pi looses power? Well most relays have a safety mechanism that keeps the circuit OFF when there is no power at all. The problem that occurs happens between when the pi (and subsequently the relay) gets its power back but before the pi has finished booting to turn the signal ON which is need to keep the circuit off. You could wake up in the morning with your garage open and potentially a few new friends!

After some experimenting, I found a simply work around. I found out that my relay doesn't actually initialize until the GPIO pin mode is set via this command: gpio mode 7 out. Furthermore, I found out that it you set the GPIO pin to ON (gpio write 7 1)before you set the GPIO mode, the relay will stay off once initialized.

To make this initialization run at boot, I created a start-up script.

$ ssh pi@[Your Pi's IP]
$ sudo nano /etc/init.d/garagerelay

Then paste this script:
#! /bin/bash
# /etc/init.d/garagerelay

# Carry out specific functions when asked to by the system
case "$1" in
echo "Starting Relay"
# Turn 7 on which keeps relay off
/usr/local/bin/gpio write 7 1
#Start Gpio
/usr/local/bin/gpio mode 7 out
echo "Stopping gpio"
echo "Usage: /etc/init.d/garagerelay {start|stop}"
exit 1

exit 0

Make the file executable:
$ sudo chmod 777 /etc/init.d/garagerelay

Now tell your pi to run this script at boot:
$ sudo update-rc.d -f garagerelay start 4
(Note: You can safely ignore the "missing LSB tags" warning.)


Step 7: Attach Raspberry Pi to the Garage

Picture of Attach Raspberry Pi to the Garage

This part is very easy. Just follow the wires of the button attached to your garage motor and attach the relay the same way. Since the relay isolates the circuit, the direction doesn't even matter.

And you're done! Let me know it works for you.


av8ndad (author)2017-05-28

Thanks for the excellent documentation and instructions. I made this yesterday using a Raspberry Pi 3, but I am now thinking of modifying the set-up to use a Pi Zero W, since this set-up really doesn't require much horsepower. Has anyone else done that?

I also modified the overall set-up a little bit by setting up a static ip using port forwarding on my Google WiFi and the no-ip service so that I can access the opener from anywhere. I have a Smart Things hub at my house, so I can sense whether the garage is open or closed, then I can use this RasPi set-up to open or close it when I want to.

I do have three questions:

1. How can I modify the UI with a photo or some other more interesting graphic than just a plain gray box? I'm not well-versed in CSS, and I am guess that it is all in the awrap div. Can anyone lead me in the right direction?

2. I'd like to also modify the code (and the UI) to allow me to control two garage doors. I'm sure someone has done it, so I'd be interested in the code and UI mods.

3. Now that the Pi is essential an IoT device, has anyone modified the code to put a password or other security in the system? We don't want some script kiddie opening and closing our garage door after finding the Pi while looking for devices.


JoshJ73 (author)av8ndad2017-10-02

Recently, I made a similar device. The biggest difference is that I programmed a python script that connects to an mqtt server. It listens for commands sent via mqtt. I have a button on my smart phone that can operate the device and it is also connected to my amazon echo so I can say "Alexa, ask garage Door to open." And it opens.

One benefit to using the mqtt method is that you don't have to worry about forwarding ports or opening the firewall. mqtt works in a sub/pub model. the pi subscribes to the server, the other devices publish to the server.

If anyone is interested I do have all this packaged in a .deb so you just install it, modfiy a couple lines in the .conf script and you are ready to go!

IsraelI8 (author)JoshJ732017-12-13

Definitely interested in this!

kroci (author)av8ndad2017-08-07

I am trying to make this with a Zero W right now but the website does not trigger the relay properly. I know the relay works because I tested it with a python script but for some reason nothing is happening with the web trigger. Did you come across this issue?

ShunY1 (author)2015-12-30
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.

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?

tulsa_jerm (author)ShunY12016-03-07

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 "high" or "low" (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.)

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 "floating". 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 "on" when it sees 0 volts (low) and "off" when it sees +3 volts (high) and your pin is "somewhere between 0 and +3" then it might be close enough to one end to turn it on or close enough to the other end to turn it off.

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 "I'm not in an output mode yet so I'm somewhere between high and low" 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 "press the button" as it were.

The way we fix this, in electronics terms, is to "pull it down" or "pull it up" with a resistor. That's the fancy term, usually a "pull-up resistor". 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 "high" or "low" (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 "turn on" 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 "write" 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 "floating?") so that resistor prevents the float.

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).

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?)

If the pi uses 5 volts on it's GPIO (but I think it is 3) then change every +3 above to +5! :)

ShunY1 (author)tulsa_jerm2017-06-10

Thank you for your explanation. It feels a little complicated, I will try to digest it.

jeff.cartwright.562 made it! (author)2014-11-23

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.

@jeff.cartwright.562: Can you tell me how and where you added the code for the UI image? I want to do the same thing to get rid of the dull gray box.

The comment editor doesn't allow php code. So, remove the quotes and spaces from "< ? php" and "? >". This is how I added the image.

"< ? php"

if ($trigger == 0) {

echo "<td colspan=\"4\" align=\"center\"><a href='/index.php?trigger=1'><img src=\"remote-background.jpg\" alt=\"garage remote\" style=\"width:50%\"></a></td>";

} else {

echo "<td colspan=\"4\" align=\"center\"><a href='/index.php/'><img src=\"remote-background.jpg\" alt=\"garage remote\" style=\"width:50%\"></a></td>";


"? >"

Forgive my PHP ignorance, but where in the code of index.php did you insert this. I have tried dozens of combinations and all I get is either a blank page or a my garage remote image and some extraneous code on the page, none of which opens or closes the garage.

I am not sure if this got to you.

Can you send your code as an attached zip file?

I don't think quartarian's code and mine are the same. I am sending code from my project, and I assume you are plugging it in to q's. I went back and looked at a very old version of mine.

The CSS has

a {


width: 400px;

height: 400px;

padding: 0px 0 0 0;


a:active {

background: url('../remote-press.jpg') top left no-repeat;


And the PHP has:


if ($trigger == 0) {

echo "<a href='/?trigger=1'></a>";

} else {

echo "<a href='/'></a>";



Basically, the css is changing the image in the defined html element "a".

However, this probably won't work for you.

I assume you got the garage door to work without the image. Is that correct?

If not, the code associated with the trigger and the write to the gpio pin is what opens and closes the door.


$switch = exec('gpio read 3');

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


exec('gpio write 7 0');


exec('gpio write 7 1');

$trigger = 1;

} else {

$trigger = 0;



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?


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> =

Step 25: Creating server/client certificate pair using

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>


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

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

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

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

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

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

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

$ 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

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


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

kiwi_cam (author)2017-02-27

This worked great to get me started but like others I did have to tweak the code for two reasons:

1. My relay was closed by default so I had to reverse the scripts to leave to circuit open

2. I didn't have a full ribbon cable so I used GPIO 1 (pin 12) instead of 7.

Here are my resulting files in case they can help someone else get started

/var/www/html/index.php (note the corrected location):

if(isset($_GET['trigger']) && $_GET['trigger'] == 1) {
exec('gpio write 1 1');
exec('gpio write 1 0');
<!DOCTYPE html>
<title>Garage Opener</title>
<link rel="apple-touch-icon" href="apple-touch-icon-iphone.png" /><link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-iphone-retina-display.png" />
<link rel="stylesheet" href="/css/style.css" type="text/css">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/js/script.js"></script>
<div class='awrap'>
<a href='/?trigger=1'></a>


#! /bin/bash
# /etc/init.d/garagerelay
# Carry out specific functions when asked to by the system
case "$1" in
echo "Starting Relay"
# Turn 1 on which keeps relay off
/usr/local/bin/gpio write 1 0
#Start Gpio
/usr/local/bin/gpio mode 1 output
echo "Stopping gpio"
echo "Usage: /etc/init.d/garagerelay {start|stop}"
exit 1
exit 0

AndrewM559 made it! (author)2017-02-15

I modified the code so that hitting the page is all it takes to open the garage door. Then I created a task with the tasker app that lets me open the door with my phone, and also have a nice button on the home screen :)

Kyle D (author)2016-08-16

I checked my Pi's IP address after doing the apache part like mentioned and I saw the "It Works" screen. Before I brought it out and hooked up to my garage door I went to check again and am getting a Not Found error. Any ideas how to fix this?

Kyle D (author)Kyle D2016-08-22

To update a little, I went on my laptop command prompt and did a ping and am not getting any packet loss at all so it can see that I am connected to the same wifi, but still get the 404 Not Found

I have not connected it to my garage door yet, but I am assuming that would not be the cause. I suppose I could connect it to test this theory out though.

JonathanH217 (author)Kyle D2017-01-28

I have a reply above about this in more detail but basically you want to check your apache error logs:

sudo tail /var/log/apache2/error.log

And it will tell you where it is looking for your site. Make sure that your site index.php file is in the folder that the error log lists as the location that was not found.

Ok, I'm farther down the path now. I've got a Rasbian jessie image changing the value of pin 7. It seems apache by default makes it's web root in /var/www/html

Place your files such that the index.php files is in that folder and you should make some headway.

Brainbox72 (author)2016-12-29

Hi all. Didn't work for me. After I copied the files and opened the website all I got was a 404 Not Found msg. Can someone help out?

JonathanH217 (author)Brainbox722017-01-28

I haven't tried this project yet but I am a
full stack web developer. You should be able to find error logs for
apache (your web server). By default they will be located in:


You can look at the most recent errors with a text editor with something like:

sudo tail /var/log/apache2/error.log

are that it is looking in the wrong folder for your site as it is
saying that it can't find the files (404). The error log should have
some advice on what folder it is currently looking in. Once you know
where it is looking, move your stuff there (make sure that your index file is in the folder it is looking in) and it should either
find the site or give you a new error to work through :)

shermy99 (author)2016-04-19

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

s1000r2016 (author)shermy992017-01-21

Did you ever solve this, i am having the same issue

shermy99 (author)s1000r20162017-01-21


JonathanH217 (author)shermy992017-01-28

chown changes the ownership of a file or folder. In this case the command you are issuing is basically saying, change the /var/www folder (if it exists) and everything in it to be owned by the pi user and root group. If you don't have a /var/www folder, you can make it first by issuing:

mkdir -p /var/www

(make the /var/www directory and also make it's parent if they don't exist) if it complains about permissions put a sudo in front of it.

Once you have the folder, you can issue your chown command again and then you can check the results of your command by issuing:

cd /var

ls -l

Which translates to "move to the /var directory then list in long format the contents of that directory". You should see the files in and folders in the /var directory with the group and owner listed beside each item. You are hoping for the line for www to look something like this:

drwxr-xr-x 3 pi root 4096 Jan 28 2016 www

newitech (author)2017-01-05

Finally got it working :-) but had to make a few modifications. I used Raspbian Jesse and WiringPi for gpio control was already installed but was located at /usr/bin/gpio instead of /usr/local/bin/gpio so I had to modify my garagerelay file to match. I am not sure if the same thing caused my other issue but if I entered the gpio commands manually at the bash prompt it would trigger the door but the webpage button would not. I ended up making a shell script file called and making it executable and then removed the exec gpio and usleep commands and replacing it with exec("/home/pi/"); and that worked.

spaul2017 (author)2017-01-01

This may be a stupid question to ask here. I am a newbie in IoT Home Automation area. However I do have a lot of technical background, so I hope that I will be able to understand your technical jargons :)

My question is - does this solution work for garage door that's canopy up and over? If yes - can a single integrated system be used to manage both doors, but can be controlled in user's discretion (i.e one door at a time or both at a time).

Any feedback or mentoring is really appreciated.

PeteK2 (author)2014-07-30

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?

Adamrathsack (author)PeteK22016-12-06

Thank you so much for this comment! I also skipped step 6 for the same reason and couldn't figure out what I did wrong.

I will try step 6 tomorrow and see if it works!

wizhack (author)2016-11-21

Hi i follow this instructable and adapt to my case, thanks for it ;)

I have issues with power on the garage door:

-When the pi boot all is ok the door stay close but when i opened 1 or 2 times if the power is off the door (only the door) and back on the door open itself!

I did the trick with the "garagerelay" file and try to change the pin (wpi 9) and its always do the same things.

Does anybody know how can i solve my problem ?

wizhack (author)wizhack2016-11-21

i just find how to do, modify index.php and adding "safe off the relay" replace the "first php code"

if(isset($_GET['trigger']) && $_GET['trigger'] == 1) {
exec('gpio mode 7 out');
exec('gpio write 7 1');
exec('gpio write 7 0');
exec('gpio mode 7 in');

jc9566 (author)2015-04-11

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.

mrcranky (author)jc95662015-05-21

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.

pber (author)mrcranky2015-08-10

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.

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.

Anyone have any thoughts?

ChrisM263 (author)pber2016-11-04

I have this issue too, looking for a workaround

tulsa_jerm (author)pber2016-03-07

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.

tulsa_jerm (author)pber2016-03-07

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.

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.

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!!

ValentinS28 (author)2016-08-19

As kyle D, I get 404 not found error with the garage door opener website :/

WillW3 (author)ValentinS282016-09-10

does this have anything to do with the directories you are using? newer updates of apache moved the default directory to /var/www/html if I am not mistaken. I followed the instructions above and was able to get it working with only this small modification.

joshuacarroll made it! (author)2016-08-20

I had been wanting to make this project for months, and the wall switch for my garage door broke so that was my excuse to do this. I'm so excited to have a smart garage door opener. I made several tweaks to the code which can be seen on Github at Thanks for sharing your knowledge on this!

ChrisG212 (author)2016-04-17

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.

cmcconnehey (author)ChrisG2122016-06-04

I am also looking for that same status notification. Thank you in advance!

JesperR2 (author)ChrisG2122016-04-29

Hi ChrisG212,

Iam looking for the exact same functions. Any chance you could share yours ?

Thanks in advance.

ChrisG212 (author)JesperR22016-04-30

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.

SofianeM3 (author)ChrisG2122016-04-29

Oh Nice ! I'm looking for this too, can you share please ? :)

collumela1 (author)ChrisG2122016-04-18

This is exactly what I am trying to do! Could you provide any more information please ChrisG212? Any help will be great

JorisM3 made it! (author)2016-05-21

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.

Howie100 (author)2016-05-03

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.

Mine wouldn't work until I added a "-g" to the two commands in the /etc/init.d/garagerelay scripts as such:

# Turn 7 on which keeps relay off
/usr/local/bin/gpio write -g 7 1

#Start Gpio
/usr/local/bin/gpio mode -g 7 out

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 "actual" or numeric pin number.

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...

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 "just" a local web server! (Hah, that's what I said ~2 years ago too...!)

Howie100 (author)Howie1002016-05-03

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 "0", and rebooted to confirm that it worked... which it did! Thanks again, and I hope some of this helps others as well!

About This Instructable




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