Building a remote gate opener using a expressjs and a Raspberry Pi
There is something very satisfying about clicking on a web interface or hitting a button on an app and seeing some physical event occur. It's a bridge between the virtual word and the tangible, and is the main reason I and others like me love working with electronics.
So if You have ever lost your Garage or electric gate remote, had the hassle of sharing just a few remotes between an office or maybe just want to be able to control your gate with your phone, then this is a project worthy of at least consideration. A small hint of Linux wizardry and a simple expressjs application is all that is needed to get this project up and running.
- Raspberry Pi (gen 3 preferably)
- 8gb+ microSD card
- A relay module such as this one
- And the remote of course
- Some wires
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Getting Started
The idea here is simple, turn one of the Raspberry Pi's gpio pin on via software to activate the remote which in turn opens the gate. the standards i gave myself for this project were that it must be simple to use, require the least amount of components components, and be reliable.
I could have went down the route of conjuring up a bespoke circuit and piggybacking it onto the remote but that would mean limiting its use to that specific remote. the easiest and in fact cheapest option was to use a relay breakout board. With a dual relay board costing only around $6 and having the added option to control a second appliance up to 10A its a nobrainer.
Putting this all together is, for the most part, fairly straight forward. The relay is essentially replacing the button on the remote, so by following the traces on the remotes PCB and soldering wires to the two pads that would otherwise be bridged by the button(marked in orange in the photos) and then attaching those wires to the normally open connectors on the relay board I am effectively bypassing the button. from the raspberry pi two wires from the GND and 5v are connected to the respective GND and 5v(VCC) pins of the relay. the third wire goes from one of the gpio pins of the PI to either one of the IN1 or IN2 pins depending on which relay you attached to your remote. the gpio pin must be one of the pull-down pins as the relay operates by pulling the voltage of the pin to 0v and not by supplying the pin with a voltage which is somewhat counter-intuitive but their is good reason for this that i wont get into. with this the hardware is is pretty much done only to put it into a nice enclosure and supply the power. in this case the remote operates at 9v so its original battery 9v pp3 battery is used. the raspberry pi is powered via its standard 5v micro usb power supply.
source for pcb layout photo http://www.eevblog.com/forum/chat/semefab/msg28960/#msg28960
Step 2: The Software
The web interface is an expressjs application running on the raspbian Linux distro. The program accepts a username and password via a post request and queries a mongodb database to for a match. Once everything matches up a system command is called which switches the gpio pin low for 1 second and then high again.
The app is run using forever (so that is runs forever), and is included as a startup job in `/etc/rc.local` so in the event that the PI loses power or turns off it will start running again once the power is restored.
Since all that is needed is a simple post request to a web page with username and password it is very simple to integrate this with other applications. I have created a very simple android app to demonstrate this. The app has just one button which posts to a specified url your username and password. The same can be done using IFTTT do buttons with the maker channel.
The software can be downloaded from my github, which also contains more detailed set up information
Step 3: After Thoughts
The Mongodb instance is probably overkill for a small network of people, a config file to store the credentials would be enough in most cases, I will be changing that in the near future. Also i would like to add an interface to add or edit users.
by the time you are reading this i should have a version of the software finished that uses a much simpler config file. this will be in the config branch of the github repo. default username and pass is 'user' and 'user123'.
have fun :)
Participated in the
Internet of Things Contest 2016