I wasn't happy with any existing Arduino code for LED
control so I wrote my own. I think it's quite nice though it needs polishing and probably some features added. It does light timing, sunrise/sunset fading and all that jazz.
Some improvements over existing code:
- Shorter and simpler
- Accurately set clock from a script on your PC. You don't need to modify any code or upload any sketches!
- Much, much smoother dimming, especially at the low end (due to a combination of higher resolution PWM output and every-second dimming adjustment instead of every-minute).
- Higher resolution PWM also means you can dim your LEDs down to a lower intensity than before if your driver is capable. I've found I can dim my LEDs down far enough to be used as moonlights.
- Flexible timing logic. You can do anything you want (with minor modifications) so long as it's on a 24hr cycle.
There are also some limitations:
- Your Arduino needs to have either a DS3231(eg: ChronoDot) or DS1307 Real Time Clock chip connected via I2C (because I have one of those). These are probably the two most common RTC chips.
- It only provides 2 PWM outputs (because I only have 2 LED strings). Of course you can modulate as many strings as you want from a single PWM signal but they'll modulate in unison.
- It should work with the Arduino Duimilanove/Uno and probably any other micro-controller that uses the Atmega168/328 chip. In particular it will not work as-is with the Arduino Mega due to a difference in the onboard timers.
- It depends on a few libraries but I've bundled them up in a download link below.
- Only compiles with versions 0022/0023 of the Arduino IDE, not version 1.0 (yet!)
It works great for me. I'd love feedback, error reports, suggestions, free beers, etc. Post in the thread or PM me.
I hope this will be useful to people!
Get the code:
The libraries that don't come with the Arduino environment by default are bundled in the zipfile above. Just extract that zip into the libraries
folder inside your sketchbook folder and then restart the Arduino IDE. If libraries
doesn't exist, create it first.
Until I get around to writing documentation just post or PM installation questions/issues and I'll try to help.
12/11/2011 (only documentation changes, no need to upgrade!)