A few months ago, I decided to learn a bit more about electronics and I stared to do this by looking at the Arduino platform. There are a lot of learning resources, and as a programmer in my day job, the transition to programming on the Arduino platform was quite easy.
The first practical project that I put together was a web interface to control my garage door. I did this so that I wouldn't have to carry a garage door opener when riding my bike. As I always have my phone on me, it's one less thing to carry.
Garage door motor
I opened up the garage door opener and after some poking around with a multimeter, found two pins that had a potential difference of 35V which when shorted together activated the motor. Those were pins 1 and 3 on the header, highlighted in the photo below.
RelayI needed a relay to connect the pins on the garage door motor when I wanted to open or close the garage door on the Arduino. I picked up a TRR1A05D00 relay and wrote the initial code to make the door open. I later found out that I needed to put a diode across the input of the relay to suppress voltage spikes when turning the relay off. I got myself a few 1N4004s and put one across the relay.
SensorsOne problem with the initial circuit was that I could only toggle the garage door motor with the relay. If the door was closed, I could open it and if the door was open, I could close it. However, I couldn't tell whether the door was open or closed.
I tried out some A3144 Hall Effect Sensors. These detect a nearby magnetic field and by using a couple of them with some rare earth magnets attached to the door, I was able to detect the door position.
These sensors require three connections, ground, power and output. The output pin goes low when there is a magnetic field detected, and remans high if no field is detected.
Status IndicatorsThe sensors worked well, but during testing, I thought that it would be nice to have a status indicator so that I could easily tell whether the sensors were sensing the magnets. I had just bough a bunch of RGB LEDs which were perfect. I could use a different colour for the door open, closed and in-between.
Putting it All TogetherI decided on the EtherTen from Freetronics. This board combines an Arduino Uno with an Ethernet shield, allowing me to hook up the board to my local network. I used the ProtoShield Short as the prototype board to connect my components. It works well with the EtherTen as it is (as the name implies) shorter than standard Arduino shields, leaving enough room for the Ethernet connector.
We can make out a number of things from the photo below.
Firstly, the relay is connected to D2 of the relay, which is also connected to the negative end of the flyback diode. I put connected header pins to the relay output so I could attach the wires to go to the garage door motor.
Secondly, pins D5, D6 and D7 are connected through resistors to the red, green and blue leads of the LED. I used 150Ω for the red and 100Ω for green and blue to limit the current to 20mA per output.
Thirdly, I soldered on a couple of three three pin headers to connect to the hall effect sensors which were mounted near the garage door.
The EtherTen is cable tied in place around a conduit running on the ceiling of my garage. It could be neater, but this seems to do the trick for now. In the photo below, the LED is blue, indicating that the door is in the open position.
The sensors are just taped in place on the garage door frame. You can see one of the magnets on the door next to the lower sensor.
Finally, a photo of everything together. In it, you can see the EtherTen, and a wireless router attached to the ceiling. Also note the Ethernet over power adapter that connects back to the home network. You can also see the cabling; the green and white cables for the garage door motor and the ribbon cable for the sensors.
The Arduino sketch is available on github and is is released into the public domain. Apart from the standard Arduino libraries, the sketch requires the Webduino library which handles the web serving.
The server responds to both HTTP GETs and POSTs to control the URL. In both cases, a parameter of named "action" needs to be set to either "open" or "close" to operate the door.
The page has a touch icon, served from the /icon.png path. This icon is used for iPhones when the link is saved to the home screen. I have tried using different images for both the favicon and the iOS icon, however, I've run into issues uploading to code the Arduino and compiler problems when the encoded image data gets larger than about 1.1kb.
The software I'm running on my Arduino is slightly different to what I've posted on github. I can't release the graphics for my icons, I drew up a simple favion an iOS icon for the released code.
I also read my network configuration from the Arduino's EEPROM, using a library that I wrote. For the released code, I've gone back to configuring the network settings in the code. I'll talk about that library in a future post.