0% found this document useful (1 vote)
56 views3 pages

Arduino Project9

Uploaded by

Anil Kumar Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
56 views3 pages

Arduino Project9

Uploaded by

Anil Kumar Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

Project 9
LED Fire Effect

54
Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

Project 9 - LED Fire Effect


Project 9 will use LEDʼs and a flickering random light
effect, using PWM again, to recreate the effect of a
flickering flame. If you were to place these LEDʼs
inside a model house on a model railway layout, for // Project 9 - LED Fire Effect
example, you could create a special effect of the
house being on fire, or you could place it into a fake int ledPin1 = 9;
fireplace in your house to give a fire effect. This is a int ledPin2 = 10;
int ledPin3 = 11;
simple example of how LEDʼs can be used to create
SFX for movies, stage plays, model dioramaʼs, model
void setup()
railways, etc. {
pinMode(ledPin1, OUTPUT);
What you will need pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
Red Diffused LED
void loop()
{
2 x Yellow Diffused analogWrite(ledPin1, random(120)+135);
LEDʼs analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
delay(random(100));
3 x 150Ω Resistor }

Connect it up
Now press the Verify/Compile button at the top of the
Now, first make sure that your Arduino is powered off. IDE to make sure there are no errors in your code. If
You can do this either by unplugging the USB cable or this is successful you can now click the Upload button
by taking out the Power Selector Jumper on the to upload the code to your Arduino.
Arduino board. Then connect everything up like this :-
If you have done everything right you should now see
the LEDʼs flickering in a random manner to simulate a
flame or fire effect.

Now letʼs take a look at the code and the hardware


and find out how they both work.

When you are happy that everything is connected up


correctly, power up your Arduino and connect the USB
cable.

Enter the code

Now, open up the Arduino IDE and type in the


following code :-
55
Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

Project 9 - Code Overview


// Project 9 - LED Fire Effect
We then set them up to be outputs.
int ledPin1 = 9;
int ledPin2 = 10; pinMode(ledPin1, OUTPUT);
int ledPin3 = 11; pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
void setup()
{
The main program loop then sends out a random
pinMode(ledPin1, OUTPUT);
value between 0 and 120, and then add 135 to it to get
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT); full LED brightness, to the PWM pins 9, 10 and 11.
}
analogWrite(ledPin1, random(120)+135);
void loop() analogWrite(ledPin2, random(120)+135);
{ analogWrite(ledPin3, random(120)+135);
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135); Then finally we have a random delay between on and
analogWrite(ledPin3, random(120)+135); 100ms.
delay(random(100));
} delay(random(100));

So letʼs take a look at the code for this project. First The main loop then starts again causing the flicker
we declare and initialise some integer variables that light effect you can see.
will hold the values for the Digital Pins we are going to
connect our LEDʼs to. Bounce the light off a white card or a mirror onto your
wall and you will see a very realistic flame effect.
int ledPin1 = 9;
int ledPin2 = 10; As the hardware is simple and we should understand
int ledPin3 = 11; it by now we will jump right into Project 10.

Exercises

1. Using a blue LED


or two, see if you can
flashes of light from an recreate the effect of
arc welder. the

2. Using a Blue and Re


d LED recreate the eff
emergency vehicle. ect of the lights on an

56

You might also like