Raspberry Pi Gate Opener




Introduction: Raspberry Pi Gate Opener

About: I build cool stuff.

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.

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

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.

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: http://elinux.org/RPi_Low-level_peripherals. 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.

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!

1 Person Made This Project!


  • Hide It Challenge

    Hide It Challenge
  • Laser Challenge

    Laser Challenge
  • Edible Art Challenge

    Edible Art Challenge



3 years ago

You can call the GPIO code from the PHP code, so there is no need for python. Especially not python that runs an infinite loop - that is a waste of computing power. Get WiringPi from here: http://wiringpi.com/download-and-install/. Then do a call like this in the PHP:

system("/usr/local/bin/gpio mode 7 out", $modeResult);
system("/usr/local/bin/gpio write 7 1", $writeResult);

If the call fails, then the result variables will have a value of 127. Otherwise you know it succeeded.


Question 3 years ago on Step 5

Hi, I’m doing this system as my final year project at my college. And I’m really new to Raspberry Pi. I was wondering if you can email me your entire code with the secure as well. That will be awesome. Credits will be on you hehe thanks mate


Answer 3 years ago

I just realize I didn’t put up my email address ..
Here you go haha thank you


3 years ago

Thank you very much for sharing this. I was wondering around gate engine manuals and boards to connect the relay directly to the engine or the board, but totally missed the remote control idea you had. This definitely cleared up my mind on how to create this kind of gadget and will try it soon.

If you could share the rest of the extended code, would be very apreciated, thanks.


4 years ago

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


4 years ago

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.



Reply 4 years ago


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!


4 years ago

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!


6 years ago

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


Reply 6 years ago

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 (https://nodejs.org/en/) 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.: https://drive.google.com/file/d/0B1je7v44VCFVS3VVM...

- Sam