I had an extra Raspberry Pi laying around from when I ordered two of them a few months ago. I used the first one for a media center and it runs XBMC flawlessly allowing me to watch downloaded movies on my television. I pretty much have my entire DVD collection converted to DIVX format saved on my network for easy access. I could not find a use for the second one until I started to read about General Purpose Input / Output (GPIO) control on the Pi. Basically, the Raspberry Pi has an extra pin header for GPIO that can be controlled for switching things on and off and for reading sensors. It’s really pretty impressive for what this thing costs. I ran across a project called WEBIOPI which allows control of the GPIO from the internet. It is possible to control the Raspberry Pi remotely with any device connected to the internet.
I read about people connecting all sorts of things to their Pi. Everything from thermostats, lights, locks, to garage doors openers, cameras, and remote sensors. Some of these guys were controlling the Pi from their smartphone as well which really intrigued me.
I decided I wanted to control my garage door with my iPhone since my existing garage door opener is very short range and I wanted to be able to open it from the road. I also wanted to be able to tell if the door was left open. I hate it when I get 10 miles from house not remembering if I closed the garage door or not. There are several ways to connecting a Pi to your iPhone but I will explain how I did it with very little programming. I am not a programmer and have no real interest in complex programming so I avoid it when possible. Any smartphone will work with this setup. All you need is a web browser on your phone with a data plan.
First I will tell you this is not originally my idea. You can even buy commercial equipment from Sears that will do this for about $76 and an additional $20 yearly fee – that’s the easy way. I don’t know about you but I hate bills and fees and I also enjoy building my own stuff the hard way.
- Raspberry Pi – $25 (you will also need a 2Gb SD card and micro USB cell phone charger for it).
- Relay Shield from Radio Shack – $19
- Soldering equipment
- 50 feet of 2 conductor thermostat or door bell wire – $9
- Small proto circuit board, 1 kOhm & 10 kohm resistor
- Female jumper wires with header – $6
- Magnetic switch (the kind used on doors and windows by security companies).
- Your own existing network connecting to the internet with a router.
- Any smartphone with a web browser
I had most of this stuff laying around already. I only had to buy the relay shield & the 50 ft of wire. I am not going to explain in detail how to solder or how to setup the default operating system on the Raspberry Pi. There are many very well written tutorials on how to do both. My Raspberry Pi is running Raspbian downloaded from Here.
Once you have a Raspberry Pi running smoothly with raspbian, there are a few software packages that you need to install to make this work correctly.
I use a program called Putty to connect to my raspberry Pi remotely from another computer. You can also of course connect a monitor and keyboard directly to the Pi but I found this inconvenient since I had the Pi mounted by my router.
WebiOPi – Download here and save to your Raspberry Pi and install it manually if you want. You can skip this step and watch the video below to install automatically.
http://www.youtube.com/watch?v=6RaBz01pi4E This is a excellent video tutorial on how to install WebiOPi and configure it. I watched this video several times before I figured it all out. It’s all Linux so if you are like me and not very familiar with it, it can be challenging to use.
Here are the commands to get WebiOPi installed automatically.
Type the commands one at a time and wait until each finishes before going onto the next.
tar xvzf WebIOPi-0.6.0.tar.gz
sudo update-rc.d webiopi defaults
That last command adds webiopi to the start up so when you reboot, its automatically started. You have to login to your Pi as “root” user so you have full access. The command “sudo” is needed prior to most commands because that calls for “root’ user privilege so you can install and configure the Pi. Linux is all about security so get used to it.
Now go to: http://localhost:8000/webiopi/ on your Pi’s browser and you will see the webpage below.
Default user is “webiopi” and password is “raspberry”
You should see this screen if it works properly:
You can also see it from any other computer on your network if you type in your Pi’s IP address into the address bar.
If you watched the video, it explains how to do some simple CSS and HTML to make a simple web interface. I also disabled the password as explained in the video. I am pretty week when it comes to this stuff so I will provide my html file for you to use or modify. Feel free to change it around to suit your needs.
I used GPIO7 as the output and GPIO18 as the input (sensor for the door). You can use anyone you want.
Here is my file Index.html just right click and “save as”. It is just plain text. Save it to your working directory on your Pi.
So far, you should have a working Raspberry Pi with WebIoPi running on your network. At this point, you can only access the web control from your local network, it will not work outside your firewall yet. To get access to your Pi from anywhere on the net, you have to do a few things. I have to assume you have some basic network knowledge to get the next part working. I will explain as simply as I can but there are whole books written on this topic.
The problem with home networks is that your Internet provider will change your external IP address often. Mine changes every week or so and I have to have some way to let the “outside internet” know what my new number is.
I no longer use http://dyn.com/dns. They have a 30 day login requirement which is really annoying for their free members. It’s a shame since I have been using them for over 10 years. I now use a much better free DNS Service: http://freedns.afraid.org/ These guys are great and work perfect so far. I updated my instructions below to reflect the FreeDNS website.
First you need to sign up for a free account on http://freedns.afraid.org/ Log into your new account and add a “Subdomain” from the options on the left of the website. Pick an address from their thousands of available subdomains to use and remember it. Example: yourname.us.to Once you picked out a subdomain, go to the “Dynamic DNS” on the left menu. You should see your domain at the bottom with a note about it that says “1 Dynamic Update Candidates!”. There are several different links to the right of your domain and you want to click the “Wget script” and download this text file. This file will contain the 32 character token code that you need to paste into your router. It’s the security code that allows you to log into FreeDNS and update your IP address (your router does this automatically for you).
Next, you need to setup a “Port Forward” in your router. Every router is different. You need to forward port 8000 to your raspberry Pi address.
For example: My raspberry Pi uses 192.168.1.10 yours might be something else but it will be similar. So I want to go into my routers port forward section and forward requests for port 8000 to 192.168.1.10.
Below is what my routers port forward settings look like. I have many ports setup in there but the only one you need is Port 8000 which is highlighted in red.
The next thing you need to do is to setup your new FreeDNS account in your router. This is different on every router so you will have to look up the manual on your router and look up DNS services that are supported. I have a section just for this and its needed so that when your routers sees a IP address change, it will tell FreeDNS to update.
Every Linksys router I have used has this feature built in. I have also seen it on Netgear and Asus routers as well. I can’t say for sure if every router can do this but if yours can’t this will be a problem for you to access the web interface from outside. You should now be able to go to any computer including your iPhone and type in “yourname.us.to:8000″ and your WebIOPi interface should come up.
This is the pin out diagram which is off of the WEBioPI default page. It is extremely useful for verifying connections before you use your custom website. I pull this up on my iPhone for testing all the time. It’s called “GPIO Header” on the default WebioPi site. I setup some prototype test circuits to test the raspberry pi before I spent money on the relay shield. This step is not necessary but I wanted to understand how it all worked before I set it up.
I ended up using GPIO7 as the interface with the garage door. Basically all you need to do is touch the two wires that go to the garage door switch together to make the door activate. The PI will accomplish this by using a relay as a switch to short the two wires together.
This is the circuit I used to connect to my garage door. The screw terminals go to the two wires that connect your garage door button in the garage. You can build your own circuit if you want, but I just bought a “Relay Shield” for $20 from Radio Shack. It was nice and had 4 relays that I can use for other stuff if I want to later.
For more detail: Smartphone Garage Door Opener