# Flicker Up to 6 LEDs With Arduino

22,172

41

8

Hi there.
Christmas is coming closer, and I was wondering if I could put some candles in my room to get in the "christmas mood".
But after a friends house burned down of christmas tree candles, I don't want to burn real candles into my room.
So why don't let the Arduino light for you?!

This Instructable will show you, how to flicker up to 6 LEDs using an Arduino Microcontroller.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: What You Need...

Here are the things you will need:

-Arduino Microcontroller (or similar)
-USB cable
-LEDs (up to 6 LEDs are possible)
-Resistors (equal to the number of used LEDs)

LED resistor calculator

if you don't want to solder the circuit:
-Jumper wires

Optional:
-DC power source

-Arduino IDE
Get it here!

-TrueRandom Library
Get it here! (Instructions included)
Unzip it to your "Libraries" folder.

## Step 2: Wire It Up!

Connect the resistor to the PWM pins (e.g. 6, 9...) on the Arduino board.
Now connect the second "leg" of the resistor to the anode of the LED (long "leg")
Then connect the cathode (short "leg") of the LED to ground (GND) on the Arduino board.

Repeat this step for each LED you want to use.

When the wiring is done, continue to the next step!

## Step 3: Code It!

Copy this code to the Arduino IDE:

//Multiple LED flicker by gotcha (2010)
//
//
#include
<TrueRandom.h>   //Include the TrueRandom Library

int ledPin1 = 9; //Set the number of LEDs you use.
int ledPin2 = 10;
int ledPin3 = 11;
int ledPin4 = 6;
//You can use up to 6 LED pins

void setup()
{
pinMode(ledPin1, OUTPUT); //Sets the LED pins as output pins.
pinMode(ledPin2, OUTPUT); //Use the same pins used above
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}

void loop()
{ //Sets a random value of LED voltage in the range of 0V - 5V with PWM
analogWrite(ledPin1, TrueRandom.random(0,255)); //Use the same pins used above
analogWrite(ledPin2, TrueRandom.random(0,255));
analogWrite(ledPin3, TrueRandom.random(0,255));
analogWrite(ledPin4, TrueRandom.random(0,255));
delay(TrueRandom.random(40,70)); //Limits the speed.
}

## Step 4: Test It!

Now connect the Arduino to the PC (or MAC) with the USB cable.
Left click on the compile button at the top of the coding field.
Now wait for the compiling to be done.

A few moments later, the Arduino should start flickering the LEDs!

I hope you liked my Instructable.
Don't mind grammar and speech, I'm from Germany :)
Merry Christmas!

Participated in the
Epilog Challenge

## Recommendations

• ### Internet of Things Class

22,792 Enrolled

## 8 Discussions

The question is how to add a potentiometer to Arduino, making the 6 leds dimmable. That they flicker at high or low intensity, just like when you dim an old oil lantern and leave it all night flicker at very low intensity ?? it is easy to hook a 5K pot to arduino input, but can someone suggest how to modify the sketch please ?

I like very much ! Thank you and Happy Holidays !
Build_it_Bob

Great project, simple to implement and just perfect for the application I needed (inside a carved Halloween pumpkin display for my son). Thank you!!!

This was a great starter tutorial and introduction to Arduino. I'd like to slow down the randomness in the blinking, to make it look more like fire flies. Any suggestions on how to tweak the TrueRandom library to do this?

Hey phatguppy.

After reading this instructable and looking at the code it looks as if the delay between flickers comes from the written code instead of the library.

In the line 'delay(TrueRandom.random(40,70)); //Limits the speed.'

I believe the '(40,70)' are ms. It's setting a range for time between flickers. Change them for a longer delay.

Hey,

thanks for the infromtation,but somehow i can't add the needed lines in the instructable.

For those wanting to use the code: put " "
after "#include"

Hi Gotcha,

Great little script. I am planning to use it to drive lights on a wreath. I noticed that you left out the library name in your include statement.

For those looking to duplicate this code, note that you need to download and install the TrueRandom library into your Arduino folders, then complete the include statement in the script as follows:

#include

the library can be found here: