Flickering LED Candle

113,363

82

26

Posted

Introduction: Flickering LED Candle

Take a dollar-store "flickering" LED candle, add an AVR ATtiny13 and a little code, and you get an LED candle that looks almost real.


Step 1: Open Up the Candle Casing

A thumbnail seemed to be the best tool for this job. The casing isn't glued. There's just a friction-fit post that goes into a receiving hole in the cover. Work around the cover edge and the base part will begin to come loose. Don't get into a hurry because the wires connecting to the LED module inside are very fine and easy to break. We'll be re-using these wires, so be careful.

Step 2: Remove the LED Module

The LED, connected to its base, is friction-fit into the base of the plastic candle flame. Twist slightly and pull to remove. Make note of the wire colors, as they may be different from the unit I used. I'll be using "yellow" for the negative and "red" for the positive.

Step 3: Move the Cathode Wire

We won't be using the original circuit, which is a low-side switch that just flickers the LED off for a few milliseconds periodically. Carefully unsolder the yellow wire and move it to the LED cathode on the middle pin. The wire is really fine. Use a hot soldering iron to melt the original connection. Add a little fresh solder to the center pin. Then you can hold the wire against the center pin and reflow the solder joint easily.

Step 4: Program Your Chip

We'll be cutting off the unused pins of the ATtiny13, so be sure to program the chip before you do that! I use a USBtinyISP programmer and a SparkFun breakout board in a solderless breadboard. We're using the internal oscillator of the tiny13, so there's no need to burn any of the programming fuses. You can use the hex file provided or compile your own with the provided source code.

Some notes about the source code: I used a generic random number generator because the stdlib rand() function is almost twice as large. When you only have 1024 bytes of Flash memory, every byte counts! Also, the millisecond timer doesn't seem to line up with real wall-clock time. But since exact timing isn't really important in this application, I just eyeballed the timing. Purists might cringe, but I'm a pragmatist. :)

To program using the supplied hex file on a Linux system, use this command line:

avrdude -p attiny13 -P usb -c usbtiny -U flash:w:flicker.hex

WinAVR users will probably know the right incantation. I don't do Windows. :D

Update: flicker2.zip contains the second version of the code, featuring two flicker patterns (flicker-up and flicker-down), along with adding watchdog protection to reset the chip if the mainline code should freeze.

Step 5: Trim the Chip Legs

Since we're only using pins 4, 5 and 8, trim off the rest of the pins with a set of flush cutters.

Step 6: Make Some Connections

The red (positive) lead was cut in an earlier step. Now you will strip about 3/16 of an inch of insulation from each of the free ends of the red lead. Then tin the exposed wire. Tin the remaining pins on your tiny13 chip, too. This makes attaching the fine wires much easier, because you can hold the wire against the chip pin and reflow the solder joint with a hot soldering iron.

The red lead from the LED module connects to pin 5. The red lead from the battery goes to pin 8.

For the ground connection, use a fine-pointed needle-nose pliers to bend the pin in a "U". With a sharp utility knife, score the insulation of the yellow (negative) wire and pull it apart to expose a small section of bare wire. Place that section of bare wire in the "U" you just bent and solder carefully.

Step 7: Add Some Insulation

Vinyl electrical tape makes a good candidate for insulating the exposed leads. Cut a narrow strip and slip it between the chip body and the pins, then fold it over. Once insulated, fold the pins over the bottom of the chip.

Step 8: Test Your Circuit

Now is a good time to install the battery and check your work.

Step 9: Put It All Together

Re-insert the LED into the bottom of the plastic flame. Tuck the chip into the case where it won't wedge against the on-off switch. Finally, put the base of the candle back, seating the post on the bottom into the socket in the cover.

Step 10: Look! a Flickering Flame!

If everything has worked well, you now have a flickering "flame" atop your LED candle. Brag to your friends. The units I bought came 2 to a package, so you could easily demonstrate a before-and-after.


Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • First Time Author Contest 2018

    First Time Author Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

26 Comments

analogwrite(random)
delay(random)

Does the same thing.

The latest tea lights from Dollar Tree have eliminated the circuit board, but they still flicker. HOW? There is nothing but an LED, a CR2032 button cell and a switch. The plastic case is the same as in your photos.

046.JPG

I think that the led has a built-in chip for flickering the light. Just as those multi-color-changing leds that does have a built-in chip too.

Yes, that's it! Totally amazing, a little chip encased in the diode. Thank you for pointing this out.

I wanted to use one of these with a solar panel out of a garden light and have a remote way of turning off several (like 100 at a time) of these....any ideas would be welcomed

Replying to an old post I know, but what he said about the common PS.

Then, wirelessly control the PS on the cheap by using a low cost RF transceiver pair from Sparkfun or Modern Device (check out the Arduino JeeNode!)

hundreds of leds rock! just get a common power source and wire everything together and put a switch on the power unit

Does the flame have a slow or fast flicker, or both? It's hard to tell from the video you uploaded. Is it possible to slow the flicker down, or make it flicker less often? (Of course, that maybe what "flicker2.zip" does in one of it's 2 patterns.) Could this circuit drive a warm white LED? (The amber LEDs used in most of the LED candles I've seen are amber or orange.) Of course if one could make up a whole group of these with orange and amber LEDs and put them into a group to make a glowing embers effect for a fire place. Thanks for a great Instructable! Viva LInux!

The flicker speed is fixed in both patterns, but it's east to change the constants that govern the timing and make it flicker as fast/slow as you like. The circuit can easily drive a warm white LED. Your white/amber embers effect sounds nice, but I'd expect you'll need an awful lot of LEDs (and chips). That would probably be better accomplished with a chip with more I/O and a charlieplexed array of LEDs.

Thanks, SolidSilver. I'm looking forward to making this. I don't have any experience with coding, but I'm sure that if I follow your directions it'll all work just fine.