Weekend Projects #1: Open Garage

Infinite garage remotes for everyone


Weekend projects were a thing that my roommate and I coined back in the day when we first started going after internships and hackathon acceptances. Our goal was to make and publish a project over the span of a weekend. No hackathon, no class, no prizes. This is purely making for fun. The one requirement, however, is that these projects have to be done within a weekend from start to finish and they need to be complete (enough) to push into production as an MVP.

Open Garage

Problem:

We recently got a new garage opener, and unlike the old one, this one only came with one remote. Unfortunately, we have three cars. This means that every time I came home, I have to get out and open the garage or park up front. Nope. I wanted a remote! Ofc, I don’t want to buy one like a normal person. I want to hack our opener to see how I could crack open the door.

Getting Started

Well, first I set out to google to research how people handled DIY remote garage openers. There were many solutions out there. ome were full fledged projects dedicated for this purpose like the GaragePi Project. Of course, I wanted to build everything from scratch, so I didn’t opt-out for a built-out solution.

Silvrback blog image sb_float_right![Silvrback blog image ]

I didn’t want to mess with the actual opener itself as well, something on a smaller scale is more suitable. So I started my research. I kicked off my project with some inspiration from an instructable to start with.

Hardware Hack!

The plan for the project was pretty straight-forward. I hack the push-button terminals on our garage remote to be triggered by a microcontroller such as an Arduino.Then trigger the microcontroller via the web. Of course, I’ve never built the entire thing myself end to end, so this is all new in a sense. I do have experience with bits and pieces.

To trigger the garage, I found the pins that when shorted triggered the door. I soldered wires to the pins of the pushbuttons. Shorting these pins allows us to trigger the door.

Silvrback blog image sb_float_left

After that, I wanted to test out triggering the pins with an Arduino. I looked all the previous projects to tap into an existing circuit, and it seemed a relay was the best way to go. So I drove over to Fry’s picked out a relay that should have worked and plugged it in. This was my first time working with relays. If you’ve never worked with one before, you should, because it makes this really satisfying switch when it flips on.

Anyways, the relay didn’t work. The voltage/current in the second circuit was not enough to allow the relay to work. I was only working with 3.3V. That’s when I reached out to my friend, and he brilliantly suggested, just use the power from the Arduino! So I removed the battery from the original Garage Remote, soldered wires onto the terminals and plugged it into the Arduino.

The code I wrote was just the sample blink LED code. Instead of an LED, I used the Garage Remote

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

And it worked! Now I just had to expose this over the web to use with anything.

###Hello Raspberry Pi

After I got the hardware working, I knew the same thing could be done on a Raspberry Pi. The beauty of the Pi is that it operates like a normal computer. All I had to do was boot it up, throw a web-server on it and then interface with the GPIO pins to perform the same actions as Arduino. So once again, I started off by testing the hardware. Here’s a good tutorial for blinking an LED with a Pi and Python.

The Pi ’s GPIO works well with Python. So this means that my web server should also be in Python. So I took the time to get started with Flask. I set up a route called Toggle that called the necessary GPIO code. I learned the hard way that GPIO.Reset is an important command. When building a web-server with Raspberry Pi and interfacing with GPIOs, make sure to GPIO.Reset. If your server crashes or shuts down resetting allows the pins to be reused. I learned this the hard way and the pins would be stuck in the on-state.

Silvrback blog image sb_float_left

The next couple hours I spent debugging my program and testing. The garage door would randomly open and close during the night. I swapped out the remote for an LED so I could simulate it.

I programmed on my mac mostly and did a git pull on the pi to fetch the latest code. My github requires 2FA, so setting up auth to my Github from the pi wasn’t all that trivial - so I just used it as a thin-client. You can find my server code [here](

After I had the server set-up, I had to expose it so that I could access my web-server outside our wi-fi network. This is how I learned about ports.

##Networking the Network

As usual, I began by reading tutorials. I read this article on accessing our home computers from anywhere. This was a nice find because it explained what all of those settings in the router configuration meant.

Networking was a blur to me before, but after working on this project, ports, port forwarding and IP Addresses all seemed to click together.

Silvrback blog image sb_float_right

Anyways, the task here was to give the Raspberry Pi a Fixed IP Address. IP Addresses come in two types, one is public facing and the other is internal. Our router assigns all of the clients that are connected to it an IP (this is usally something like 192.168.xxx.xxx) . Our router itself has another IP like (64.12.22.xx), that’s the public facing IP.

I mapped the local IP to a particular “port” on the router. This told the router that all requests to the public IP at a particular port should be forwarded to the internal IP. Wiring all of this up, it worked! I could control my garage from anywhere in the world. However, there was still one more challenge.

Our public facing IP changes every 48hrs or so, so that means the url to my garage would change then too. I would never know it changed or what it changed to. To solve this problem, our routers have this problem called Dynamic DNS. A provider like Dyn will give us a fixed Web Address. Our router will then go to the Dyn portal, and update the new IP information. I ended up buying a new router because D-Link provides free Dynamic DNS domains or else it’s like $40.

The good thing with building a web-service is that there is native IFTTT support. I wired our garage to IFTTT to get triggered on things such as location and virtual button presses. Unfortunately, I still had to build my own client. The latency with using IFTTT was far too much compared to a more reliable web call done by my browser. I didn’t want to wait 5 seconds for my door to get signaled and then another 10 as it slowly opens.

Building a Mobile App

Lastly, I wanted a way to interface with my system. I added a simple password based auth system that was hard-coded into my server. My app took the password and allowed me to control the remote. I used my Xamarin.Forms for the App logic. I installed it onto all the phones in our household.

Silvrback blog image sb_float_center

My mom suggested a feature where the door should only unlock within a certain distance from the home. Don’t want the garage door open because of an accidental press. So, I added a location service into the app to restrict access. It worked! The app was lightweight and fast. I also realized that writing code for locations and handling coordinates is a pain.

Conclusion

I learned a wide array of things. From basic hardware skills with relays to port-forwarding and Dynamic DNS, I built an end-to-end solution in less than 24hrs. That’s enough for me. This was like my own hackathon and I had a lot of fun building it out. It did something useful. All in all, this was a fun project, and I can’t wait for my next one!

Note: I gave my mom her actual remote back the next day because my server couldn’t stay up reliably. This server should have 0 downtime. If I ever get time, I would look more into ways to improve reliability and probably look into using an ESP8266 for this type of project. A Pi just has too much going on.

comments powered by Disqus

Thanks for stopping by! Subscribe to my blog to get my latest posts