Realistic Flickering Flame Effect With Arduino and LED's

108,826

139

38

About: Hi, my name is Mike and I am from London, England. I really like to make things and in particular like to do creative things with Arduinos and electronics. Other hobbies include astrophotography and sailing....

Intro: Realistic Flickering Flame Effect With Arduino and LED's

In this project we will use 3 LED's and an Arduino to create a realistic fire effect that could be used in a diorama, model railway or a fake fireplace in your home or put one inside a frosted glass jar or tube and no-one would know it wasn't a real candle inside.

This is a really simple project suited to beginners.

Step 1: Step 1 - Wire Up the LED's

Wire up 3 LED's. Use 2 x Diffused Yellow and 1 x Diffused RED. You can increase the number of LED's if you wanted a larger or brighter display. Consider the use of transistors if your amperage will go over that which can be supplied by the Arduino.

Use resistors that suit your particular type of LED.

Step 2: Enter the Code

Enter this code:

// LED Fire Effect

int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 11;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
delay(random(100));
}

Step 3: Upload and Run

Upload the code to the Arduino and run it. You will now have a pretty realistic flame/fire effect from the LED's. Bounce the light off a white card or a mirror to achieve the full effect.

Step 4: Video of the Effect

Video of the effect. The colours and the effect don't show up very well in the video. In real life it is a very effective flame effect. Give it a try.


Share

    Recommendations

    • Audio Contest 2018

      Audio Contest 2018
    • Furniture Contest 2018

      Furniture Contest 2018
    • Tiny Home Contest

      Tiny Home Contest

    38 Discussions

    0
    None
    rastita

    4 years ago on Introduction

    Hi! thanks you very much... i was coding something very complex and you gave us a very simple but efective candle efect ;)

    Instead of a full Arduino, i used an ATTiny85, and added a swich...

    Thanks a lot!

    2014-04-05 00.30.41.jpg2014-04-05 00.30.09.jpg
    5 replies
    0
    None
    LightsActionrastita

    Reply 3 years ago

    Do you have a circuit diagram by any chance?

    0
    None
    metalhead8711rastita

    Reply 3 years ago on Introduction

    hi rastita. this is a very awesome project you created. im interested how you wired it. it. code uses two leds but i see four. lol unless the others are just there. i see you connected leds with resistors on pins 5 and 6. your battery case looks like it takes two 1.5V batteries. AA or AAA? truly and awesome project.

    0
    None
    rastitan71

    Reply 3 years ago on Introduction

    Yeah! for shure.... but it´s almost the same than the original :)

    But only using 2 leds, instead of 3...

    // LED Fire Effect

    int ledPin1 = 5;

    int ledPin2 = 6;

    //int ledPin3 = 11;

    void setup()

    {

    pinMode(ledPin1, OUTPUT);

    pinMode(ledPin2, OUTPUT);

    //pinMode(ledPin3, OUTPUT);

    }

    void loop() {

    analogWrite(ledPin1, random(80)+35);

    analogWrite(ledPin2, random(120)+135);

    //analogWrite(ledPin3, random(120)+135);

    delay(random(100));

    }

    0
    None
    n71rastita

    Reply 3 years ago on Introduction

    Actually there could be 3 random flickers + 2 random fading using PWM on pins 0 and 1 with bursts to simulate little flame with occasional crackers. :-)

    0
    None

    Thanks for the great Instructable! Saved me a bunch of time writing the code myself!

    0
    None
    AKIREEV

    6 months ago

    A simple, yet convincing flame effect!

    Used it with two 8 mm LEDs (red and orange, but may switch red with something else, not sure yet) and AtTiny85.

    I have used two bright LEDs with clear cases, these were the brightest, but had to sand them with sandpaper (fine grit) to make lighting more even.

    Thank you very much!

    0
    None
    payams2

    9 months ago

    thanks a lot, i done it for myself and join to its realistic fun's. i want just modify it a bit for adding some random wind effects

    0
    None
    DylanS63

    1 year ago

    Can I make this exact circuit but with LED strips that run 12v?

    I want to make a flicker box that can simulate fire for my short films, the only problem with normal ones you buy in stores, they are really really expensive :(

    I appreciatie any answer.

    Dylan

    0
    None
    sergiolrmartins

    2 years ago

    Thanks for the simple but efective code.

    I included the randomSeed(392113) command in the Setup function

    and change the analogWrite commando to analogWrite(ledPin1, random(0,255));

    just to make it more effective and cleaner.

    and

    0
    None
    GuyH13

    2 years ago

    Thanks, I borrowed your approach for a project I'm doing with my son's Minecraft torch from Thinkgeek... enhanced it as a part of my main loop so that it also incorporated a random timer controlling the flicker. Not the most elegant code but it ended up looking very cool!

    Just posting an excerpt of the code, but as you might guess the elapsedTimeSinceOn is millis() now - millis() when the torch was turned on (button press):

    if ((torchLEDState == TORCH_FLICKER) && (elapsedTimeSinceOn % lastFlickerDelay == 0)) {

    // let's make the torch flicker

    if (DEBUG) { Serial.println("8 - running flicker routine"); }

    int brightness = random(10);

    int duration = random(10);

    switch (brightness) {

    case 0:

    case 1:

    case 2:

    case 3:

    case 4:

    case 5:

    analogWrite(torchLED_pin, random(120) + 50);

    break;

    case 6:

    case 7:

    analogWrite(torchLED_pin, random(120) + 85);

    break;

    case 8:

    case 9:

    analogWrite(torchLED_pin, random(120) + 135);

    break;

    }

    switch (duration) {

    case 0:

    case 1:

    case 2:

    case 3:

    case 4:

    lastFlickerDelay = 100;

    break;

    case 5:

    case 6:

    lastFlickerDelay = 200;

    break;

    case 7:

    case 8:

    lastFlickerDelay = 500;

    break;

    case 9:

    lastFlickerDelay = 50;

    break;

    }

    }

    0
    None
    Heyup

    2 years ago

    not tried this yet, too busy at moment, but the effect looks really good. well done and thanks for sharing

    John :)

    0
    None
    a_wrek

    3 years ago

    Hello, when i try to upload the code to the arduino i get this error message.
    Collect2.EXE: error: Id returned 5 exit statusError compiling.

    2 replies