Arduino – LED2


 

 


What we do
What we need
How we do (Hardware)
How we do (Software)
Still shots Outcome
What we do

From the previous post (Arduino - LED1), we can easily extend or modify our Blink LED example for further learning. 🙂

However, we should need breadboard for playing with multiple LEDs in this post.

How we do (Hardware)

Please note that I'm not using breadboard when we play with two of LEDs, but you can choose to use it or not.

(I wanted to show you how hard the wiring is without breadboard)

 

In case of using three LEDs, we should definitely use breadboard, otherwise that can be quite messy and hard to wire all of them. 🙂

 

  • Blink Two LEDs with different delay time (blue and red LED together)

  • Blink Three LEDs without delay time

How we do (Software)
  • Blink LED with more delay (more than 1 second)

Step 1) Define pin number. we can use different pin at this time.

 

int ledPin = 10;

 

Step 2) Configure 10 pin as an output.

 

void setup() 
{
pinMode(ledPin, OUTPUT);
}

 

Step 3) Turn ON/OFF LED with delays

 

void loop() 
{
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
delay(3000);
}

 

Step 4)

You can see LED Light On and then Off after 2 secs, and On again after 3 secs.


  • Blink Two LEDs with different delay time (blue and red LED together)

Step 1) Define pin number. we need to define 2 pins now.

 

int ledPin1 = 10;

int ledPin2 = 12;

 

Step 2) Configure 10 and 12 pin as an output.

 

void setup() 
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}

 

Step 3) Turn ON/OFF LED with delays

 

Now we can configure to turn ON/OFF two LEDs with different delay times.

  1. Turn On LED 1
  2. After 3 secs, turn On LED 2
  3. After 4 secs, turn Off LED 1
  4. After 5 secs, turn Off LED2
  5. this step replays after 6 secs

The above is my plan. you can design your own plan. 🙂

 

void loop() 
{
digitalWrite(ledPin1, HIGH);
delay(3000);
digitalWrite(ledPin2, HIGH);
delay(4000);
digitalWrite(ledPin1, LOW);
delay(5000);
digitalWrite(ledPin2, LOW);
delay(6000);
}

 

Step 4)

Please carefully watch your LEDs to check if they're acting like you want.


  • Blink Three LEDs without delay time

This time, we can try to do more funny one. without delay times!

 

Step 1) Define pin number. we need to define 3 pins now.

 

int ledPin1 = 10;

int ledPin2 = 11;

int ledPin3 = 12;

 

Step 2) Configure 10, 11 and 12 pin as an output.

 

void setup() 
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

 

Step 3) Turn ON/OFF LED without delays

 

Now we can configure to turn ON/OFF three LEDs without any delays.

  1. Turn On LED 1 / 2 / 3 subsequently
  2. Turn Off LED 1 / 2 / 3 subsequently
  3. this step replays after 5 secs

The above is my plan. you can design your own plan. 🙂

 

void loop() 
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
delay(5000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
delay(2000);
}

 

Step 4)

Please carefully watch your LEDs to check if they're acting like you want.

Still shots Outcome

Well done! 🙂

As you can see from the above examples, you can design and develop your own programs with your various good ideas. The more you think, the better program you have!

 

 

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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