Blink Row of LED’s | The Complete guide to IoT

In this article we will learn how to blink or control a row of LED’s as we have done in our previous practical article to blink only a single LED, So now we are going to extend that to row of LED’s. And also you will get to do some experiment to blink the row of LED’s .

So hey Guys how are you? Doing Good? Are you learning daily? If not bookmark this blog I post everyday!
Controlling a row of LED’s is very much similar to the way we controlled a single LED. So the logic will be, the code that we wrote for controlling a led in pin 13 or pin 10 that same part will be copied for the number of LED’s you plan to use the only thing we have to do is to use the different pin number in which each of the LED will be connected. Don’t worry we will go step by step.
Arduino row led blinking

Step 1: Things That You Will Need ??
thing you will need blinking row of led
Step 2: The Circuit Diagram

circuit diagram to blink led using arduino

Step 3: The Code
// the setup function runs once when you press reset or power the board
void setup() {

// initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

// initialize digital pin 12 as an output.
  pinMode(12, OUTPUT);

// initialize digital pin 11 as an output.
  pinMode(11, OUTPUT);

// initialize digital pin 10 as an output.
  pinMode(10, OUTPUT);

// initialize digital pin 9 as an output.
  pinMode(9, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn LED 13 on 
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn LED 13 off 
  delay(1000);              // wait for a second

  digitalWrite(12, HIGH);   // turn LED 12 on 
  delay(1000);              // wait for a second
  digitalWrite(12, LOW);    // turn LED 12 off 
  delay(1000);              // wait for a second

  digitalWrite(11, HIGH);   // turn LED 11 on 
  delay(1000);              // wait for a second
  digitalWrite(11, LOW);    // turn LED 11 off 
  delay(1000);              // wait for a second

  digitalWrite(10, HIGH);   // turn LED 10 on 
  delay(1000);              // wait for a second
  digitalWrite(10, LOW);    // turn LED 10 off 
  delay(1000);              // wait for a second

  digitalWrite(9, HIGH);   // turn LED 9 on 
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // turn LED 9 off 
  delay(1000);              // wait for a second
}
Copy the above code and paste it in your Arduino IDE new sketch. It will be better if you understand and write by yourself.
Step 4: The Explanation
Code Snippet:
void setup() {

// initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

// initialize digital pin 12 as an output.
  pinMode(12, OUTPUT);

// initialize digital pin 11 as an output.
  pinMode(11, OUTPUT);

// initialize digital pin 10 as an output.
  pinMode(10, OUTPUT);

// initialize digital pin 9 as an output.
  pinMode(9, OUTPUT);
}
We already have done the blinking of a led in pin 13 so here what we are doing is that in setup part we are declaring 5 pins viz. pin 13, pin 12, pin 11, pin 10, pin 9 as output. This is so simple there must not be any confusion if it there ask in comments below.
Code Snippet:
void loop() {
  digitalWrite(13, HIGH);   // turn LED 13 on 
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn LED 13 off 
  delay(1000);              // wait for a second

  digitalWrite(12, HIGH);   // turn LED 12 on 
  delay(1000);              // wait for a second
  digitalWrite(12, LOW);    // turn LED 12 off 
  delay(1000);              // wait for a second

  digitalWrite(11, HIGH);   // turn LED 11 on 
  delay(1000);              // wait for a second
  digitalWrite(11, LOW);    // turn LED 11 off 
  delay(1000);              // wait for a second

  digitalWrite(10, HIGH);   // turn LED 10 on 
  delay(1000);              // wait for a second
  digitalWrite(10, LOW);    // turn LED 10 off 
  delay(1000);              // wait for a second

  digitalWrite(9, HIGH);   // turn LED 9 on 
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // turn LED 9 off 
  delay(1000);              // wait for a second
}
Earlier in previous example we only {turn on the led attached to pin 13 then wait for 1 sec then turn off then wait for 1 sec} and this process goes on. Which was simple to implement.
But now we are { (turning on led 13, wait 1 sec, turn off, wait 1 sec) then (turning on led 12, wait 1 sec, turn off, wait 1 sec) then(turning on led 11, wait 1 sec, turn off, wait 1 sec) then(turning on led 10, wait 1 sec, turn off, wait 1 sec) then(turning on led 9, wait 1 sec, turn off, wait 1 sec) } then repeat this again and again….
Concluding we are doing here is that blink led 13 then 12 then 11 then 10 then 9 and repeat this again and again.
Step 5: Upload the Code to Arduino
Connect your Arduino Uno to your Laptop, Now in the Arduino IDE go to Tools > Board > Select Arduino Uno
Select Board circuit and code

And after you have connected your Arduino Uno, the Port option will be active select the required COM port showing the Arduino board.

Select Port circuit and code


Now hit that upload button to compile the code and the upload to your board.

Arduino code compile and upload

If the code is correct you will get no error and your code will upload to the board and you will see a message of successful upload in the message area.
1.
Arduino code compiling

2.
Arduino code uploading

3.
Arduino code done uploading

On Successful Uploading of code your Arduino RX TX led will blink like this (only 2 time). It means you have successfully uploaded the code.


arduino code uploaded


Now you will see something like this. Congratulation you DID It! after connecting the LED's as shown in the circuit diagram here is what it looks like.
Arduino row led blinking

Let’s experiment
Now experiment and learn by yourself , here is some task I am giving you if you are able to do it. That means your are going good. If not you need to practice more. Need help contact me, I am there to help you out.
1st TASK: Decrease the delay between the blink.
2nd TASK: Turn on all LED’s together wait for 1 sec Turn off all LED’s together wait 1 sec then repeat
3rd TASK: { Blink forward i.e(Blink 13 then 12 then 11 then 10 then 9 th LED) then backward i.e (blink 9 then 10 then 11 then 12 then 13)} and repeat this process.
So today in this article we coded our second Arduino project, uploaded it and tested also did some experiment. In our upcoming articles you will be controlling the brightness of the LED, keep visiting
How did you like this post. Was it informative, Did you understood all the points, What problem you faced during reading this article. Do you have any doubts or any query…
Comment Down each and everything I am eager to hear from you.

In the next article you will be will be controlling the brightness of the LED. Till then KEEP LEARNING

Post a Comment

0 Comments