Introduction: Multiple Blinking LED on the Arduino

Picture of Multiple Blinking LED on the Arduino

In this tutorial I will show you how to make multiple LEDs blink with Arduino.  You will need three LEDs, jumper wires, breadboard, and Arduino.

Step 1: Program the Arduino

Picture of Program the Arduino

Now you will need to paste the following code into the Arduino software and upload it to the Arduino.

int led = 13;
int led2 = 12;
int led3 = 11;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT); 
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100); 
  {digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);}
{digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(100);}// wait for a second
}

Step 2: Connecting GND

Picture of Connecting GND

First connect a jumper wire from GND to the negative rail on the breadboard.

Step 3: Connecting the LEDs.

Picture of Connecting the LEDs.

Then plug in the other jumper wires like this:
First, plug a wire from 13 on the Arduino to the top row on the breadboard.
Next, plug a wire from 12 on the Arduino to the top row on the breadboard.
Then plug a wire from 11 on the Arduino to the top row on the breadboard.
Space these out well. Use the picture to help you.
Now connect a wire going from the negative rail to the right of the other wires on the breadboard.
Lastly, put the longer leg of the Led (+) under the wire that goes to the Arduino. The shorter leg of the LED goes under the port that connects to the negative rail.

Step 4: Video of It Working

Picture of Video of It Working

Comments

mahi5 made it! (author)2017-11-07

Thank you for this code. I used it with Adafruit's Gemma V2. It will be a nice example to show my students tomorrow.

MusayevZ (author)2017-10-08

What to do to turn on 4 leds?

freyadutta (author)MusayevZ2017-11-05

you missed a semi colon on line 4, that's why you have an error.

MusayevZ (author)2017-10-08

What to do to turn on 4 leds?

hornet1717 made it! (author)2017-04-02

Hi

Great Job Mate, I made a few changes to the code for 8 LEDs on a board,

Here's the code; Using the following pins 13,12,11,10,9,6,5,3 on Arduino UNO R3

int led = 13;

int led2 = 12;

int led3 = 11;

int led4 = 10;

int led5 = 9;

int led6 = 6;

int led7 = 5;

int led8 = 3;

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(led7, OUTPUT);

pinMode(led8, OUTPUT);

}

// the loop routine runs over and over again forever:

void loop() {

{digitalWrite(led, HIGH);

delay (15);

digitalWrite(led, LOW);

delay(15);

digitalWrite(led, HIGH);

delay(15);

digitalWrite(led, LOW);

delay(15);}

{digitalWrite(led2, HIGH);

delay (15);

digitalWrite(led2, LOW);

delay(15);

digitalWrite(led2, HIGH);

delay(15);

digitalWrite(led2, LOW);

delay(15);}

{digitalWrite(led3, HIGH);

delay (15);

digitalWrite(led3, LOW);

delay(15);

digitalWrite(led3, HIGH);

delay(15);

digitalWrite(led3, LOW);

delay(15);}

{digitalWrite(led4, HIGH);

delay (15);

digitalWrite(led4, LOW);

delay(15);

digitalWrite(led4, HIGH);

delay(15);

digitalWrite(led4, LOW);

delay(15);}

{digitalWrite(led5, HIGH);

delay (15);

digitalWrite(led5, LOW);

delay(15);

digitalWrite(led5, HIGH);

delay(15);

digitalWrite(led5, LOW);

delay(15);}

{digitalWrite(led6, HIGH);

delay (15);

digitalWrite(led6, LOW);

delay(15);

digitalWrite(led6, HIGH);

delay(15);

digitalWrite(led6, LOW);

delay(15);}

{digitalWrite(led7, HIGH);

delay (15);

digitalWrite(led7, LOW);

delay(15);

digitalWrite(led7, HIGH);

delay(15);

digitalWrite(led7, LOW);

delay(15);}

{digitalWrite(led8, HIGH);

delay (15);

digitalWrite(led8, LOW);

delay(15);

digitalWrite(led8, HIGH);

delay(15);

digitalWrite(led8, LOW);

delay(15);

{digitalWrite(led8, HIGH);

delay (15);

digitalWrite(led8, LOW);

delay(15);

digitalWrite(led8, HIGH);

delay(15);

digitalWrite(led8, LOW);

delay(15);}

{digitalWrite(led7, HIGH);

delay (15);

digitalWrite(led7, LOW);

delay(15);

digitalWrite(led7, HIGH);

delay(15);

digitalWrite(led7, LOW);

delay(15);}

{digitalWrite(led6, HIGH);

delay (15);

digitalWrite(led6, LOW);

delay(15);

digitalWrite(led6, HIGH);

delay(15);

digitalWrite(led6, LOW);

delay(15);}

{digitalWrite(led5, HIGH);

delay (15);

digitalWrite(led5, LOW);

delay(15);

digitalWrite(led5, HIGH);

delay(15);

digitalWrite(led5, LOW);

delay(15);}

{digitalWrite(led4, HIGH);

delay (15);

digitalWrite(led4, LOW);

delay(15);

digitalWrite(led4, HIGH);

delay(15);

digitalWrite(led4, LOW);

delay(15);}

{digitalWrite(led3, HIGH);

delay (15);

digitalWrite(led3, LOW);

delay(15);

digitalWrite(led3, HIGH);

delay(15);

digitalWrite(led3, LOW);

delay(15);}

{digitalWrite(led2, HIGH);

delay (15);

digitalWrite(led2, LOW);

delay(15);

digitalWrite(led2, HIGH);

delay(15);

digitalWrite(led2, LOW);

delay(15);}

{digitalWrite(led, HIGH);

delay (15);}

digitalWrite(led, LOW);

delay(15);

digitalWrite(led, HIGH);

delay(15);

digitalWrite(led, LOW);

delay(15);}

}

