Flicker up to 6 LEDs with Arduino


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.
For more information about Arduino visit http://www.arduino.cc/


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

-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!

LEDs with Arduino circuit (1)

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.

Step 3: Code It!

Copy this code to the Arduino IDE:

//Multiple LED flicker by gotcha (2010)
<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.

Read more: Flicker up to 6 LEDs with Arduino

Leave a Comment

Your email address will not be published. Required fields are marked *