Weekender Project: Mini LED Candle

Works done? Proud of it? Show off here! Let's see what you've built can help inspire others.

Weekender Project: Mini LED Candle

Postby Brian Griffin » Sat Sep 29, 2012 8:55 pm

Project Description: Mini LED candle

What will you do if you have mini 8 and 14-pin microcontrollers lying around on your desk? They are good for small battery operated projects.

Also, the mooncake festival is on the corner. So, without having to burn yourself with candle (or the lanterns), you can use 2AA batteries, an ultra-bright LED and a microcontroller! (alongside with a transistor and some resistors).

Compiler: MikroC v5.60 (can be compiled in demo mode)

Hardware:

- PIC16F1503 (PIC10F and PIC12F are encouraged, but with modifications of code)
- Ultra-bright LED (orange/yellow) and a suitable resistor (R1) for maximum brightness. Please refer the LED's datasheet and select a resistor which allows acceptable level of current or you risk frying it!
- 2N3904 transistor. (these things are everywhere)
- a cut, tiny veroboard/stripboard/donutboard
- another resistor (1K)

How the "flickering candle" work: By exploiting the PWM module inside, we can control the LED brightness easily. The "flickering" is caused by the random numbers generated in the microcontroller. The random-number generator isn't any random, it's pseudo-random, which means it is a Linear Shift Feedback Register (LFSR). The numbers will repeat every few hundred numbers, but it is very hard to notice, hence it's being pseudorandon. On every each time (like 50miliseconds in the project) there will be a random number sent to the PWM registers.

Schematic:
ledcandle.gif
Schematic
ledcandle.gif (8.87 KiB) Viewed 5157 times


Program code: Attached

Picture:
pic16f1503candle.gif
LED candle with 2AA batteries


(It's flickering, but I can catch only one brightness on the camera)

References: Myke Predko's "Programming and Customizing the PIC Microcontroller". Though the book is old, but he sure has a lot of cool home projects for the microcontroller.

Note: The microcontroller is running without crystal, only 62.5kHz internal oscillator and a approximately 60Hz PWM. The low speed is used because it's meant for battery operation.
Attachments
pic16f1503-candle.zip
LED candle
(22.39 KiB) Downloaded 415 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Weekender Project: Mini LED Candle

Postby robosang » Mon Oct 01, 2012 8:16 am

Good work! :D
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Weekender Project: Mini LED Candle

Postby sahniana » Thu Nov 08, 2012 6:08 pm

simple, but really interesting. like :!:
sahniana
Apprentice
 
Posts: 44
Joined: Wed Jul 01, 2009 4:30 pm

Re: Weekender Project: Mini LED Candle

Postby Brian Griffin » Wed Sep 18, 2013 11:44 pm

The Mooncake festival is at the corner, so why not build another LED candle? Place it in the lantern, of course. This time it's using a PIC10F322, and a clothespeg (special thanks to Mats Engstrom from SmallRoomLabs, Malaysia - Instructables) to hold the AG13/LR44 batteries.

Components:
PIC10F322 microcontroller
8-pin DIP socket
1K resistor
BC547B transistor
a current limiting resistor for LED, R2 (check the LED datasheet for the maximum allowable current)
LED (ultra bright yellow recommended)
two AG13 batteries (can be bought cheap from Mr.DIY or something)

Schematics:
ledcandle2.png
Schematics


Picture:
ledcandle2-pic.jpg
Electronic candle


How it works? First the microcontroller starts by sampling the electronic noise from an ADC pin, then it is placed into the pseudo random number generator as a seed. Then, every 100ms, the random number generator creates a random number, and place into the PWM module which controls the brightness of the LED. So you will see the flickering, almost like a candle. There are limitations, of course, like the sequence of the random numbers are the same if you stare it long enough, but usually you will forget it fast enough too, because on every start of the candle, the seed for the generator is different. :)

This thing shuts off into sleep after 3 hours (or you will bleed these poor AG13s dry), so if you need to restart it, rip out the batteries and place it again.

References: http://stackoverflow.com/questions/1689 ... on-of-code
Attachments
ledcandle2.zip
Source Code
(4.5 KiB) Downloaded 391 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Weekender Project: Mini LED Candle

Postby robosang » Mon Sep 23, 2013 10:46 am

Good man!
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to Project Showcase

Who is online

Users browsing this forum: No registered users and 3 guests

cron