Idiot’s Guide to a Raspberry Pi Garage Door Opener
It has become apparent that WebIOPi is not yet compatible with the Raspberry Pi v2. If you are following this tutorial, you must be using the first-generation Pi. The link below for the B+ model is still valid, and this model will still work for this project.
I’ve updated the Amazon links to point to the new Raspberry Pi B+ revision. Please note that if you’re going to use this version, you don’t necessarily need the USB wireless adapter listed below since the B+ revision of the Raspberry Pi includes a wired LAN port. Another note is that the B+ revision now uses Micro SD cards rather than the full-size SD card. The guide has also been updated to reflect this.
Recently, I read a blog post (http://freemansgarage.com/blog/?p=587) about configuring a Raspberry Pi to become an internet-connected garage door opener – meaning you can control your garage door from any device with an internet connection. I had never used, or really thought of using a Raspberry Pi for anything at all, or anything related to home automation, but this really piqued my interest. This project could prove useful for things like letting in a repairman or family member to your home when you’re not there, or if you simply lose your dedicated garage door remote or its batteries have died. Or it’s just really cool.
Along with the post I linked above, most tutorials I came across involved making circuits with breadboards or something similar for the magnetic switch sensor portion, but I didn’t have anything like that laying around and to be honest, it seems to over-complicate things. This project can be accomplished with no soldering or breadboards required.To start with, the build list:
– Raspberry Pi (Updated this link to the B+ model since it is the most readily-available revision)
– Plastic Case for the Pi (This isn’t necessary, but will keep the Raspberry Pi safe. Has a hole to allow jumper wires through)
– 2-Channel Relay (One channel will be used for the door, the other could be for a future use)
– Wireless USB adapter (Raspbian has built-in drivers for this wireless chipset to make things easy)
– Magnetic Switch (This is only necessary if you want to be able to determine if the door is open or closed)
– Wire for the magnetic switch and connecting the Raspberry Pi to your garage door opener (I used extra CAT6 cable I had laying around, any 2-conductor cable ~20-24 gauge should be fine)
– Micro SD Card (You probably have some extras kickin’ around, 4GB or larger recommended, I went with 8GB in case I wanted to add stuff later)
– Female-to-female Jumper Wires
– USB to serial TTL adapter (This is also discussed below. It is optional, but this tutorial assumes you’re using a serial connection)
– MicroUSB Charger (You might have one laying around, at least 1 amp current recommended. Make sure you have a place to plug this in near your garage door opener)
– Wire Nuts (for connecting wires and resistors together, might be able to find them cheaper at a local hardware store)
– 1 10k Ohm resistor (You can get a pack of them from RadioShack for less than 2 bucks)
– 1 1k Ohm resistor (Again, a pack from RadioShack for a dollar and change)
First things first, you’ll need to get an operating system for your Raspberry Pi installed onto an SD card so there will be some type of user interface. Plug your SD card into your PC or USB SD card reader, then go to http://www.raspberrypi.org/downloads and download the image for RASPBPIAN Debian Wheezy (under the OPERATING SYSTEM IMAGES section). You’ll download a ZIP file that’s around 780MB. Once this is done downloading, open the zip file and inside you’ll find a file with a .img extension – extract this file to your PC and remember the location where you extract it. Since Windows doesn’t know how to handle this file natively, you need to download a program to write this image to the SD card. Download Win32 Disk Imager from http://sourceforge.net/projects/win32diskimager/ and install it. Run the program and you’ll get a box that looks like this:
Click on the blue folder icon and browse to the folder where you extracted the .img file previously. Double-click on the .img file in the ‘Select a Disk Image’ dialog and you should end up with a window similar to this:
Make sure you have the correct drive letter of your SD card (or USB SD card reader) selected under the ‘Device’ heading. Once you’ve confirmed the correct device is selected, click ‘Write’ and let the program write the image file to your SD card. Once this process has completed go ahead and safely eject the SD card from Windows and insert the card into the bottom of the Raspberry Pi.
Now, depending on how you want to communicate with the Raspberry Pi, you’ll either need a USB hub to connect a mouse and keyboard to the Raspberry Pi and connect to a TV or monitor with HDMI, or connect to the Raspberry Pi via serial interface. I opted for the serial interface since I already had a USB to serial TTL adapter from another project. My instructions will assume you’re also using the serial method and already have the appropriate drivers installed for the adapter and have a COM port assigned. One thing to note, you should only have to connect the RX and TX cables to the Raspberry Pi since it will be powered via USB connection.
This is the Raspberry Pi PCB and diagram of where the GPIO, VCC, ground, and serial pins are located:
Now you’ll want to connect your USB to serial adapter pins to the UART0 RX and TX pins (8 and 10) and one of the ground connections on the Pi. The RX on the USB to serial adapter goes to TX on the Raspberry Pi and vice versa. You can also go ahead and plug in the wireless USB adapter at this point, but it won’t connect to your wireless network yet since the encryption settings are not configured. Once you have these wires connected you can go ahead and power up the Raspberry Pi. You should see a red power light below the blue 3.5mm connector as well as a green activity light that shows file system read/write activity.
If you don’t already have a terminal emulator program, you can download the free PuTTY program from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Run PuTTY and you’ll see a screen like this:
You’ll want to click on the ‘Serial’ radio button and make sure you input the correct COM port that is connected to your Raspberry Pi (COM3, for example). You’ll want to make sure and change the baud rate to 115200 (just type it in the box). Once you’ve done this click ‘Open’. A black window might be all you see, so press ENTER until a login prompt appears. The default username/password is pi/raspberry. You’ll probably get a message saying something about this being the first time you’ve run Raspbian and to run raspi-config to configure some settings – you’ll want to do this now. At your command prompt, enter:
You’ll get a configuration menu – the only thing to bother with right now is enabling SSH connections so you can connect to the Pi via network later on. Go to Advanced Options, then SSH. It’ll ask if you want SSH enabled or disabled, select ENABLED and it’ll update the configuration and kick you back to the command prompt.
The first thing you’ll want to configure is the wireless connection, so you will need to assign an IP address to the Raspberry Pi. To do this some configuration file editing is necessary. The first file you want to edit is /etc/network/interfaces, so at the command prompt, enter the following:
sudo nano /etc/network/interfaces
This brings up the nano text editor with the contents of the /etc/network/interfaces file, like this:
The contents of your file will be different, but you’ll want to edit it to resemble this picture. You can use your regular letters, delete, and arrow keys to make changes to the file. The part where your settings may differ from mine are the address, netmask, and gateway lines. My router is configured for the 192.168.1.xxx subnet, so I decided to assign the address as 192.168.1.10. Your router might be 192.168.0.1, so you could use an address like 192.168.0.10. The netmask will almost always be 255.255.255.0, but you’ll want to confirm the correct value in your router’s settings. The gateway address is the address of your router. Once you have the file edited to the correct settings, press CTRL+X to close the file. It will ask if you want to save the modified buffer, press Y. It will then ask the file name you want to write, just press ENTER. NOTE: If you get a permission denied error when you try to save the file, it’s because you did not have ‘sudo’ in front of your nano /etc/network/interfaces command. You’ll have to close the file without saving changes and at the command prompt, type:
sudo nano /etc/network/interfaces.
Now you need to get the Raspberry Pi connected to your encrypted wireless network. You should be back at the command prompt, so enter the following:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
You’ll get a window that looks like this:
Again, use your keyboard to navigate the screen and match your file with what I have here. Replace YOURSSIDHERE with your wireless network name (2.4GHz only) and replace YOURPASSHERE with your WPA/WPA2 passphrase. Press CTRL+X to save, Y to confirm, and ENTER for the filename. Now it’s time to reboot the Raspberry Pi and see if it’s reachable via network. To reboot the Pi, at the command prompt type:
Your Raspberry Pi will reboot and you’ll probably see the booting status in your terminal window. Eventually, you’ll arrive back at the login prompt – go ahead and login (again, the default user/pass is pi/raspberry).
Now you can check if your network settings took effect. To do this, at the command prompt enter:
You’ll see the loopback connection (lo) and your wireless connection (wlan0). In the wlan0 section you should see inet addr, bcast, and mask. As long as this has the information you entered in the /etc/network/interfaces file, you should be set! If you’re still having troubles with WiFi, try consulting this guide on ThePiHut. At the command prompt type:
sudo shutdown -h now
This will gracefully shut down the Raspberry Pi and halt all processes. The red power LED on the Raspberry Pi will still be lit, but the green activity light will stop flashing and you’ll see a shutdown message in the terminal window. Once the activity LED is done flashing, go ahead and unplug the power from the micro USB connector. Remove the serial cable jumpers, plug the micro USB cable back in, and restart PuTTY. This time, when you start PuTTY, leave the SSH radio button selected and type in the IP address that you gave the Pi previously (in my case it was 192.168.1.10). Now when you click ‘Open’ you might get a prompt about accepting the machine’s ID, go ahead and confirm and you should be greeted with the familiar login prompt. The login is the same as before (pi/raspberry).
Phew! It took me a little while to get the wireless working my first go-round, so hopefully my experience sped up the process for you a little.
The next thing to install is WebIOPi. WebIOPi provides a web interface to control the GPIO pins on the Raspberry Pi, and thus, the garage door opener.
You’ll want to make sure you are working in the home directory on the Pi, so at the command prompt enter:
This gets you back to your home directory where files can be written as necessary. Now you are going to enter several commands to get WebIOPi installed and configured to run at boot. Bear with me and just enter the commands as followed, one by one, waiting for the previous one to complete (you’ll get a command prompt after each step completes). Ready? Enter:wget http://downloads.sourceforge.net/project/webiopi/WebIOPi-0.7.0.tar.gz
tar xvzf WebIOPi-0.7.0.tar.gz
sudo update-rc.d webiopi defaults
Once the commands are all completed, you should end up back at the login prompt. At this point, WebIOPi should have installed successfully and already started running. To test this, open your web browser and navigate to http://192.168.1.10:8000 (you’ll want to make sure and use the IP address you assigned instead of mine). You should get an HTTP login prompt, and the default login/pass for WebIOPi is webiopi/raspberry. Is it working? If so, congratulations! If not, post a comment below and I can try to get you up and running.
If it worked for you, it’s time to get busy connecting some wires. Go back to your PuTTY window, login if necessary, and shut down the Raspberry Pi by entering:
sudo shutdown -h now
Once you get the shutdown message and the green activity light stops flashing go ahead and unplug the power from your Raspberry Pi.
Alright, now get your bundle of jumper wires – you’ll need 3 of them, and also break out the 2-channel relay if you haven’t already. Here’s a crude diagram of how you want to connect the wires to your relay:
For more detail: Idiot’s Guide to a Raspberry Pi Garage Door Opener