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:
Program code: Attached
Picture:
(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.