Go Down

Topic: Multiple Candle Flicker (up to 24 circuits) (Read 1 time) previous topic - next topic


Hi, I am totally new to the Arduino and an electronics beginner.  I have a cutaway model of a sailing ship that I want to add internal illumination to.  I am looking to use 24 individual miniature LED's designed to look like candle lanterns.  I could group some of them but I would like to keep as many individual flicker circuits as possible for maximum realism.

I am currently testing individual circuits using the CDT3460 chip but I also thought there might be an Arduino solution.

There are many candle flicker sketches around but nearly all seem to be for single flames with sngle or multiple LED's.  I need many, many more individual flicker circuits.

Anyone seen anything like this?


Yes flickering is just like blinking. This sketch was for a small Christmas tree, change the on / off times to make it look like it is flickering.

Code: [Select]

/* Random blinking lights
for use on a christmas tree
By Mike Cook

#define numberOfLights 16

byte pins[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
byte pinState[numberOfLights];
long int changeTime[numberOfLights];
int flashRate[numberOfLights];
long flashChange;   // how often to change the flashing patterns

void setup() {
  for(int i = 0; i< numberOfLights; i++) {
    pinMode(pins[i], OUTPUT);
    changeTime[i] = millis() + random(1000, 200);
    pinState[i] = LOW;

void loop() {
  for(int i = 0; i < numberOfLights; i++) {
   if(changeTime[i] <= millis()) {
   pinState[i] = ~pinState[i];
   digitalWrite(pins[i], pinState[i]);
   changeTime[i] = millis() + flashRate[i];
  if(flashChange <= millis()) setFlashTime();

void setFlashTime(){
  for(int i=0; i<numberOfLights; i++){
    flashRate[i] = random(200, 1500);
  flashChange = millis() + 100000;  // next time to change pattern


Thanks for the reply, but isn't that going to look a little too "blinky"?  When I said flickering, I meant 3 or 4 pwm light levels from say 10 or 20% up to 100%.  The difficulty being not enough analog outputs.


You could use several shift registers and create PWM outputs on them with this:-


You can simulate PWM writing by simply toggling on and off at different rates. The default PWM frequency is only 490 Hz. With a 16 MHz clock you have lots of room to set up various duty cycles on various pins.

This thread here shows how I simulated PWM on all 20 pins by using an interrupt:

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Mike, Nick,

Thanks very much - I will be experimenting with those circuits as soon as I get some components together.


A TLC5947 is perfect for this, as it has built in 24 channel, 12-bit PWM. You can get very smooth changes in brightness, and almost imperceptible flickers if you need it. It only require any four digital pins from your Arduino.

The TLC5947 is available from many distributors as a surface mount chip. I also have a breakout board for it: http://macetech.com/store/index.php?main_page=product_info&products_id=22
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Go Up