Introduction: Three Electronic Candles

This project is a combination of two other projects I posted on Instructables:

I also reused the software of both projects to create this project.

The idea started when we bought some Electronic Candles in different sizes that use LEDs. Although they look nice there were some disadvantages:

  • They do not work on rechargeable batteries since the electronics in the electronic candle could not handle the lower voltage. I prefer using rechargeable batteries over regular batteries to save the environment
  • The smallest one used a button cell which does not have such a long life span
  • The LED light of the flame was quite bright and a little bit too white instead of yellow

So I decided to get rid of these disadvantages and since the three where always used together I combined them all on one platform. If you look at the Illuminated presents project you will see that I used the same approach for this project. The following functions are performed:

  • Control 3 LEDs at the same time using one PIC12F615 microcontroller that generates the candle effect. The microcontroller software was written in the JAL programming language.
  • Switch the electronic candles and off using a push button. The original candles had a slide switch at the bottom but using a push button makes on/off control easier.
  • Switch off the candles when the battery voltage drops below 3.0 Volt. This will prevent the rechargeable batteries from being discharged too much.

The candle effect is obtained using Pulse Width Modulation (PWM) to control the brightness of the LEDs. For more information on PWM see: e.g. Wikipedia.

Step 1: The Mechanical Work

For making the platform I used MDF which can easily be glued using wood glue.

I also replaced the existing LEDs by high brightness LEDs which had a more yellow color. The candles were glued on the top of the platform. In the pictures you see what I used and the final result.

Step 2: The Electronics

The schematic diagram shows the electronic components you need. Three LEDs are controlled independently of each other. Since high brightness LEDs are used it is not required to use the standard current of 20mA per LED. Instead the LED current is about 9 mA if it is continuously on, which it hardly is. Because of the low current the PIC is capable of driving the LEDs directly without the need for extra electronics. The electronics is powered by a three AA rechargeable batteries and can be powered on or off by pressing the push button switch.

You need the following electronic components for this project:

  • 1 PIC microcontroller 12F615 with socket
  • 2 Ceramic capacitors: 2 * 100nF
  • Resistors: 1 * 33k, 3 * 180 Ohm
  • 3 high brightness yellow LEDs
  • 1 push button switch
  • 1 battery holder for 3 AA batteries

You can build the circuit on a breadboard and does not require much space, as can be seen in the picture. The peak current of the whole system is around 20 mA but it hardly reaches this because of the constantly changing current through the LEDs.

Step 3: The Software

The software performs the following tasks:

  • When the device is reset by the push button switch it will turn the device on if it was off or it turns the device off if it was on. Off means putting the PIC12F615 into sleep mode in which it hardly consumes any power.
  • Generate a Pulse Width Modulation (PWM) signal to change the brightness of the LEDs and so to create the candle effect. This is done using a timer and an interrupt service routine that controls the output pins of the PIC12F615 that turn the LEDs on and off.
  • During operation the PIC will measure the supply voltage using its on-board Analog to Digital Converter (ADC). When this voltage drops below 3.0 V, it will switch the LEDs off and the PIC will put the itself into sleep mode. The PIC could still operate well at 3.0 V but it is not good for the rechargeable batteries to be completely drained.

For the candle effect, the PWM frequency must be high enough as to prevent seeing any flickering by the human eye – except for the flickering like a candle does - and so I chose a PWM frequency of 100 Hz. I decided to use a step increment of 5 to increase the brightness of the LEDs and a step decrement of 50 to decrease the brightness of the LED as to get a better candle effect. Since the timer uses a range of 0 to 255 for the duty cycle, the timer needs to run at 255 / 5 = 51 times the normal frequency or 5100 Hz. This results in a timer interrupt every 196 us of which the interrupt routine itself takes at most 60 us.

As already mentioned, the software was written in JAL. Since I did not use any specific JAL libraries for this project I had to make a random generator for creating a candle effect. This generator uses a linear feedback shift register for generating a random number.

The JAL source file – renamed to .txt instead of .jal as to be able to upload the file - and the Intel Hex file for programming the PIC are attached. If you are interested in using the PIC microcontroller with JAL – a Pascal like programming language – visit the JAL website.

Step 4: The Final Result

The two video show the final result. One video is shot with some light and one is shot in the dark as to better see the candle effect.

It might be that you see some of the 100 Hz frequency because of the camera that was used to shoot the videos.

Have fun making this Instructable and looking forward to you reactions and results.