Introduction: Raspberry Pi Gate Opener

Picture of Raspberry Pi Gate Opener

This is a raspberry pi project that enables you to open your garage/gate with any kind of web browser!

Step 1: Gather Those Supplies.

Picture of Gather Those Supplies.
  • Raspberry Pi - 35$
  • Relay Board - 5$
  • Your Gate Opener - (You will be sacrificing the gate opener)

Great. Now that you have those, moving on!

Step 2: Wire Up That Remote.

Picture of Wire Up That Remote.

Crack open your gate opener and find where the button leads are. Solder two wires to the leads. When you touch these wires together, your gate should toggle. At the time of making this I didn't know much about circuitry so i went a head and soldered the button, so that when power was supplied to the remote, the gate toggled. YOU DO NOT NEED TO DO THIS. Just solder the two wires to the button leads. And then solder those wires to the relay.

Step 3: Wire Up That Relay.

Picture of Wire Up That Relay.

Find the pins on the relay that are labeled GND and VCC. Connect the VCC to the raspberry pi's 5v pin. You can find a mapping of the pins here: And wire the IN1 to one of the Pi;s GPIO pins. Your choice of which pin. Check out that link above to see which ones are ok for this. (make sure you're using relay 1 if you're relay board has more than relay channel.)

Step 4: Get That Library.

Picture of Get That Library.

SSH into your pi or get the CLI somehow so we can install some things.

First install RPi.GPIO. Just search google for it and download it to your pi. It's a very easy install of the python library. If you have any problems, try running as root through the entirety of the installation.

Step 5: Write That Code.

In this tutorial I will include the very first version that I created. I have expanded on this by a ton so if you want my code, just comment. Mine includes access codes that expire and a full web application that secures the gate web interface and remembers your password for next time. But here we go with the simple version. Install apache web server on your Pi. It is very easy! Look for tons of tutorials on google for this! After you've done that, here is the php code:

Create a file called index.php and put this in it. make sure the file permissions are set correctly after this...chmod 777.



exec("touch /var/www/key.txt",$output);


Step 6: Write More of That Code.

Ok, now the python code. Put this in the same directory as Index.php. On my pi that is /var/www/. Here is the python code:

import os.path

import os

import RPi.GPIO as GPIO

from time import sleep


GPIO.setup(11, GPIO.OUT)

while True:

if os.path.isfile('/var/www/key.txt'):

GPIO.output(11, False)


GPIO.output(11, True)


GPIO.output(11, False)


Make sure that you make it executable. Chmod +x.

Step 7: Putting It All Together.

Ok, so you've got the code in and permissions perfect. Now it's time to start it up. SSH into your pi and run the python script in the background using &. If you are confused by this, google it. This tutorial is meant for people who have at least some experience with CLI.

Great! Now visit you Pi's IP address in a web browser and you're gate should open! (The remote is toggled.)

If you have any questions, I invite you to comment! I hope this tutorial is clear because it was my first instructable. :) Good luck!


DarrenF6 made it! (author)2015-09-05

great instructable.

My wife just broke both her ankles in a holiday accident! so I needed a way to phone-enable the gate for her.

following your steps, I pulled this together in about 90 mins this morning

I plan on integrating this with one of the HD Security Cam Instrictables out there, so I'm saving on Pis. :)



sam1999 (author)DarrenF62015-09-05

Oh man! So sorry about your wife. I hope she has a quick recovery! You honestly just made my day by commenting. Thanks! That security cam idea sounds cool as well! I'm beyond happy this was so useful to someone :D! My family and I use it almost every day!

- Sam

DarrenF6 (author)sam19992015-09-06

i hare Ron. :)

have a look at HomeGenie integration vid.

DarrenF6 (author)sam19992015-09-06

Hey Sam

thanks for.the well wishes.
ive just integrated it with HomeGenie so i now have voice control of the gate.

once i ill throw up a small instructable.

all the best

d3mig0dj (author)2017-10-20

Is there a way to contact you about this? i'm looking for a way to send IP commands to this to open/close and possibly show 2-way feedback through a control system

BelloN1 (author)2017-02-14

Hey Sam

Thank you for sharing. I am totally new in home automation.I'm more into industrial automation [PLC and all] but now i'm planning to realize that project for my dad house.

Your project is nicely explain and seems to be very easy I'm going to do it and get back to...

Thanks once again for sharing the good work.


sam1999 (author)BelloN12017-08-02


My apologies for the late reply. School has been quite busy!

I'm so glad that it has been helpful to you! Thank you for the kind comment!

I hope you had good luck integrating this with your dad's house!

TazeH (author)2017-03-21

I don't know anything about Raspberry Pi's but I have been wanting to find a "usefully" project to get started with one. I think I have finally found the project. I do commercial security, so I'm very familiar with relays & the like. My question is why do you have to sacrifice the remote, why not just use the relay on the aux relay board (controlled by the raspberry) to short the relay/trigger on the gate operator? I like the idea of your new code that has a interface. Once I get all my supplies, I'll be back in touch!

nking5879 (author)2015-10-01

Great write up. I'm interested in building this as well, can you provide your code that also allows access codes?

sam1999 (author)nking58792015-10-12

I am currently busy with school, my apologies for the late reply!

I originally wrote the access code program in PHP, and about 4 months ago, redid the system with node.js ( and made small hardware improvements. I don't have the original code anymore, but I am happy to provide the code that I am using as of now. I really want to add the access code feature into the new one when I have time. I'll post if I end up doing it soon. Thanks for the comment!

Here is the current node code. Let me know if you need any help understanding it and whatnot. I'm happy to help.:

- Sam

About This Instructable




Bio: I build cool stuff.
More by sam1999:Raspberry Pi Gate Opener
Add instructable to: