502 Bad Gateway

502 Bad Gateway

nginx/1.4.6 (Ubuntu)


This is a project I built July 2009 for a friend's party. I'd been interested in 1) how to build a cheapish light dimmer circuit 2) controlling things from my iPod Touch 3) interactive engineering-art. So I set myself on this project. Two weeks and about 80 hours of work later, I had a solid working prototype (shown in the video).


I started by learning how to build a light dimming circuit. I knew triacs and solid state relays could be used to dim lights. Solid state relays are expensive so I took a look at a couple of existing light-dimmer designs that use triacs. This article by Andrew Kilpatrick was particularly helpful and will explain the theory of light dimming using triacs. Triacs, as well as most (maybe all) other AC light dimming methods, dim the lights by turning them on and off rapidly and in sync with the ac sine wave. I ordered the parts and set about making the AVR software that would control the TRIAC's timing.

The software on the microcontroller works like this: commands containing a light id and an intensity are received through the UART. Every time the AC voltage goes to zero (a zero-crossing), the light items are sorted by intensity, all lights that don't have an intensity of 100% are turned off, then an output compare interrupt is set for the time the next light needs to be turned on. When the output compare interrupt happens, the light specified in the top item in the array of lights is turned on, then another output compare interrupt is set up for the next light that needs to be turned on. A couple designs I saw used an interrupt that happened 256 times every AC cycle; while this certainly works, I wanted only to use output compare interrupts so that, the handler code only runs when a light is about to be turned off.

The router is a Fonera 2100 that has been updated to run a more plain version of OpenWRT Linux instead of the original FON firmware. I used the serial interface to do update the Fonera's firmware. The software on the Fonera was fairly simple: it receives commands light intensity commands via UDP and then forwards those out the UART to the AVR. To compile programs for the Fonera, I set up the OpenWRT buildroot in a VirtualBox virtual machine as per these instructions.

I learned some legit ObjectiveC iPhone/iPod programming using the Apple SDK for this project. ObjectiveC is a superset of C/C++ so it is still possible to program in C/C++ for the iPhone/iPod. For the UDP code, I used standard Unix function calls in C and the rest I wrote in ObjectiveC.


Thanks / Acknowledgements:

Comment jc on : Sun December 13, 2009, 14:37:11
Looks nice! I'd like to look at the schematic, but have no idea what CAD package uses a .SCH file. Could you consider updating the .zip to include a PDF print of the schematic? I suspect you're on a Mac, but if Windows, you can use CutePDF (a free program) to print to a PDF file.
Comment Alan on : Thu October 22, 2009, 20:20:00
Wow, great project. Nice video too. You really built this for a friend's party?, very impressive. Man I need to get a triac project under my belt.
Comment nate on : Thu October 22, 2009, 03:32:57
Saw this on Hackaday. This is really awesome. Good work!
Comment johnboiles on : Wed October 21, 2009, 10:24:33
I realize the original Fon firmware is a modified OpenWRT. I find it easier to put a more vanilla version of OpenWRT, because I know exactly what's on there. Editing the 'hacked to run OpenWRT' text to be more clear... I might look into making a plugin sometime though, thanks for the tip!
Last Edit: October 21, 2009, 10:37:42 by johnboiles  
Comment steven on : Wed October 21, 2009, 08:45:55
the FON2100 allready runs "openwrt linux".
The only hacking necessary is to have ssh access so you can add your extra sourcecode to it...
just like the people of www.francofon.org and www.freewlan.info did.

they can add your "plugin" to their distribution if you'd like...
Comment Tom Dye on : Fri October 16, 2009, 08:10:05
John, Enjoyed your Dimlit application last night at Dorkbot. Great job! I've started a company here in Austin call (MyTurf www.myturfwireless.com) Maybe we can chat sometime? My Skype name is tdyeaustin, skype me if you are interested. Also, my profile can be found on linkedin (search - linkedin tom dye austin)

Look forward to chating with you.