Garage Door Opener Using a Raspberry Pi

12,213

135

13

Introduction: Garage Door Opener Using a Raspberry Pi

About: Self taught DIYer, interested by anything electronic but without trying to launch a rocket to the moon :-)

Control garage motor from a smartphone or any device able to browse a webpage (with AJAX!). The project was started as I only had one remote for my garage. How fun was it to buy a second one? Not enough. My target was to be able to control and monitor my garage door from my smartphone with a single page. I haven't put any fancy security around it as the RPi is not exposed outside of my LAN. Thereby I rely on VPN to access the web page. Using an Android smartphone it's very easy to both setup a VPN and add a webpage to my homescreen. All i needed was the software for it.

Step 1: Some Background

What I found online

As a programmer, I like to reuse tutorials or already "production level" code. In this case I wasn't happy with what I found :

  • Raspberry Pi Garage Door Opener by quartarian. Where I started, a simple button to command the relay. No open/close buttons, no feedback. It was anyway very helpful to understand the concept around dedicated RPi to control a motor from a relay. The cabling I use now is still the same for the command part.
  • Raspberry Pi Garage Door Opener with GaragePi by Chase Chou. Same kind of setup but using an extra wireless remote. I wasn't willing to kill my only remote. It proved to anyway use the same kind of electrical setup for the command part. Along the way I learnt about WebIOPi to check my GPIO over a webpage. That's were I also learnt about putting a shortcut to my Android homescreen. It also started to light the idea of relying on services, after all, I want it to be reliable.
  • Making Your Garage Door Email, Tweet, or SMS: Part 1 By Richard L. Lynch. This one added the idea to use a Magnetic Sensor to control the door state. However I haven't used much as I wasn't building an alarm system but a command/monitor system.
  • Completely Wireless Garage Door Opener / Security Cam by DeckerEgo. This made me better aware about webcam streaming to monitor the door. I still have to put some effort into that. Maybe I'd have to recycle a USB hub or fetch another webcam.
  • Raspberry Pi control from mobile device or desktop web browser by Frédérick Blais. This is now my base for the software stack. It uses Flask to run a very simple web page along with AJAX. This is premium to me as it provides real-time monitoring and command options. Read below.

About my RPi

As I'm still learning about the RPi and electronical stuff in general, I bought a number of stuff for my freshly acquired Raspberry Pi: a few cables, a T-cobbler, some leds, a one-relay module, a eight-relays module, a LCD display and so on. I'm in no way an electronician and this proved very instructive. To buy the extra hardware Amazon and Ebay are your best friends.

The current state of the project includes following hardware :

  • A Raspberry Pi model B running Raspbian Wheezy 2014-09-09 with latest updates
  • An 8GB SD Card to hold the OS, files and so on
  • Two zinc alloy garage reed switches to detect open/close state
  • One 3v relay module to send commands to the door motor (mine has a built-in LED to monitor the relay state, very handy!)
  • A breadboard and 2 momentary switches to simulate the door on my desk
  • A wifi dongle to remove extra cabling when it'll be hanging from the garage ceiling

A limitation I still have is that I don't know when the door is halfway, stopped or still moving. This is also why I'd like to later add an old webcam to stream from inside the garage. Probably I'll actually add some sensor to monitor the motor itself.

Step 2: Software Stack

General stuff

The software relies on Python, Flask and WiringPi GPIO Python module. As explained in background, I started from the tutorial Raspberry Pi control from mobile device or desktop web browser published by Frédérick Blais. The current software is composed of :

  • An HTML template file containing some jQuery Mobile code and controls
  • A Python Pins module to access the GPIO of the Raspberry Pi
  • A Python go module to run Flask and support the AJAX queries

What is present in the repository is the raw software. It's in no way fancy or overwhelm of features. It's just what I was able to achieve from what I've learned.

Current interface

Currently the state for doors is read every 0.5s. Two switches are used for both open/close state. A relay is used to command the motor. Current code still outputs some debug. Below screen shot is from a Nexus 5.

Step 3: Hardware - Alpha

Test bed

My test bed is pretty simple, a RPi, a relay and two switches. To hold things tight, a few zip ties is all you need. Here is a picture of it. LAN cable is for desktop debug and WIFI dongle for garage use.

Live system

RPi is connected to motor only for now, switches will follow. I must wait a bit to get my heat-shrinking tubing. I should also be more steady. Sorry for blur.

The blue, yellow and green cables on the left are for the magnetic switches.

  • Blue is the GND
  • Yellow and green are pins 18 (open state) and 27 (closed state).

Step 4: Hardware - Beta

Test bed

This is now a direct cardboard with zip ties. The LCD and relay are also bundled. The LCD is 20x4. First 2 lines display welcome and date/time. Last 2 lines cycle between pins states and network state (eth0/wan0 IPs). The door state line is a nice GFX to say :

  • | | is open
  • |-| is operating
  • |.| is closed

