Originally written on Jun 10, 2017
This is a quick tutorial for turning an OpenWRT router into a garage door controller. In this tutorial, I will be using the MT300N from GL-Inet to control my garage door over WiFi.
First, you'll need to SSH into the router. We need to edit the file
/etc/rc.local. In this file I will put the following lines before
The first command enabled GPIO pin 44. The 2nd line sets the GPIO port as "output", what we will use to control the relay. Now reboot the router.
Next, lets wire up the relay to the router. For my MT300N router, I used GPIO port 44 (labeled as LINK4 on the router board). Conect GPIO pin 44 to the "IN" pin on the relay. Now, connect GND to GND on relay, and connect the 3.3v pin on the router to the VCC pin on the relay. Here is a wiring diagram:
Now to test if it works, run the following commands. To turn the relay ON, run:
The green light on the relay module should turn on, and you should hear a click. Now to turn the relay off, run:
and the green light will turn off. If this works, your relay is wired correctly.
Now we need to install PHP to run the commands from a web interface. Run the following commands in order to install PHP to your router.
/etc/config/uhttpd to enable PHP. Right below the first block of text, add the following lines:
And now restart uhttpd.
Now lets create a quick script to turn the relay on, wait 1 second, then turn the relay off again. This simulates someone pressing a button to make the garage door open. I wrote this quick and dirty bash script to do just that. I saved this file to
And lastly, lets create the quick PHP page to run this shell script. I put this file in
Lastly, we need to wire the relay to the garage door opener itself. This process in concept is simple, you just need to find the two screw terminals on your garage door opener that connect to the garage door button, and wire them to the NO and COM ports on your relay.
Now, when I navigate to http://router-ip-here/garage.php, I can activate the relay, opening my garage door.
A picture of the final setup: