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.

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

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

Step 3: 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

9 People Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

36 Discussions

0
None
Embedded for fun

7 months ago

Hi..
I just have a question, I have gone trough some example codes for arduino nano board but my doubt was not clear, I wanted to build a code where leds are connected to port b for all the 8 pins and I wanna blinking them alternatively similarly how we blink in 8051 just by sending hex value to port 0x55 and 0xaa.
I wanna know how to send a hex value to port in arduino can anybody tell me.
Thank you

0
None
gadamsettysaiprakash

Question 10 months ago

How can we blink these leds if I some 60 to 70 ? The pins are limited on arduino

0
None
ms0133594

Question 1 year ago on Introduction

Led serial wise blink hogi ek ke baad ek but mujhe ye krna h ki....pehle led 1,2,3,4 ek k baad ek blink ho fir led 4,3,2,1 ek ke baad ek band ho

Plz tell me iski

programming kaise hogi

1 answer
0
None
icengms0133594

Answer 1 year ago

hogi ek ke baad ek but mujhe ye krna h ki means ??

0
None
GWG12345

1 year ago

I had to run the last jumper from the GND on the Arduino itself to have the third led flash. It worked but I am not sure why.

0
None
JanV160

Question 1 year ago on Step 4

only 2 leds lite with me

0
None
freyaduttaMusayevZ

Reply 1 year ago

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

0
None
MusayevZ

2 years ago

What to do to turn on 4 leds?

0
None
LizzyL9

2 years ago

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

2 replies
0
None
Arafe ZawadSLizzyL9

Reply 2 years ago

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);

0
None
Arafe ZawadSLizzyL9

Reply 2 years ago

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

0
None
Jazza my top lad

2 years ago

KFC is yummy
Kuam is yummy
Kuam is KFC

*dab

0
None
Jazza my top lad

2 years ago

KFC is yummy
Kuam is Yummy
Kuam is KFC

*dab

0
None
arduinocoder

2 years ago

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);
}

}

1 reply
0
None
iTECHKING

2 years ago

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.

0
None
amg66

3 years ago

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

0
None
maxyfun

5 years ago on Introduction

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?

1 reply