Raspberry Pi Gate Opener

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

Raspberry Pi Gate Opener

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.

https://pypi.python.org/pypi/RPi.GPIO

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.

Index.php:

<?

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

?>Raspberry Pi Gate Opener schematic

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:

#!/usr/bin/python
import os.path

import os

import RPi.GPIO as GPIO

from time import sleep

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

while True:

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

GPIO.output(11, False)

sleep(0.2)

GPIO.output(11, True)

sleep(1.6)

GPIO.output(11, False)

os.remove(‘/var/www/key.txt’)

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!

For more detail: Raspberry Pi Gate Opener

Scroll to Top
Scroll to Top