Opening a gate using a phone — Part 1

Brian Dooley
6 min readJan 2, 2021

The idea for this project came to me when I had a lightbulb moment during one of our lunch and learn sessions at work. A presenter made a comment about activating an Internet Of Things application using an Amazon Echo device, which triggered an idea, “what if I could open a gate using my phone?”

As someone who lives in an estate with an electric gate at the entrance, I have found that it can cause minor annoyances when, for example:

  • An unexpected delivery arrives when no one is home, and the delivery agent is stuck at the gate
  • Visitors arrive to stay and frequently need to have the gate opened for them

The gate opens using the gate’s electronic remote controls (“zappers”). My home is near enough to the gate so that a signal from one of the zappers at home will reach the gate.

This project was going to be a little challenging, but after doing some research and remembering that I work with many knowledgeable people who would be happy to help, I decided to go for it.

Here’s how it turned out.

Preparation

After my initial research, it became clear the easiest path to achieving this remotely would be to set up a web server at home that would listen for a signal from the internet to activate a zapper. Specifically, a Raspberry Pi web server sending a signal through its GPIO pins to a relay module will convert the signal into the equivalent of a current from the zapper’s 5v battery. The Raspberry PI was an easy choice for the hardware as I already had a Raspberry Pi 3B Starter kit lying around already.

To get up to speed on GPIO, I went through this Blinking LED tutorial. All that was required for this was:

Here is what it ended up looking like.

The Node.js code from this tutorial became the foundation of the code that was eventually used in the final project. Soon, I had a web server that could make a bulb light up from pinging a URL on my local wifi network.

Here is what it looks like when I ping it from a shortcut on my phone

The Main Event

So a lot of the work was already done in the lightbulb tutorial. What I needed to do next was to use the same method that lights the bulb to signal the zapper. This would involve connecting more of the GPIO pins on the Pi to one of the zapper buttons. As the Pi’s operating voltage may be different from the operating voltage from the zappers battery, I had to use a relay between the Pi and the zapper to handle the conversion from one circuit to the other.

I was able to get a relay module from a work colleague. Here’s what it looks like.

And here is the zapper that I sacrificed to get to the internal board.

There is a big difference between wiring a bulb to a Pi and wiring a zapper button to a Pi. There is no convenient connection at the end of the wires to stick to a zapper button. The wire would have to be soldered onto the internal board. I am more of a software engineer than an electronics engineer, and soldering is something I never really had to do. Guess it was time to learn a new skill.

Once I had received my soldering kit and studied a soldering tutorial, I did a practice run by stripping the connections off some of my leftover wires and soldering the wires together.

That wasn’t too hard. The next step was to solder a wire to the underside of one of the zapper buttons. A bit daunting but, with a colleague’s help, we were able to solder the two wires to the metal setting on the underside of one of the buttons.

So all that was left to do was connect the GPIO pins on the PI to the relay and then connect the relay to our newly installed wires, as follows:

  1. Connect the DC+ pin on the relay module to a 5V GPIO pin on the PI. I used pin 4.
  2. Connect the DC- pin on the relay module to a Ground pin on the PI. Both of these steps provide power to operate the relay. I used pin 6.
  3. Connect the IN1 pin on the relay module to a BCM pin on the Pi. This is the signal to control the relay switch that is being activated. I used pin 7
  4. Connect the NO pin on the relay module to one of the wires soldered onto the zapper button.
  5. Connect the COM pin on the relay module to the other wire soldered onto the zapper button

See the Raspberry Pi Pin Diagram for reference.

Here’s how it looked at the end.

To implement this, I needed to run my code (you can find it here) on the Pi and call the endpoint broadcasted by the code to open the gate. To do this, I needed to know the local IP address of the Pi. This I found using the hostname -I terminal command.

Then it was simply a case of hitting this URL in Safari on my iPhone (This will only work if the iPhone is on the same wifi network as the Pi).

http://<IP address>:5000/zapper

And the gate opens. Hallelujah

Here it is in action, hitting the URL from a shortcut on my phone.

That’s a basic direct method of opening the gate with one touch. I made myself a UI, for a better look, that shows a countdown timer for the duration of the gate opening.

Wrap up

It was really satisfying to see the gate opening after all the planning and stop & starting on this project. However, there was more to be done if this was to become something that I, and others, could use regularly. Next, I would have to delve into port forwarding, API monitoring, and API Management.

--

--