This was a fun little project I put together in a few
hours for a homemade-themed gift exchange this
Christmas. I had on-hand a "Full Color LED" from
Radio Shack (part 276-0028) which caught my eye
on my last visit there.
The LED has a common anode and three
cathodes, one for each of the three primary colors:
red, blue and green. By changing the duty cycle
(the fraction of time the pin is low) on each of the
three pins controlling the colors, I could create any
The next step was the housing. I found a good
candidate in a prize I had won for judging a technical
paper competition at Georgia Tech years ago. It was
a sphere with a golf ball inside that you had to move
around until it balanced on a tee. The sphere was a
good size and the polystyrene base made for an easy
mounting of the components.
My first thought for controlling the colors was a simple algorithm
that I think is called "the drunk's walk" - for each step, choose
randomly which direction the step will be (one color a little
brighter, another a little dimmer). The problem with this is that
you're unlikely to get far; you'll likely keep drifting around
wherever you start. The chances of wandering all the way to a
vibrant color were small and I certainly didn't want this thing just
showing different shades of off-white!
Instead I devised a configuration of 10 nodes: three of them
pure colors, seven of them intermediates. The globe would
start randomly on one of these nodes. Every three seconds an
adjacent node would be randomly chosen and the color would
slowly shift to that one over the course of 20 steps.
Here is a graphical representation of the ten nodes showing
(roughly) their colors. The numbers show proportions of red,
blue and green respectively.
The result is a random walk that gets to the more vibrant
colors reasonably often. To be really nit-picky, I don't use all
of the colors that could be generated, only those along the
The circuit is quite simple - a battery, a 5V regulator, a PIC
16F688 microcontroller, and three 470-Ohm resistors from
the LED to the control pins. I later replaced the battery with a
plug consisting of a "wall wart" transformer and a 9V clip.
I was always bothered by pseudo-random number generators
that return the same string of values each time you power
them on. I didn't want this project to always follow the same
path, so I seed the random number generator with a floating
value that's measured off one of the unconnected pins of the
microcontroller. I figure that's quite random.
The hardest part of the project was actually frosting the
globe. I wanted the whole surface to light up instead of
letting you see the LED inside. First I tried this "spray
snow" for drawing Christmas images on windows. That
was too fluffy and clumpy. My friend Lindsay told be
about Frosted Glass Finish from Krylon. That worked
pretty well, but after trying to make it more frosted with
multiple coats I realized that it simply doesn't happen. (I
think the stuff works by having the outer surface of the
layer it leaves be rough instead of smooth, scattering the
light. Spraying an additional coat covers up that rough
surface, making it transparent and adds a new
translucent outer surface, so it's no better than the first
I realized that I needed a multiple-step approach. I found
some translucent packing foam and added two additional
layers with this - one in the form of a "bonnet" over the
LED to start to scatter the light, and one layer just inside
the surface of the glass sphere. All told it does a fairly
good job of creating the effect I was looking for.