Introduction: RPi Garage Door Opener for Rentals

The problem with renting a unit, is that we are unable to modify much of the furniture in the house without upsetting our landlords. But we would still like to do it, and it is possible to do a few things.

Our particular rental unit comes with a motorized garage door, but it only came with one remote to open the door when we have more than one person wanting to use it. So, we decided to hook up the garage door opener so that we are able to open it with our mobile phones, without modifying the built-in devices.

The things required:

  1. Garage door remote (make sure it works with your garage door, there are plenty on eBay)
  2. Optocoupler
  3. Raspberry Pi
  4. Router

Unfortunately, we did not take any photos during the build, so a few things might be a bit hard to see, just ask in the comments if you have any questions.

Step 1: The Optocoupler Circuit

As a quick intro for those who do not know what an optocoupler is, it is more or less like a relay switch, but instead of a mechanical relay, it uses a photodiode ( has a good explanation on how it all works). So basically instead of the original button on the remote completing the circuit, we are replacing that with an optocoupler that will complete the circuit when our raspberry pi sends a signal.

The optocoupler we've used is a the 4N35, which is a pretty standard optocoupler which you could purchase from any electronics supplier (we got ours from element14). And you can see in the image, how the optocoupler is wired.The resistor we used was 220 ohms. This resistor is there for safety, to limit any backwards voltage going into the raspberry pi.

So once you've tested that the remote works with the garage door opener, open up your remote, de-solder the button and wire it up like the schematic and that's all that's required electrically.

You can see in the other image, how it is wired on our button, we've added header plugs on our cables, so that we can easily remove them if required. If you'd like, you don't have to de-solder the button either and the remote would still work.

Step 2: Raspberry Pi Setup

Firstly, setup a php webserver on your raspberry pi. There are many i'bles and guides out there to do this. (here is one example:

Once your webserver is up and running, setup your GPIO pin. (We've decided to use pin 17 to control ours, so adjust your code accordingly.)

$ echo "17" > /sys/class/gpio/export
$ echo "out" > /sys/class/gpio/gpio17/direction

As note, you can place these commands in a startup script so that your GPIO will be setup even if your raspberry pi was restarted. This is now a good time to plug the other side of the optocoupler to your raspberry pi. (remember not to mistake the gnd and the gpio pin) Now that your GPIO is setup, test it by running this command:

$ echo "1" > /sys/class/gpio/gpio17/value

That command should have opened your garage door (and turn on the led on your remote if there is one there). To "let go" of the button, run this command:

$ echo "0" > /sys/class/gpio/gpio17/value

If all is well, we can now save these two commands into a bash script, so that it hits the button and then lets go off the button after 1 second.

echo "1" > /sys/class/gpio/gpio17/value
sleep 1
echo "0" > /sys/class/gpio/gpio17/value

Place this script into /var/www/ directory on the raspberry pi and we can setup the php command.

Step 3: PHP Setup

This step will show you how to setup a php file that will be able to receive commands from any computer, even your phone.

In your /var/www/ directory, create a file called index.php and add the below code to it.

if ($_GET['garageopen']) {
  # This code will be run when garageopen is set to true
exec('sudo /var/www/');
<form action="?garageopen=true" method="post">
    <button type="submit">OPEN</button>

Once you've saved the file, if you are on the same network as your raspberry pi, go to your raspberry pi's ip address on a browser and you should be able to see a button. When you click that button, voila, your garage door should open.

Step 4: Tasker Task From Android

If you're familiar with Tasker, you can setup a task to open up your garage with your android phone.

  1. Create a new task
  2. Select http get as your task
  3. Fill in the details (given in image)

Now, when that task is run, your garage door will open

Step 5: Closing and Other Additions

Currently, you have to be connected to your home network to be able to open the garage. If you'd like, you can add port forwarding to your router so that you can access it from anywhere you are connected to the internet. Although, if you do so, remember to add some form of security as doing this means anyone can access your garage door.

Hopefully this has been useful to someone out there! Again, if there are any questions, let us know in the comments!


JaredPage (author)2016-10-24

Hi @TinP4,

Great to see you're doing the same thing as us !

Couple of things:

1. How is Tasker communicating with the Pi ? Can you paste your implementation there too ?

2. Have you verified that the scripts ( and work independently with your setup? So, if you run them from the command line on the Pi itself, do they perform the expected functionality ?

3. Have you verified that the form is submitting the correct data? The reason I ask is because I'm not sure your form is structured correctly. Usually you'd construct a HTML form like this:
<form action="index.php" method="post">

<input type="hidden" name="PC1" value="true">

<button type="submit">ON</button>


<form action="index.php" method="post">

<input type="hidden" name="PC0" value="true">

<button type="submit">OFF</button>


Hit the web server up via cURL and see if you get the expected results. Something like:

curl -kLv https:// hostname>:<port>/index.php?PC1=true

Let me know how you go :)

TinP4 (author)2016-10-23


I tried making something similar with my home automation system. I have a 433MHz Transmitter connected to my Pi to send On and Off signals directly to my power outlets. I wanted to be able to activate and deactivate one of them via tasker, but I have not succeeded in adapting your implementation. I am a beginner in this area and fairly weak with php, so please tell me if there is anything wrong with my code.

This is my /var/www/html/index.php file (in jessie stuff is in the html folder rather than directly in www):


if ($_GET['PC1']) {

# This code will be run when PC1 is set to true

exec('sudo /var/www/html/');


else if ($_GET['PC0']) {

# This code will be run when PC0 is set to true

exec('sudo /var/www/html/');




<form action="?PC1=true" method="post">

<button type="submit">ON</button>


<form action="?PC0=true" method="post">

<button type="submit">OFF</button>



How do I need to alter my code to get this to work?

About This Instructable




More by justindra:RPi Garage Door Opener for Rentals
Add instructable to: