LEDs should be smarter. Sure we have flashing LED assemblies and even rudimentary RGB-flashing discrete LEDs. But LEDs themselves are predominately just dumb lights. There’s no real reason for this. Fab processes for microcontrollers and LEDs aren’t that dissimilar. It should be possible to have both in a single LED-like package.
There is a glimmer of this happening, like the “RGB LED Slow Colour Change” LEDs you can get. You can see an example of these being used on the Embarrasingly Easy CaseMod. Unfortunately you can’t change the cycle time or anything else of how these LEDs work. So let’s make our own. These prototype Smart LEDs will necessarily be larger than a production run, but the size is getting close, giving us a feeling for how we might use them.
Smart LED Designs
Making a Smart LED just means adding a micrcontroller to an existing LED. Alex Weber created a neat version of this with his Programmable LED that has a blink pattern programmed by you via its integrated photocell.
The circuits for the Smart LEDs on this page are essentially the same as Alex’s, except that an RGB LED is used instead. Electrically, an RGB LED looks like three LEDs. An Atmel AVR ATtiny13 is the microcontroller brain.
In this design the ATtiny13 is running at 4.8MHz from its internal oscillator with no clock scaling. That means it draws only about 1mA of current. The LEDs draw around 10mA for each color, so 30 mA total. But that’s a maximum, and by using PWM the average power consumption is a good deal less.
If you know how to program an Arduino, you can program one of these chips. The result is soldered together directly without the need of a PCB. Its only input is two power pins. Hook these pins up to any voltage between 2.7V and 5.5V to light it up.
The particular LED used for this Smart LED is a common anode one with a diffused lens. The common anode is connected to the positive power connection instead of ground, and all the on/off logic for the LED in the software must be flipped.
The software for this Smart LED is just a simple 3-channel software PWM color fade similar to Clay Shirky’s Arduino example.
Adding senses to the Smart LED
As with Alex’s Programmable LED, adding senses to a Smart LED is easy. Instead of a photocell, let’s add a piezo element ripped from an old buzzer and used as a knock sensor. Using piezos as knock sensors is easy. By soldering the piezo directly to the Smart LED, a nice little package is made.
The algorithm initially implemented for this Smart LED is a RGB color change like before, but if the piezo is struck, the LED turns white for a moment, then decaying down in brightness before returning back to the color changing.
In this case, a common-cathode RGB LED with crystal-clear lens was used with a small diffuser on top.

RGB LEDs and Diffusers
Most RGB LEDs you can find have a really narrow viewing angle, making them useful for flashlights maybe but not for ambient indicators. And because the red, green, and blue LED die are off axis from the integral lens that creates the narrow viewing angle, you don’t get very good color mixing. Sometimes you can find diffuse integral lenses on RGB LEDs (like the smaller smart LED pictured) but more often the lenses are crystal clear.
By placing a small dab of diffusive material on top of the LED, the light is mixed and diffused. In this case, a cylinder of unmelted hot glue was used:

And then you can get a wide range nicely mixed colors:

Smart LED Prototype Programming
The fun part about building these devices is that you can reprogram them after you’ve constructed them. That is, if you’re careful and leave the back of the chips exposed. With the backs exposed you can press them only an 8-pin socket that is connected to a standard AVR ISP connector.
Smart LED Prototype Software
The software is really pretty easy stuff once you’re over the hurdle of AVR programming in general. As mentioned above, Arduino is a great place to start and you can review the Spooky Arduino class notes for a directed introduction.
After you know Arduino, it’s a small step to program AVR chips directly. You’ll need something like the AVRISP mkII programmer (about $35 from Digikey).
This particular software is kinda tricky because it implements software PWM. The software PWM code is directly borrowed from Atmel Application Note #136, “Low-Jitter Multi-Channel Software PWM” by Andy Gayne. I’ve successfully used the code to scale up to 16 software PWM channels and here, down to 3. At the 4.8MHz clock, the PWM rate is about 73Hz, which is low enough to cause beating with the 30 Hz rate of the video below. The PWM frequency could be increased with a few timer changes, but the rate isn’t visible to humans and any changes away from a known-working system should be avoided.
The software:
The code was quickly thrown together from another project, so the comments are either non-existent or misleading.
Smart LEDs Video Demo
Here’s a little demo of both of the Smart LEDs.







I’ve programmed arduino’s before but not sure how close this is to that enviroment? Does the code for these chips need to be programmed in C? when you say “If you know how to program an Arduino, you can program one of these chips. ” what do you mean? are they identical? any help much appreciated.
best
bert
Left by bert on March 26th, 2007