Pseudo-Random Flickering Jack-O-Lantern LED Using 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.

17 thoughts on “Pseudo-Random Flickering Jack-O-Lantern LED Using ATtiny13

    1. “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].”

  1. 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…

    1. Yup, that’s true. Although I don’t think the 13 second repetition is a problem (because I guess few people will stare at a flickering pumpkin for 13 seconds straight), it can easily be fixed by using a uint16_t and a multiplier of 65 (also efficient without multiplication libs) and an increment of 30677.

    1. 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.

  2. 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.

    1. 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.

    2. 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.

  3. 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.

  4. 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.

  5. 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

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.