Introduction: How to Build a 5 Channel Flame-less LED Candle Simulator
Our hackerspace "The Rabbit Hole" is having a pumpkin carving night and we wanted to try something different to light the pumpkins. So I came up with this Flamless LED candle that uses an inexpensive IC and parts but simulates the random flickering of a candle.
When complete this circuit emulates the flicker of a candle including random "wind / draft" events of fast dim flickering. The 5 LEDs flicker at different rates and intensities allowing you to drive 5 individual candles with a course effect, one candle with a smoother effect, or any combination in between.
The first part of this Instructable goes over kit construction which are available from tymkrs.com at [add link to store here]. If you wish to build a unit from scratch all the design data is available at http://www.wire2wire.org/LED_candle/LED_candle.html
The second half of the Instructable goes over the circuit operation and firmware in greater detail.
Here is a video of the prototype circuit running on my bench.
And here is a demo of the final kit set up in a jack-o-lantern pumpkin.
Step 1: Required Materials for the Flame-less LED Candle Simulator
- 5 channel LED candle kit https://www.tindie.com/products/tymkrs/led-candle-simulator/
- 4x double AA batteries (fresh alkaline batteries work best)
- soldering iron
- wire cutters
- Helping hands (optional)
- tip cleaner (optional)
Step 2: Before We Start, Some Math!
- power supply
If you're going to change power supplies and/or LEDs read on since this will affect the value of the LED current limit resistor.
For the power supply your main options are either batteries or an AC to DC adapter.
- If using an AC to DC adapter choose something in the 3.5V to 5.5V range.
The higher the better for this application. Especially if you're going to use blue or white LEDs (due to their high forward voltage they may not operate at the lower end of the range)
- If using batteries the range moves to 4.5V to 6V.
The other thing to consider when picking your power supply is the current draw of the circuit. The largest load is the LEDs. The easiest way to estimate circuit current draw is to take the LED current (see next section) multiply by 5 and add 50mA. If using a AC-DC adapter make sure it's output rating is greater than this number. If using batteries see notes in the next section.
If you want to swap out the LEDs, consider the following:
When looking at the LED data sheet there are 2 numbers you will need for the next section.
- Forward voltage minimum / typical (Note: verify that the max voltage plus 0.6V is less than your power supply voltage)
- Forward current recommended max (continuous NOT pulsed / peak)
To set the LED current limit resistor value use the following formula:
Rled = resistor value in ohms (ALWAYS round up to the next standard value)
Vsupply = voltage of your power supply
Vfled = Forward voltage minimum / typical of your led
Iled = max continuous led forward current in A (note 1000mA = 1A)
In the current kit we have the following values
Vfled = 2.1V
Iled = 50mA => 0.05A
(6 - 2.1)/0.05 = 78 Ohms
78 Ohms is not a standard 5% resistor so round up to the next standard value of 82 Ohms.
Step 3: Begin Kit Assembly: Check Your Kit!
The kit should include:
- 1x pic12f508 (programmed)
- 1x 100uF 16V cap
- 1x 0.1uF 50V cap
- 5x 2N3904 transistor
- 3x Yellow LEDs 5mm15deg
- 2x Red LEDs 5mm 15deg
- 5x 82 ohm resistor 5% 1/4W (gray, red, black, gold)
- 5x 1k ohm resistors 5% 1/4W (brown, black, red gold)
- 1x Battery holder
- 1x 8 pin dip socket
- 1x PCB
Step 4: Install the Micro Socket
Install the micro socket as shown in location IC1.
Note the small notch in the socket! Make sure it matches the notch in the silk screen (down when holding the PCB as shown) This has no affect in the circuit operation but makes installing the micro later easier.
Solder the socket in place
Step 5: Install the 0.1uF Capacitor
Install the 0.1uF cap as shown in location C2.
Note this cap is NOT polarized and can be installed either way.
Solder the cap in place and clip the leads off
Step 6: Install the 1k Resistors
Locate the 1k resistors (brown, black, red, gold) and form the legs as shown in image two.
Next install 5 1k resistors in locations R3, R4, R5, R6, R7 as shown.
Solder the resistors in place and clip the leads off
Step 7: Install the LED Current Limiting Resistors
Locate the LED current limit resistors (82 ohm (gray, red, black, gold). if using the parts provided in the kit.) and form the legs as shown in step 4.
Next install 5 LED current limit resistors in locations R8, R9, R10, R11, R12 as shown.
Solder the resistors in place and clip the leads off
Step 8: Install the 100uF Capacitor
Next locate the 100uF capacitor.
Note: this device IS polarized and must be installed as shown. The - lead is marked on the side of the cap and is the shorter of the two leads.
Install the cap in location C1 with the - side to the center of the PCB as shown.
Solder the cap in place and clip the leads off
Step 9: Install the Battery Holder
Locate the battery holder and strip the wires approximately 1/4" long, then "tin" them (coat the stripped wires with solder).
Install the wires as shown into CN1 (black - to the inside of the PCB, red + to the outside of the PCB)
Solder the resistors in place and clip the excess off.
Step 10: Install the Jumper in R1
Warning, sorry but the LEDs in the picture are out of sequence, please ignore that
Take a resistor leg trimming and bend it into a U shape.
Install the resistor leg into location R1 as shown.
Solder and trim off the excess.
Step 11: Step 9 Install the LEDs
Locate your LEDs and identify the cathode (-) pin of the LEDs. The negative pin has the shorter leg and you'll notice the flat on the body.
The standard kits include 2 Red and 3 Yellow LEDs. Installation location has no affect on circuit operation. But for best visual effect place one red LED on either end of the PCB surrounded by the yellows.
Install the LED with the cathode (-) side on the inside of the PCB next to the current limiting resistor, as shown in locations LED1, LED2, LED3, LED4, and LED5.
Solder in place and trim off any excess.
- When installing the LEDs lift them off the card by ~1/2" before soldering. This will allow you to aim the LEDs by bending them. If mounted flush on the PCB, you will not be able to adjust their angle and can end up with 2 distinct spots of light.
- To minimize mounting space when embedding in a candle, mount the LEDs on wires, then attach the wires to the PCB. The Anode (+) side of all the LEDs is common so only a 6 conductor cable is needed. This will allow you to remotely mount the PCB and have a minimal foot print of just the LEDs in the top of the candle.
Step 12: Install the Transistors
Locate the 5 2N3904 NPN transistors and install them as shown and locations T1, T2, T3, T4, and T5.
Note they are polarized and the flat side of the transistor case needs to match the flat side on the silk screen.
Step 13: Install the Microcontroller
Locate the PIC12F8508 micro controller.
If you're using the controller from the kit, it's already programmed with the firmware.
Make sure to remove the aluminum foil protecting it during shipping (see photo 2).
If you're not using the controller from the kit, you'll need to program the firmware.
Install the micro into the socket added earlier.
Make sure the notch in the micro matches the notch in the socket and more importantly the silk screen on the card.
Installing the micro backwards WILL DAMAGE it.
You may need to bend the legs in slightly to get the micro-controller to fit into the socket.
Step 14: Testing the Flame-less LED Candle Simulator
If everything is assembled correctly all the LEDs should light brightly with a slow flicker.
After a few seconds the LEDs should dim and run with a fast flicker for a few seconds before returning to slow bright flicker.
If this checks out your LED candle is ready for use.
If for some reason things are not working right, check the following:
- If you get a dim slow followed by a bright fast flicker, check the jumper is installed in R1 and that R2 is open (output active level select)
- If you have 1 or more LEDs not lit (but at least 1 lit), check the orientation of the non-functional LED and transistor (they are polarized and must be installed correctly). Also check and for general solder defects (opens shorts).
- If none of the LEDs are lit, check that the micro is installed correctly, has been programmed, that the battery pack is installed correctly, that the batteries are good, and also check for general solder defects (opens shorts).
Step 15: Flame-less LED Candle Simulator Circuit Descripton
Electrically this project is relatively simple.
Battery holder CN1, and Caps C1, and C2 make up a unregulated power supply feeding everything else.
The PIC micro IC1, R1, and R2 make up the brains of the circuit. Most of the function is just firmware running on the micro.
R1 and R2 set the active output mode. When R1 is populated the outputs are high when the LED should be on. When R2 is populated the outputs are low when the LED should be on. For the application in this kit R1 should be populated for active high outputs.
There are 5 identical LED driver channels. The first is made up of LED1, R8, T1, and R5.
LED1 and R8 are the LED and it's current limit resistor. The current limit resistor is chosen based on the LEDs forward current limit and how bright you want the LED to be when running. See slide #2 for more information.
T1 acts as a power driver for the micro. It takes a low current (~6mA) signal from the micro and allows it to drive up to a 200mA load. R5 is the base current limit resistor for the transistor. Normally this will not need to be adjusted.
Step 16: Flame-less LED Candle Simulator Firmware Description
The source for the firmware (as well as the binary images for programming) are available at
There is extensive documentation in the source on how the firmware works in detail so will only go over the high points here.
This project uses a pic12F508 this particular micro has very little in the way of hardware peripherals. In fact it does not even have interrupts and only has a single hardware timer / counter. This particularly made generating PWM signals difficult. The main reason I chose this micro was I had stock on hand and their low cost.
The datasheet for this part can be found here:
The core components of the firmware are the 5 LFSR PRBS generators and the PWM engine. To generate the maximum amount of random flicker with the limited resources I had I decided to set up 5 identical Linear Feedback Shift Registers Pseudo Random Bitstream Generators. Each one is 16 bits long and starts with a unique seed. The unique seeds are important since the generators are NOT truly random and they will repeat after a given amount of time. If they all started with the same seed the 5 channels would be in sync and not produce as nice of a flicker. To maximize the randomness between channels the low order bits are used to set the brightness of that channel and the upper order bits of the previous channel are used to set the dwell time this brightness level will be held. The LFSR is only updated to the next value when a new brightness level is needed. So by using another channels generator to set the Dwell time the individual channel patterns should shift over time with respect to each other.
The other function in the code is a "wind" mode. This at a code level is a random event that last for a random duration. When a wind event is triggered the code picks 2 new numbers from the existing LFSR one is used as the duration of the event and the other is the delay before the event triggers again after it finishes. During the wind event the only real difference in the PWM code is the masks applied to dwell time and the brightness value. For the "normal" mode they are set up to produce a bright and slow flicker. During wind mode the masks are adjusted to produce a dimmer and faster flicker.
As stated earlier there are no interrupts or peripherals available on this micro other than a single timer. To implement the 5 channel PWM generator I first set up timer 0 to be a counter running slow enough that I could execute all the instruction needed to update the LFSR before the next count but fast enough that the dimming was smooth to the eye. In the main loop there is logic that does one of two things with the timer. First if the timer rolls over to 0 it turns on all the outputs. Second it compares the count to the individual channel brightness levels. If the level is lower than the current count it turns the channel off.
This method worked well for this application but is not without drawbacks. The main drawback is since the timer count must be slower than the time your update instructions take it would not work well on large complex programs (or the PWM would be very grainy).