Introduction: 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.
49 Comments
9 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!
Reply 7 years ago
Do you have a circuit diagram by any chance?
Reply 7 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.
Reply 8 years ago on Introduction
Hey Rastita, can you provide the code? Superthanx!
Reply 8 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));
}
Reply 8 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. :-)
9 years ago on Introduction
Very simple; & very impressive..
10 years ago on Introduction
Thanks for the great Instructable! Saved me a bunch of time writing the code myself!
13 years ago on Step 4
Very COOL Earthshine. You have invented a very nice thing.
Reply 13 years ago on Step 4
Thanks
Question 6 weeks ago on Step 2
왜 0~255가 아니가 0~120을 해서 135를 더한 거예요?
Question 4 months ago
Thanks for the circuit, works well with 3 LEDs. Have used 3 sets of LEDs and obviously to much current as fails after some use. You mention the use of transistors, do you have further info on that circuitry.
Thank you,
Allan
11 months ago on Introduction
Could I use this code to control lets say 16 3mm 3v Leds? I want to add leds to the thrusters on a model kit and want them to have this flickering effect? I have an arduino UNO.
Reply 11 months ago
Yes that would work as long as you have enough current to power all 16 LEDs. You may need to power them from an external source and use the Arduino to control them via transistors or something like that as it is unlikely you'll get enough current from the Arduino pins for that many LEDs.
Question 2 years ago
question if I put a 5 or 10k pot on the ground line back to the uno could I get varriable brightness of candle or will it break everything ?
Answer 2 years ago
That will also reduce voltage to the Arduino, so yeah it will totally break everything.
Reply 2 years ago
Sorry I mean the ground going from all 3 leds back to the Arduino?
Reply 2 years ago
It would sorta work but it is not ideal as each LED is meant to have it's own current limiting resistor. It would be a lot easier to do it in code using the PWM functions.
2 years ago
Thanks. Very elegant coding.
3 years ago on Step 4
Brilliant. This is just what I've needed for a dollhouse project. Thanks!