Pseudo-Random Flickering Jack-O-Lantern LED using ATtiny13

Pseudo_Random_Flicker_ATtiny13

It’s time to get those jack-o-lanterns twinkling for Halloween. If you don’t want to use candles or buy a jack-o-lantern light this Halloween you can do like [Johannes Bauer] and code your own pseudo-random flickering super bright LED. His wife wanted their pumpkin to be illuminated this year and he knew it would be easy to do with an Arduino, but that would be overkill for such a simple project. Plus, he doesn’t have an arduino. [Johannes] used very few components; 4 slightly depleted AA batteries, a super bright LED, 680 ohm resistor and a little custom code on an 8 pin ATtiny13. The circuit does work great for a pumpkin lantern but his video is more of a tutorial on coding linear congruential generator (LCG) for the 8 bit pseudo-random LED flickering.

The code is short and can be gleaned from the YouTube video. [Johannes] used avr-gcc to compile and has packaged his code and build scripts for download. The hex file can be flashed over to the chip using avrdude or AVR Studio. If you have any ATtiny13s lying around you should cobble this hack together just in time to emulate that real look of a pumpkin candle without the hassles and hazards of real flames.

If you want something with a lot more light that still has that candle like flicker then checkout “Flickering Pumpkin Lanterns” that used the signal from LED tea lights to power some 12 V lamps.

Follow along after the break to watch [Johannes Bauer’s] video.

Comments

  1. Georg says:

    This isn’t a hack. It’s an LED randomly going on and off.

    • Blue Footed Booby says:

      “It’s not a hack. It’s [description of end result that totally ignores tools, method, materials, or anything else that could actually be used to determine if it's a hack].”

  2. larsi.org says:

    The code uses an 8 bit “random” generator which cycles after 256 calls. The code also requests 20 numbers a second – so the light flickers with a 13 second sequence and then repeats over and over. I think a 16 bit generator would have been better…

  3. perfect_d says:

    So why not grab the least significant bit off an analog read?

    • Joe says:

      Yup, that’s a possibility. However with an open pin or pin fixed to a certain voltage it’s hard to ensure that the LSB is really random (and not influenced due to systemic effects such as the 50Hz/60Hz background and such). So I’d rather use the LSB to seed a PRNG, which would ensure entropy pool mixing and yield better results.

  4. Chamb Onz says:

    Isn’t there a built in random number generator in arduino? Doesn’t arduino support attiny85 (at about $1 a piece)? The rest is some batteries, a resistor and an LED.

  5. JIm B says:

    First off, thanks Johannes for taking the time to share this. My one suggestion would be to use the PWM to modulate the intensity of the LED instead of making it on/off. A real candle is always lit, so it always produces some light. Vary the PWM duty cycle from 20% on the “off” state and 100% in the “on” state, or ramp it between those duty cycles for bonus points.

    • Joe says:

      Thanks for your kind words.

      Initially I planned on using the PWM generator (and I have the LED connected to the OC pin for this exact reason); the result would certainly look better, but I just didn’t bother for this project. Should be very easy to integrate however.

    • Stoneshop says:

      Eggzacktley. I did something similar a couple of years ago, and ended up with 3 LEDs running off an ATTIny (85, IIRC) using separate PWM channels, and not letting the modulation drop below 20% for each of the channels. Used the random() function in the GCC libs, which I found to be good enough.

  6. ThorstenS says:

    I like it – its so simple!
    thx

  7. required says:

    for those who also want to know what kind of software melt is:
    http://www.mltframework.org/

  8. kpharck says:

    My kids’ table lamps use pseudo-random generator for color cycling of an RGB LED with software-PWM on ATTiny85, with internal clock. Free tools, avr-gcc, built on Linux, programmed with AVR-Dragon two years ago. I did not find justification to call it a hack worth anybody’s time.

  9. Did this ages ago using a PIC 12C508 but these days you could use a Tiny13.
    Someone should totally make one of these using a red phlatlight, these are incredibly efficient and can illuminate the largest pumpkins.
    For glare reduction, I’d avoid using a lens at all and mount the LED, heatsink and driver in the top
    of the pumpkin projecting downwards.

  10. There are also circuits “out there” for transistor based shift registers that can be modified to flicker an LED, a simple one can be built using a modified multivibrator circuit with each stage coupled to the next and a tap point used to further randomize the output.
    I built this back in 1995 :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s