Intro: LED Candle for Paper Lanterns
This project shows how to make realistic looking candle effect for use for example inside Paper Lanterns. It uses a NodeMCU board (ESP8266) to drive NeoPixels, also known as WS2812 LEDs. Look at the videos in the results sections to see a comparison with real candles.
Step 1: Hardware
WS2812 LEDs, are full-colour LEDs that are connected in serial, are individually addressable, and can have their red, green and blue components set between 0 and 255.
From a previous project I had some strips left, as there was some spacing between the LEDs, I choose to use 4 LEDs in a cross for one lantern.
As with all WS2812 projects it is recommended to add a small resistor on the first data channel (centre wire). And in addition, add a capacitor near the power supply. Power Amp depends on the number of LEDs.
Step 2: Software
In this project the LEDs are not driven by an Arduino, but a NodeMCU board (ESP8266) with MicroPython on it.
The first step is top flash the micropython firmware following this guide: Getting started with MicroPython on the ESP8266
It is then possible to use it to drive the LEDs like shown in 11. Controlling NeoPixels
On my board Machine.pin(4) is D2 (as can be seen on the picture). Do not forget to connect the gnd with the LEDs.
To make the led flicker like a real candle I wrote a small python program which randomly updates the individual leds following the gaussian distribution found in the comments of this article:
The program (main.py) creates as many LED_light objects as are specified in the LED_COUNT constant.
By altering randomly, the length and intensity of the light, it creates a nice effect.
Probability Random LED Brightness<br>50% 77% – 80% (its barely noticeable) 30% 80% – 100% (very noticeable, sim. air flicker) 5% 50% – 80% (very noticeable, blown out flame) 5% 40% – 50% (very noticeable, blown out flame) 10% 30% – 40% (very noticeable, blown out flame) all of this with a Gaussian actualization time. Probability Random Time 90% 20 ms 3% 20 – 30 ms 3% 10 – 20 ms 4% 0 – 10 ms
source: Eric's comment on https://cpldcpu.wordpress.com/2016/01/05/reverse-engineering-a-real-candle/
Step 3: Result
The result provides a nice effect as if there was some wind making the candle flicker.
In the second video the lanterns in the back are LED based and the once in the front are real candles for comparison.