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.
If you’d like to support me in writing other instructables, please buy hardware from the Amazon sponsored links, thanks! 🙂 I’m providing links to multiple Amazon sites, use the one best suiting you (i.e. FR for France, DE for Germany).
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 home screen. 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 electronic 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 (FR/DE) running Raspbian Wheezy 2014-09-09 with latest updates
- An 8GB (FR/DE) or 16GB (FR/DE) or 32GB (FR/DE) micro SD Card Class 10 to hold the OS, files and so on
- Two zinc alloy garage reed switches (FR/DE) to detect open/close state
- One 3v relay module (FR/DE) to send commands to the door motor (mine has a built-in LED to monitor the relay state, very handy!)
- A solderless breadboard (FR/DE) and 2 momentary switches (FR/DE) to simulate the door on my desk (or get a starter kit (FR/DE))
- A wifi dongle (FR/DE) 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
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.
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
My test bed is pretty simple, a RPi, a relay and two switches. To hold things tight, a few zip ties (FR/DE) is all you need. Here is a picture of it. The RJ45 LAN cable (FR/DE) is for desktop debug and WIFI dongle for garage use.
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
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 schematic with 20×4 I2C LCD, open/close switches and relay. The only addition is the I2C LCD screen. I preferred that to the 18×2 I had.
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 NAS (FR/DE) on the right side, it is used to power the RPi directly. By night with modem, switch and NAS.
Step 5: Source Code and Ressources
You can find all ressources at this GitHub repository: https://github.com/amayii0/GarageOpenerR1
This article was originally posted by me to my Instructables.