H

LizzyL9 (author)2017-03-03

how can I make two lights blink at the same time?

Arafe ZawadS (author)LizzyL92017-03-24

By the way you can also do it in a much simpler manner using delay().

//turns on leds 3 and 4 for 500 millisec
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
delay(500);

//turns off leds 3 and 4 for 500 millisec
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(500);

Arafe ZawadS (author)LizzyL92017-03-24

for this you will need to multitask. Look into the millis() function.

Search: aduino multitasking to learn more

here's the code:

class Flasher

{

// Class Member Variables

// These are initialized at startup

int ledPin; // the number of the LED pin

long OnTime; // milliseconds of on-time

long OffTime; // milliseconds of off-time

// These maintain the current state

int ledState; // ledState used to set the LED

unsigned long previousMillis; // will store last time LED was updated

// Constructor - creates a Flasher

// and initializes the member variables and state

public:

Flasher(int pin, long on, long off)

{

ledPin = pin;

pinMode(ledPin, OUTPUT);

OnTime = on;

OffTime = off;

ledState = LOW;

previousMillis = 0;

}

void Update()

{

// check to see if it's time to change the state of the LED

unsigned long currentMillis = millis();

if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))

{

ledState = LOW; // Turn it off

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))

{

ledState = HIGH; // turn it on

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

}

};

Flasher led1(12, 350, 350);

Flasher led2(13, 350, 350);

void setup()

{

}

void loop()

{

led1.Update();

led2.Update();

}

taken from: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution

Jazza my top lad (author)2017-03-20

KFC is yummy
Kuam is yummy
Kuam is KFC

*dab

Jazza my top lad (author)2017-03-20

KFC is yummy
Kuam is Yummy
Kuam is KFC

*dab

arduinocoder (author)2017-02-06

far more elegant

int led3 = 3;
int led4 = 4;
int led5 = 5;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

for(int counter =3;counter<=6;counter++){
digitalWrite("led"+counter, HIGH);
delay(100);
digitalWrite("led"+counter, LOW);
delay(100);
}

}

BL4CKM4MB4 (author)arduinocoder2017-02-23

It says error.. (T_T)

KatiaA5 made it! (author)2016-11-15

This is my first project ever with Arduino or anything hardware related. Thanks so much! Super pumped to level up.

iTECHKING (author)2016-10-29

Hey,

