Picture of 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.

Remove these adsRemove these ads by Signing Up

Step 1: Open up the candle casing

Picture of 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

Picture of 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

Picture of 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.
steve07013 years ago
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.
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.
2wistd6 years ago
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
GrantLevy4 years ago
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 "" 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!
SolidSilver (author)  GrantLevy4 years ago
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.
trainables5 years ago
Step 4, learn Latin.  (Sorry, I don't know Latin well enough to teach you.)
MixMasterM6 years ago
I just whacked this up on a breadboard using an ATtiny45 (pretty similar to the 13 you used, but lots more memory so I can do more eventually). I adjusted the Makefile for the device and the 8MHz internal clock and it flashed and works for a while. However, after a couple minutes, it seems to lock-up and the LED just stays at one brightness. Pulling the 5V briefly resets it and it runs for a while longer. This is my first time using AVR and also programming a microcontroller in C (I used asm on PICs before) but I'm wondering if the gcc is generating a leak of some sort that eventually causes something to fill-up/overflow/whatever and that's what locks the AVR up? Has anyone else seen any problems like this? Any tips/input/ideas? Anyway, this is a nice Instructable and one I've kept bookmarked for when I finally got my USBtiny built and working (aka earlier this morning ;) ) Mike
How are you storing your timers?  What do you do if your time to wait is negative?

Both millis() and micros() are unsigned long
check for overflow.

int moo;

if (millis() - moo > DELAY)
   moo = millis();

Will lock up on moo overflow.

unsigned long moo;

if (millis()  - moo > DELAY)
   moo = millis();
} else {  if (moo > millis(){moo=millis();}}

SolidSilver (author)  spandox5 years ago
My code uses delay_us() from the AVR runtime libs.  My guess is that it properly checks for over/underflows, but I haven't actually audited the code. In any case, your point is well taken.  I learned this the hard way when I first started embedded coding (way back when on the 8051 family).
SolidSilver (author)  MixMasterM6 years ago
I looked through the delay code while working on this project and didn't see any dynamic allocation, so I don't think there's much chance of a memory leak. It should have hit the tiny13 quicker than a 45, anyway, no? The only thing I can think of is that I didn't activate the watchdog timer. Your symptom sounds like the main loop is locking up. I'll look into adding the watchdog in, so if the main loop does lock up, the chip will automatically reset.
SolidSilver (author)  SolidSilver6 years ago
I redid the code for this project to add watchdog protection (hopefully it addresses cheeze69's freezeup problem on a tiny45) and alternating flicker patterns (up and down) that change with each reset or power cycle. Download the new code from step 4 of this Instructable.
Hi SolidSilver, I just tried the new code on the Tiny45. I re-compiled it again after adjusting the makefile for 8.0MHz and attiny45, using the AVRmacpack. It's running nicely and the new feature with the "low ficker high" and "high flicker low" works fine. I've run it for over 5 minutes without any lockup. Not sure if it was something with the gcc generated code or maybe I had some noise in the circuit (I have a couple fluorescent lights on the same 120v circuit and have seen the project lock-up when I switch a light off). Anyway, I definitely like the "low flicker high" mode best, so I'll modify the code to use that entirely. Now to find a good LED/etc. to make an old "Pirates of the Carribean" lantern for my back porch. Thanks for the great project and continued work!
SolidSilver (author)  MixMasterM6 years ago
Good news! Glad it works better for you.
zanfr6 years ago
a while ago i saw a similar tutorial but done with a zener diode i believe, the idea was to build a zener-based "noise" generator and use it to power the LED
subrotos zanfr5 years ago
Can you publish a link for the zener based circuit? (I'm requesting on a year old comment -- sorry about that.)

SolidSilver (author)  zanfr6 years ago
That's an interesting idea, but I think the effect would be quite different and more random than my "flame profile".
well it woudl likely flicker alot more; of course sometimes it would drop below the "starting" voltage of the LED but only so briefly i dont know if it would be objectionable
SolidSilver (author) 6 years ago
Welcome Hack-a-day readers! Thanks for the link, Hack-a-day!
Strublay6 years ago
Very nice Instructable, on a project that not many people have posted about (I've found plenty of massively complicated flicker circuits on other sites for big projects but no small [as in one led] applications.) This is going to help make my Halloween projects a lot cheaper and less.... combustible... Thank you!
You might want to move a picture into the first step so it displays in the listing.
SolidSilver (author)  Tool Using Animal6 years ago
Thanks! It's my first Instructable, so I missed that point.