[Updated 2019-06-12 – Additional Pictures and To-Do]
We just completed a big move from east of Dallas to south of Fort Worth. This is a big move for us, not just in terms of distance (about 70 miles), but in terms of house and property as well. The old house was a 1,900 sq ft 3-bedroom on a tiny lot, around 1/4 acre, and the new house is just over 5,000 sq ft, 5 bedrooms, on about 1.5 acres.
The front fence is about 300 feet from the house, and there is a big, steel gate at the front, operated by a Mighty Mule gate opener.
The gate controller uses coded remotes that have a very short range – only about 20 feet with a clear line of sight, which is not very convenient.
Which brings us to…
Justin’s Adventures with the Gate Controller
1. Typical Installation
In a typical installation, there is a swinging gate, where the electrically-operated gate actuator attaches.
The gate control box, located a short distance from the actuator, houses the gate controller board, and connects to the receiver antenna.
The whole system runs on a 12V battery located inside the control box, that is continuously charged by the controller board. Input voltage is from an 18V DC charger connected to 120V AC line voltage.
When you press the transmitter button, the receiver sends a signal to the controller board, which then cycles (opens or closes) the gate.
FM135 Keychain Clicker
The transmitter can be programmed with one of 3^9 codes using a series of dip switches located inside the remote. Obviously, the first thing I did was to reprogram the remote so that it no longer uses the factory default code. :-/
In our case, there are some additional accessories installed.
1.1. FM136 Wireless Intercom and Keypad
You put the keypad on a post, and can be programmed with up to 25 codes to allow entry without a transmitter. Inside the keypad are the same 9 dip switches, and you set the same code that your transmitter uses. When the correct key code is entered, it transmits a signal to the receiver (sitting a short distance away), which then cycles the gate.
This is a convenient feature for friends and relatives who don’t have a transmitter, and it even supports temporary codes – for example, if you are expecting a delivery, you can program a code that only works for 1 day, and automatically expires. If you have guests over for the weekend, you can give them a personal code that expires after 3 days, etc…
The other part of this accessory is the intercom system.
From the keypad, you can “call” the base station, and conduct a voice conversation, similar to a wireless intercom. From the base station, pressing a button cycles the gate, or you can “hang up” by pressing the “End Call” button.
In our case, the distance to the house far exceeds the range of the base station, so although the keypad is quite handy, the base station is completely useless.
1.2. FM138 Driveway Exit Wand
This is a magnetic REX (Request to EXit) sensor that’s buried near or under the driveway, and hard-wired to the gate controller. Driving over the sensor with a large, iron or steel object will cause the gate controller to automatically open the gate.
In our case, the sensor is about 15 feet from the gate.
So in summary, the keypad allows you to enter (if you know the code), the magnetic REX sensor allows you to leave (if you’re in a car), and the transmitter allows you to cycle the gate if you’re within about 20 feet of the receiver.
2. Shortcomings of the Existing System
This system has some serious shortcomings.
2.1. Transmitter has Limited Range
As mentioned, the transmitters have a range of about 20 feet, assuming a clear line of sight.
The transmitter has a clip, and normally sits on your visor, like a garage door opener.
When you approach the gate, this isn’t a problem, because you have a clear line of sight through the windshield of your vehicle.
If you drive through the gate and you want to close it behind you, you quickly find that your line of sight is now obstructed by your vehicle, which sometimes even entails holding the transmitter out of the car window to obtain a clear line of sight.
There’s a timer that eventually closes the gate automatically, but sometimes you want it to close immediately
In addition, there is no way that the transmitter will reach 300+ feet from the house to the gate.
2.2. Base Station is Useless
Although it’s supposed to allow you to open the gate from inside the house, the base station has a practical range that is much shorter than the distance from the gate to the house, which makes the base station useless.
I’ve read reviews on Amazon and other sites, that even when the base station works, reception and control are both spotty. They have an updated version, but it’s not worth nearly $300.
2.3. Can’t Remotely Program the Keypad
Although the keypad allows up to 25 codes, and even allows you to program temporary codes that expire after a certain number of days, you have to actually walk up to the keypad to program them.
There is no way to remotely administer the keypad (or, hey, tell it to OPEN THE GATE, either).
2.4. No Easy Way to Open from Inside
All of these small issues lead to a big one:
Aside from the REX sensor (which works VERY WELL, by the way), if you’re INSIDE the gate and you want to open it, there is no easy way to do this.
Here are your options:
- Drive up to the gate with a vehicle. Not practical if you’re just trying to go grab the mail, or let the delivery guy in.
- Walk up to the gate with a transmitter. It’s a long walk, and you might not be sure about who is at the gate. Especially in the rain, I’m going to be seriously disinclined to walk all the way out there to let someone in.
- Give someone the keypad code. This presupposes that you’ve programmed a series of temporary codes, or a throw-away code, and that you aren’t giving the delivery person one of your “main” codes. Also, although this allows you to let someone in, it won’t work if you are trying to get out (example: to check the mail).
- Lock the gate open. This entails walking up to the gate, opening it with a transmitter, and then using the toggle switch on the bottom of the control box to turn off the motherboard. Later, to close the gate, you have to walk back out to the control box and flip the switch again, and then either wait for the timer to close the gate, or use the transmitter to close it. This is a good option if you’re expecting a delivery, but not so good if you have to leave.
2.5. Can’t Tell Who is at the Gate
The other major problem is that you can’t easily tell who is at the gate.
Unless someone calls you and says “hey, I’m at your gate”, you have no way to know who is there and what they want.
Even if the intercom worked properly, from what I’ve read, the voice quality is poor, and you might not be sure who you are letting in.
3. Potential Solutions
With these limitations in mind, I started to think about possible solutions.
3.1. FM132 Push Button Control
The “Push Button Control” accessory is basically a doorbell button that is direct-wired in to the gate controller. When you push the button, it acts like one of the transmitters and causes the gate to cycle (open or close).
At first, this seemed like a good solution, but the exact distance limit isn’t clear, and I would probably have to bury or tunnel about 400 feet of cable in order to mount it in a convenient location.
The other issue, of course, is that the gate will probably time out and close before you could walk out there, so you’d still need a transmitter if you go out to check the mail.
3.2. WiFi Interface?
Since I actually get a decent WiFi signal everywhere on the property (including all the way out at the front gate), the second thing I did was to check to see if there is a WiFi interface available for the gate controller.
NO, THERE IS NO WIFI INTERFACE AVAILABLE FOR THE GATE CONTROLLER.
3.3. Build a WiFi Interface?
After looking at the list of accessories and their installation instructions, I started to think about building a WiFi interface.
My first approach was to sacrifice one of the keychain clicker transmitters, where I could simply bypass the pushbutton switch with a relay. This approach had some down sides:
- The transmitter runs off of a 12V camera battery, and would need to be mounted within about 20 feet of the gate controller in order to operate. This means that additional battery power would be required, and / or a larger battery would be required, in order to allow the transmitter and the WiFi interface to continue to operate for more than a few hours at a time without requiring new camera batteries.
- I would have to sacrifice one of my precious clickers, which aren’t cheap.
Fortunately, the gate controller board is very well documented.
Each pin is labeled. The “Cycle” pin is how you would connect the push button control, allowing you to open or close the gate.
Looking at the “Safety” pin, the description seems to indicate that this would be a convenient way to remotely hold the gate open as well.
SAFETY: (Typically for use with photo beam device, loop detector or other non-contact sensors) • Activation of this input while the gate is closing will cause the gate to stop and return to the opened position. • Activation of this input while the gate is opening has no effect (gate will continue to open). • Activation of this input while gate is idle will prevent gate from closing.
So if I were to build my own interface, it would need to perform three functions:
- Cycle the gate by briefly connecting COM –> CYCLE. This would allow the user to open or close the gate.
- Hold the gate open by briefly connecting COM –> CYCLE, and then holding COM –> SAFETY. This would tell the controller to start opening the gate (CYCLE), and then hold it open (SAFETY).
- If the gate is being held open, release COM –> SAFETY, allowing the gate to close.
The more I thought about it, it seemed increasingly feasible that I could build an interface that runs off of the gate’s 12V DC battery, connects to WiFi, and allows the user to remotely perform the three functions listed above.
4. Solution Design
4.1. 12V DC Power
The gate controller and the gate itself run off of a 12V DC battery located inside the control box.
The reason for this, is because you still need to be able to operate the gate during a power failure. I want my solution to run off of the same battery for the same reason.
4.2. Pi vs. Arduino
Raspberry Pi and Arduino are the two leading single-board solutions for hobbyist, embedded electronic applications.
Arduino is more of a programmable controller, where the Pi is a full-blown computer with programmable IO pins.
Both have an inexpensive, small-form-factor version.
- Arduino Nano
- Pi Zero
The Arduino operates at 5V through its USB interface, or, conveniently, 7 to 12V DC through the DC jack or its VIN (Voltage IN) pin.
The Pi ONLY operates at 5V through its USB interface, so going with the Pi means including a DC-DC converter. It also means using relays for the control pins on the gate controller, which operate at 12V and would fry the Pi.
The Arduino is basically meant to be a device, and that means no native WiFi support. Although there are addon boards for WiFi support, doing anything beyond a simple socket listener would probably require extensive coding, and a true server interface would be out of the question.
Conversely, the Pi Zero W includes on-board WiFi support, and the Pi is a full-blown computer, capable of supporting a more comprehensive range of server services, such as SSH and Apache.
So the choice was clear.
Although the Arduino has better support for 12VDC, WiFi integration would be much more complex.
Since the goal of this project is to take advantage of the WiFi coverage, the Pi made more sense, even though more hardware would be required in order to run from 12V and actuate the gate controller’s 12V input pins.
- On the Pi, I would easily be able to serve up a simple web interface, and perform remote administration via SSH.
- As a bonus, the Pi Zero W has a camera interface, and integrating a camera in to the solution means that the user can also see who is at the gate before they open it – a valuable safety feature to have.
- The Pi boots and runs from a micro-SD card. Using a slightly beefier memory card would allow me to store video from the camera, just like a DVR system.
4.3. Integration with 12V DC
Having chosen the Pi as the base platform, two issues needed to be solved:
- Knowing that the solution must run from 12V DC, there must be a DC-DC converter that runs on 12V input, and provides 5V output, ideally from a micro USB connector (phone charger connector) that the Pi uses as its input power.
- Knowing that the gate controller’s input pins operate on 12V, but the Pi’s GPIO pins operate at 5V, there must be a 5V relay for each of the two pins I intended to control (CYCLE, SAFETY).
Fortunately, it was fairly easy to find both a 12V-5V DC converter, as well as 5V, optically-coupled relays that are designed to drive AC or DC voltages up to 240V – well beyond anything I’ll be using.
A simple web interface would allow anyone on the property to view the camera or operate the gate from a phone or laptop.
Apache + PHP made the most sense for the UI.
For the back end, rather than have a mashup of PHP shelling out to call Python, I opted for WiringPi, which is already built in to Raspbian, and provides the gpio command-line tool. PHP calls a handful of shell scripts, which then use the gpio command to operate the gpio pins.
To drive the camera, I opted for Motion, which is a simple event-driven webcam interface and controller.
I was also able to write a simple media server using PHP, so that you can view videos and stills recorded by Motion.
Here is the main user interface:
- Live feed from the camera
- The green button opens / closes the gate using the CYCLE pin.
- The “Hold” button opens the gate using the CYCLE pin, and then and holds it open (using the SAFETY pin), while the “Release” button cuts off the SAFETY pin, releasing the gate.
- A list of dates is listed on the left, and the hour of the day is listed across the top.
- A “V” tells the user that there are one or more video files for that date / time, while “S” indicates still frames.
- Clicking a “V” or “S” in the grid above lists files for that date / time below.
- Clicking on a specific file opens it in a new browser tab:
5. Putting it All Together
I mounted the camera on top of a 6ft pole next to the gate.
Here is my messy work area:
Here is a close-up of the finished product:
- DC-DC 12V to 5V converter. Note the micro-USB plug connected to the Pi’s power interface. This converter worked really well over a range of voltages. On my test bench, I had it connected to a PC power supply that was putting out about 11.6V, and voltage at the battery terminals in the gate control box ranged from 12V to 13.6V (voltage drops a bit when the gate is being opened or closed). The 12V terminals are hard-soldered, and I used the two little snippets of blue jacketing (top-middle) to cover the two solder points.
- Pi Zero W. Rather than using the header, I hard-soldered wires to the pins I needed.
- Each of two 5V relays. These are optically-coupled, and run directly from the Pi’s Vcc, 5V, and GPIO pins (connected on the right). The gate controller’s pins connect on the left.
- Day / Night camera. You’re seeing the back of the camera. Those two heat sinks are attached to each of the LED infrared flood lights. I cut a rectangle in the enclosure, then used epoxy to insert a clear plastic cover, so that the enclosure remains completely waterproof.
Here is a shot of the gate controller box:
- I had to replace the battery connectors, which were worn and rusted.
- This shot was taken before I connected the 12V power supply directly to the battery connectors.
- Rather than use a separate com for each of the control pins, I shared one com connection and bridged it internal to my WiFi interface. This shot was taken before the three pins (COM, CYCLE, SAFETY) were connected on the lower-left.
6. Additional Pictures and To-Do
6.1. Additional Pictures
- I drilled a small hole through the bottom of the controller box for the CAT5 solid-core cable that I used for my bus cable. The brown / brown-white pair are 12V power, soldered to the buck converter on the other end. This picture was taken after I installed new battery terminals.
- Orange-white is com(mon). Blue is connected to the CYCLE pin. Internal to the wifi interface, orange-white is bridged to the com pin of the cycle relay. Orange is connected to the SAFETY pin.
The wifi interface in its IP65 enclosure.
I used a piece of CAT5 solid-core as a bus cable.
The two infrared illuminators (left and right) are visible next to the camera (center)
6.2. To-Do List
- I had a failure condition, where the linux kernel apparently continued to function, but the wifi interface disconnected and failed to reconnect. Because the power is hard-wired to the gate controller’s battery, a simple reboot required partial disassembly of the gate controller in order to disconnect the power for the wifi interface.
- A simple script will ping the gateway once per hour and reboot if no reply is received.
- A Normally-Closed (NC) pushbutton switch will be installed behind one of the rubber grommets, allowing a manual reset without disassembly. Pushing the switch will interrupt the normally-closed positive lead to the battery, triggering a power-off and reboot once the switch is released.
- The IR illuminators bounce off the acrylic lens, making true night vision impossible. I will install a baffle around the camera lens, blocking out the reflection from the IR illuminators.
- This project worked so well as a wifi camera, that I plan to add several more throughout the property.
- Currently, the housing is zip-tied to the T-post, but I intend to install proper brackets, allowing the camera angle to be adjusted.
For about $50, 200 lines of code, and about 2 weeks of development, I built a WiFi interface for my Mighty Mule gate control system.
- View a live feed or operate the gate using WiFi, anywhere on the property from a smart phone or laptop
- Automatically records motion “events” locally, that are continuously downloaded to a Linux PC inside the house
If anyone is interested, please reach out to me, and I’m happy to share parts lists / scripts / code / config.