I am using Arduino with RTC to operate the lights of my home.

I want at 10 PM all my lights should OFF and at 6 AM same should be ON.

I have completed everything but only unable to tell Arduino to read time from RTC to operate lights.

Can it be done by reading Arduino Serial Monitor? If yes, then HOW.

Also the other possible method to do same through Arduino.

Thanks.

GriffinKay made it! (author)2016-03-13

Thanks for sharing! This is one of my first projects with my Arduino and it went really well.

amg66 (author)2016-01-26

Develop a reaction game for two players. The game starts with
both LEDs on. After a random time (between 1 and 10 seconds) both LEDs go off
and the board waits for one of the buttons to be clicked. The goal of both
players is to press their button as fast as possible after they see the LEDs
turned off. The faster player wins and the appropriate LED is turned on (for 5
seconds) to show the winner. Then both LEDs are turned on and the game repeats.

there is any body now how can do it

maxyfun (author)2014-05-24

Perhaps you can help me

Im looking for code that will switch an LED on then off withing a single loop

without using the delay() function. Everywhere I look there are modified versions of the 'blink without delay' however they all have the same issue

loop starts the use millis() and a few variable to check the state if its high or low then swop the state over but only swops it once so the loop runs it switches on then the loop has to run a second time before it switches off. Any ideas?

zzglenm (author)maxyfun2015-11-19

This example will blink multiple LEDs all at different rates.

http://oosmos.com/examples/blink

kevin.swanepoel (author)maxyfun2014-08-09

http://arduino.cc/en/Reference/analogWrite

using the analog pins should help with your problem.

ariphy10 made it! (author)2015-03-04

thanks for sharing the code. I'm new to arduino programing. I'm able to run this program successfully.

wmac2 (author)ariphy102015-10-17

Thanks for the interesting photo. Could you tell us what programming board is that?

Can you share the wirings too?

mil0044 (author)2015-09-16

Do you know how to do it in a forLoop? If so can post the code

victorg13 (author)2015-08-13

are you not using resistors on your leds

rcruz32 made it! (author)2015-04-16

Thanks man! I add 3 more LEDs and it works great!!

vjoshi14 made it! (author)2015-03-29

great to see my first arduino project being supported by instructables

goldenshuttle (author)2015-02-27

if the video is private why are you posting the youtube link here ? is it to show us the black screen ? thanks for sharing

Oops sorry about that. I fixed it.

TorbenK (author)2014-11-28

Help

TorbenK (author)2014-11-28

Help

TorbenK (author)2014-11-23

It dos not work. why?

TorbenK (author)2014-11-23

thanks for your help!!

psycho.maggot (author)2014-10-27

i've modified your code, just a little bit here is:

int led = 13;
int led2 = 12;
int led3 = 11;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay (1000);
{digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(1000);}
{digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(1000);}// wait for a second
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay (100);
digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay (100);
{digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);}
{digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay (100);
digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(100);}
}

psycho.maggot (author)2014-10-27

its really works!! thanks, but i think you should add the resistors to the led. i using 220k resistor and 3 different leds,

stratovarious (author)2014-07-17

Hi, could you explain why we would list int led = 13; and not int led 1 = 13
I know default 13 is a blink led , is that why ?
Can we use 13 for other things , what do we have to do different while addressing pin 13?
Thanks.

int led = 13;
int led2 = 12;
int led3 = 11;

mralr (author)2014-01-26

worked! thanks

cwolter97 (author)2013-12-05

I would just like to say I hope you know the comments are incorrect about the length of time the delays are.

The delay you have it set to is to delay for 1/10 of a second

The Electrodog Show (author)2013-09-15

Thanks! Glad it worked.

o__o (author)2013-07-02

Thanks! This is explained perfectly, this is my first aduino project ever and it turned out beautifully!

About This Instructable

185,744views

40favorites

License:

More by The Electrodog Show:Checking Battery Status on Mediatek LinkIt OneChecking Your Current Location With MediaTek LinkIT OneControling Low Voltage Devices with MediaTek LinkIt One
Add instructable to: