LED Candle

Discussions of programming Microcontrollers in C
User avatar
Paul
Posts: 16
Joined: Fri Apr 01, 2016 5:15 pm

LED Candle

Postby Paul » Wed Apr 06, 2016 11:17 pm

Inspired by all the LED candles in the stores these days, I wanted to have some fun building my own fake candle with dual LED's to see if I could get a better flicker effect. Atmel's ATTiny10 is perfect for this project since it has two PWM channels to control brightness of each LED separately and another timer available for LED flickering.

Image

My candle is powered by a 3 pack of AAA batteries and the circuit is mounted on top of the battery pack. The candle body is simply a piece of paper (I used semi translucent Vellum) shaped into a hollow cylinder that gives the candle shape. I attached a small breadboard to a battery pack to prototype the candle. I already have the Tiny10 mounted on a dip converter so it fits nicely into the breadboard.

Image

While this worked fine for prototyping I found I couldn't download a program the Tiny10 in circuit unless I isolated it from the LED's with a couple of transistors. Also note there is a photoresistor that is used for daylight sensing so the LED's are only on in the dark of night. Overall the hardware is quite simple as shown in the schematic.

Image

JP1 is battery power. JP3 and JP4 allow for in circuit programming of the Tiny10. Daylight is sensed by charging C1 and then measuring the discharge time through the photoresistor. Sensing daylight is done as seldom as possible with the mcu powering off and sleeping between sense operations during daylight hours to conserve battery power. After it was working satisfactorily, I designed a small circuit board that could be attached to the battery case with double sided foam tape and had a small batch of them made in China at Itead Studio. I was able to put 4 up on the board so ended up with 40 boards for $10 + shipping, just had to wait a month for them to arrive in the mail.

Image

The next step was to get them all programmed. Hooking five loose wires into the holes with good contact long enough to download a program was slow going to say the least. Fortunately I found some pogo test contacts on eBay and they made an excellent programming pen for these little boards. The pogo contacts are spring loaded so all I have to do is push the contacts onto the holes and hit the program key on the PC. Simple and fast.

Image
Image

One thing to remember is at least one of the batteries is drained very low, almost zero, when the candle finally goes out. This is very stressful on batteries and many of them leak in the final hours so be sure to have something under the battery pack so furniture is not damaged. If I make more I will use a battery case that is enclosed to catch the juices. In the mean time this version has some experimental code to sense the battery voltage and turn off early but it's not working out so well because by the time the pack voltage is below the threshold one of the batteries is probably already at zero and possibly leaking. The best solution may be to include a boost converter in the design so the batteries will be connected in parallel instead of serial which should prevent any one of them going to zero.

The compiled code is 954 bytes so barley fits on the tiny10. Amazing that these little chips can even be programmed in C. The files for this project can be downloaded from https://github.com/pduke/LED-Candle. The included Makefile is set up to use my TPI Programmer and will need to be updated if you are using a different programmer.

BobaMosfet
Posts: 30
Joined: Tue Jan 19, 2016 2:48 pm

Re: LED Candle

Postby BobaMosfet » Mon Oct 09, 2017 3:45 pm

Nice project all around. I like the look, and the methodical approach. Very neat. Fantastic idea for the 5-pogo-pin programming-connector method. Quick and easy.

BM


Return to “C Programming”

Who is online

Users browsing this forum: No registered users and 1 guest