Halloween LEDs

There comes a time in a mouse’s life when it is no longer a mouse: it transpires away from the realm of the living and joins the ever increasing pile of electronics junk.

My mouse, computer mouse that is, gave its last breath not too long ago.  In the midst of an intense Portal2 Co-Op session, my mouse suddenly decided that it would no longer acknowledge any my clicks, irrespective of how hard I pressed the buttons.  Thankfully, spare mice are plentiful in these parts, and it wasn’t long until the Portal2 endeavor vigorously ensued.

I suppose that in normal circumstances I should have felt at least a bit sad about my loss, but instead I couldn’t wait to open it up and figure out the decorative multi-color LED was wired (this video illustrates this feature).

After cracking the mouse open, I was surprised to find that the LED only had two leads instead of the standard four.  Aha!  This is one of those integrated LEDs: and sure enough, wiring straight to 5V produced the ever changing color patterns.  Very simple to wire up, entertaining to watch, but not terribly useful to keep around: unless of course Halloween is around the corner.

Carve a pumpkin (there’s a great online tutorial on how to carve amazing looking pumpkins), wire up the LED, and you got yourself a groovy jack-o-lantern.

Integrated RGB LED wired to a 5V boost circuit from Sparkfun and batteries.

Integrated RGB LED wired to a 5V boost circuit from Sparkfun and batteries.

Carving a Pumpkin.

Carving a Pumpkin.

Integrated RGB LED circuit inside the pumpkin.

Integrated RGB LED circuit inside the pumpkin.

Mission accomplished, unless, of course, you have two carved pumpkins.  It simply wouldn’t be fair for the other pumpkin to not have any cool LEDs as well.  The second pumpkin, carved by my lovely assistant, is pretty evil looking.  Groovy LEDs don’t go well with evil pumpkins, but it’s nothing a small PIC and a few spare LEDs can’t fix.

Evil pumpkin, and friend.

Evil pumpkin, and friend.

For this project, you’ll need:

  1. A small breadboard (something like this would do)
  2. A 0.1uF ceramic capacitor.
  3. A 4.7k-10kOhm resistor.
  4. Five 220Ohm resistors.
  5. Five LEDs of your choice (preferably of different colors).
  6. A 3.3V or 5V boost converter (Sparkfun builds a great little boost converter)

Wire them up like this:

Halloween LED Schematic

Halloween LED Schematic

And with the little snippet of code below, you got yourself a pretty angry multi-colored LED pattern.

Multi-Color LED breadboard for evil pumpkin.

Multi-Color LED breadboard for evil pumpkin.

What the code does, in essence, is initialize Timer0 of the PIC18 to a random value, and starts the timer.  On every timer interrupt, a random value is assigned to the LEDs (wired to PORTC0 to PORTC4), and a new random value is assigned to the timer.  The LEDs thus turn on/off randomly, and at a random intervals.  The end effect is pretty cool, to say the least.  But don’t take my word for it: check it this video that show both pumpkins in action.

Notice that the Timer0 prescaler is off.  If you want the LEDs to change more slowly (say, because the holidays are soon coming), uncomment these two lines in the main() routine, and the end result will be much more soothing.

Needless to say, these little pumpkins turned out great.  Happy Halloween!

Happy Halloween!

Happy Halloween!

 

 

Tagged with: , , , , , , , , , ,
Posted in Jonathan's Corner

Leave a Reply

Your email address will not be published. Required fields are marked *

*


× 5 = thirty

Tera Charge