Fritzing schematics

Fritzing schematic with 20x4 I2C LCD, open/close switches and relay. The only addition is the I2C LCD screen. I prefered that to the 18x2 I had.

Live system

The beta HW is now "production level" as it fits nicely in an old screws box. I kept one separator to host relay and misc cables while RPi stands at lower level. You might notice the Synology on the right side, it is used to power the RPi directly. By night with modem, switch and NAS.

Close view of screws box, the LCD shows door' state and Open/Close/Relay pinout.

By night, inner view from top.

Step 5: Source Code and Ressources

You can find all ressources at this GitHub repository:

https://github.com/amayii0/GarageOpenerR1

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest

    13 Discussions

    Great work! I did a similiar thing with a Wemos D1 Mini using Arduino code. I also added a nice feature which will send push notifications to your phone using IFTTT even if the door is operated manually. Operating the door is made through a simple HTTP GET request to the Wemos device, on Android devices that can be done very nicely with an app called HTTP Shortcuts. Source code for the garage door opener can be found here: https://github.com/delabrava/GarageDoor

    The hardware is nicely fitted into a plastic box, 7 * 5 * 3 cm.

    IMG_20161203_212609.jpgIMG_20180303_145114.jpg
    2 replies

    Very clean assembly! Looks like there are just as many ways as people trying to do this :)

    Thanks for sharing your repository, this can prove useful for people targeting an ESP8266 (including me to some extends).

    Hi, nice tip, thanks I wasn't aware of such issue!

    Nice job...I did the same thing a few months ago using the ESP8266 breakout for I/O, logic, and Wi-Fi. I wanted to monitor the door status when we're away and if necessary operate the door to let someone into the garage. I used Adafruit IO as the front end. Spent a grand total of about $25 on the whole thing.

    Door control.jpg
    1 reply

    Hi, thanks for sharing!

    An ESP8266 was indeed an option, see tip section we started a short discussion earlier today.

    Note to myself: Invest in a proper soldering station, very neat build!

    Hi Rudy, it's a nice project. I'm managing to make something similar with NodeMCU as a cheaper solution for such a simple task. However I'll give you a tip about how to check the door position and movement. You can use ultrasonic proximity sensor HC-SR04 to check how far is the door from the sensor and if it changes its position.

    1 reply

    Hi Stan, thanks for your interest!

    NodeMCU / ultrasonic was indeed a solution. However I had a RPi around and wanted to use it in my garage (next to networking equipment). This is why I used it. Final target was to use it for home automation .

    I had a look at PiDome (https://twitter.com/pi_dome), now Home Assistant (https://home-assistant.io/hassio/).

    In a perfect world I'd be happy to use more simple D1 Mini boards (similar to NodeMCU, I actually own a few NodeMCU but bought a few different models from Ali Express). Ultra sonic sensor was an option but lakes a precise reading for "fully closed" / "fully opened" vs "slightly opened", for instance to let some fresh air flows when doing wood working.

    To link all these I'm having a look at Homie for ESP8266 framework (https://github.com/marvinroger/homie-esp8266), this is very promising but I'm still lacking time to investigate, especially regarding IR controlled HVAC units.

    Please see my other 'able : https://www.instructables.com/id/Building-Homie-De...

    I've been looking into this also, mainly because I have a new-in-the-box Raspberry Pi looking for employment. With respect to the door opening and closing, and direction, could you use a magnetic or optical sensor with 2 trigger points on some part of the rotating mechanism (One might have two or more reflective strips or magnets, while the other would have only one). This could give you direction of travel, speed, and if you knew how many turns were required from that part for the door to be fully open or fully closed, an indication of that state also. This is much more lo-tech than a camera, but might be a reliable alternative. (Where I live, some cameras tend to have issues in cold weather). The indication of direction is definite - which marker passes the sensor first - and likewise measurement of RPM is simple, as is the overall revolution count. Just "thinking out loud" at this point. Good luck with your build.

    1 reply

    Hello Trike,

    I actually found an article using 2 magnets on the chain, near the motor. I also liked that approach but ordered the switches before finding that :-)

    You can have a look at this Arduino based article, not sure however if a RPi has the precision required for "pulses" between strips to have direction/RPM. As a rul of thumb, my door takes 12.5 seconds for full course. At some point that is why I had that "middle" position in the UI.

    https://www.megunolink.com/articles/arduino-garage...

    On my TODO list is "learn to design 3D printed parts" :-)

    Thanks for your feedback, always good developing around ideas!

    Wow great able, I have similar project in mind. Thanks for all of the links to similar projects that will really help to go through them all.

    Ralph

    1 reply

    Hello Ralph,

    Thanks for your comment!

    I always say I like being lazy, this makes me look around for tips and tricks and eventually enhance some stuff.

    Hope this'll help you, don't hesitate to hang around!