Here's a quick demonstration of the finished project.
Although this guide will provide most of the technical details to complete this project, there are a few things you'll have to do on your own.
So the first step is to take apart your garage door opener (the one mounted to your wall) and figure out how it works. There's a good chance that your garage door opener works in a way similar to mine.
I unmounted the opener from the wall and opened it up. There was a red and a white wire that were secured to the PCB (circuit board) by screws, so my first guess was that this operates like a normally open switch and if I connect the wires (and close the circuit) it will activate the garage door.
To test this theory, I hooked up my own NO (normally open) switch to the two terminals on the PCB and tested it out. To my delight, it worked!
So with this mystery solved, our circuit is going to be pretty straight forward. We'll put a relay in place of this switch, and the Raspberry Pi can drive that relay.
In this step, we'll follow the diagram below to wire up our circuit. We'll use the Raspberry Pi to drive the relay, which will activate the garage door opener. And of course, we'll need software to drive the relay, but we'll deal with that later.
The following is diagrammed below, but I'll describe it here as well. Using female to female jumper cables, wire pin 11 on the Pi to the IN1 pin on the relay. Wire pin 2 (5V) on the Pi to the VCC pin on the relay. Then wire pin 6 (GND) to the GND on the relay.
Then wire the relay to the garage door opener. The relay should be wired in the normally open position so that when activated, the circuit will close, and the garage door will open/close. If you need more details, follow the guide we've written on how to use a relay with the Raspberry Pi.
The next part that will require a bit of problem solving on your part is to determine where to put the sensors (reed switches). We're going to use two magnetic reed switches to determine the position of the door. The three positional options are open, closed, and somewhere in between.
If you're unfamiliar with these types of switches, they are the same switches that are often used in security systems to secure a window. There are two parts to the switch - the sensor and the magnet. When the magnet is moved close to the sensor, it closes the circuit. When the magnet is moved away, it opens the circuit. So we're going to use this to determine the position of the garage door. These are the NO, or "normally-open", reed switches I used.
We'll use two switches because we want to know if the door is fully open, fully closed, or somewhere in between. So the first step is to open the garage door completely and determine where to put the first switch. Then close the door and determine where you'll put the second switch.
Once you've determined the positions, you'll need to measure how much wire you'll need to connect each switch to the Raspberry Pi. Each switch has two leads, so I needed four 25 foot spools of 22 gauge wire. So before securing the switches, solder the spools of wire to the leads from the switches. Then secure the switches in place. The switches I bought had an adhesive strip that I used to secure them.
Note: This may seem obvious, but the magnet should be attached to the door and the sensor should be attached to the rail.
After securing the first switch, close the garage door and position the second switch. I recommend putting the two switches as close to each other as possible to make the wiring easier.
With the two switches in place, you'll now need to run the wire across the ceiling. I secured the wire to the ceiling using staples, but I was extremely careful not to damage the wire, It might be wise to use cable clips.
Now that the wires are run to the Pi, we'll need to connect them. I prefer to use jumper cables to connect to the Pi, so I'm going cut two female to female jumper cables in half, then strip and solder them to the switch wires. Now I can easily connect them to the correct pins.
This next part is somewhat important. We need to know which wires belong to the "fully open" switch and which wires belong to the "fully closed" switch. For both switches, we'll connect one of the wires to a ground (it doesn't matter which wire); you can use pins 20 and 14 on the Pi. Now connect the "fully open" wire to pin 19 and the "fully closed" wire to pin 13.
It's important that you use these pins if possible, because the software we'll use later is configured to read from these pins. If you feel that you must use different pins, we can specify the correct pins at run time.
The web application that serves the garage door controller UI is packaged in a Docker image, so we'll need to install Docker. To install Docker, log in to your Pi and run:
curl -sSL https://get.docker.com | sh
We've also written a detailed guide on installing Docker on the Raspberry Pi, so check out the guide if you need more details.
With Docker installed, we can now run the garage-pi image using:
sudo docker run \ --restart=always \ --device=/dev/mem:/dev/mem \ --name=garage-pi \ --privileged \ --publish 80:80 \ -d \ howchoo/garage-pi:latest
Before we open this up on the phone, we need to find the IP address of your Pi. There are a few ways to do this, but we're going to use nmap. Explore the attached guide if you'd like to use a different method.
To find the IP address, open a shell and type:
sudo nmap -sn 192.168.1.0/24
Note: You'll need to use the correct subnet.
You should be able to find your Raspberry Pi in the output. Copy down the IP address. The IP address of my Pi is 192.168.1.183 so I'll use this for the rest of the step, but where you see this IP address you should know to use your own.
Now navigate to your IP address in your mobile browser by typing http://192.168.1.183. You should see the very simple web UI that can be used to control your garage door.
At this point, you should be able to hit the "Open" and "Close" button to control your garage door!
Since the IP address can be hard to remember and cumbersome to type on your phone, you might consider adding a shortcut to your home screen.
If you're using an iPhone you can click the action icon at the bottom of Safari, then scroll across the bottom menu until you see Add to Home Screen.
Here's a look at the Pi and relay inside of the project enclosure!
Nothing can slow down the Raspberry Pi Foundation, as even in 2021, the team managed to serve up a selection of new Raspberry Pi boards, modules, and fun accessories.