Wednesday, September 7, 2022
Home Arduino Let's work with Arduino with LED Bar Graph Lesson 05

Let’s work with Arduino with LED Bar Graph Lesson 05

Good day Today, we will talk about how to work with LED BAR GRAPH.

  1. Arduino Uno board:www.daraz.lk
  2. A LED BAR GRAPH: https://www.duino.lk/LED-Bar-Graph-Display-10-Segment
  3. Jumper Wires: https://www.amazon.in/Jumper-Wires-Male-female-Pieces/dp/B00ZYFX6A2?th=1
  4. 10 Resistors 220 Ohm: EDGELEC 100pcs 220 ohm Resistor 1/2w (0.5Watt) ±1% Tolerance Metal Film Fixed Resistor, Multiple Values of Resistance Optional
LED BAR GRAPH https://shop.stemlabs.edu.lk/index.php/product/10-led-bar-graph/

LED BAR GRAPH is a single unit consisting of 10 LEDs. It has 20 PINs with 10 PINs on each side. Therefore, we use Arrays to implement this. Multiple values ​​can be stored in an array variable. Here we will store the PIN values ​​we need on the Arduino board.

This is how to make Arrays in Arduino.

First, we have to mention the relevant variable type and then the Array’s name. Then [] is noted next to that name.

int arrayName[];

string arrayName[];

When substituting values ​​into Array, the substitution is as follows.

int LedPin[] = {3,4,5,6,7,8,9,10,11,12}

Here we have used ​​the PINs connected to the Arduino UNO board.

Now let’s turn on this LED BAR GRAPH.

First, we need to set up all the relevant PINs. For that, we use a for loop in void setup() to set it up like this.

for (int i=0;i<10;i++)
{
   pinMode(LedPin[i], OUTPUT);
}

Here the initial value of int i is equal to 0 because the index value corresponding to the first value of an Array is 0. In the middle of the for loop i<10 it will execute until the value of i is less than 10 or else the number of PINs in our Array. Finally, i++ increases the value of variable i by 1 (i=i+1).

Inside pinMode(), we specify the relevant PIN and whether that PIN is INPUT or OUTPUT. Here we have given all the PINs using an Array, so we call it LedPin[i]. There, the value of i will be changed until the for loop is executed, and this pinMode will be obtained by specifying i inside the boxes. That way, all the PINs in the Array will become OUTPUT PIN.

Here, the value of I and the value coming out of that Array will change this way.

  1. LedPin[0]; = 3
  2. LedPin[1]; = 4
  3. LedPin[2]; = 5
  4. LedPin[3]; = 6
  5. LedPin[4]; = 7
  6. LedPin[5]; = 8
  7. LedPin[6]; = 9

Now let’s light this LED BAR GRAPH through the void loop. We use a for loop for that. This will light up all the ports or several related to all the values ​​in the Array we created above. We do it in the following way.

First, we turn on all the LEDs one at a time.

for (int i= 0;i<10; i++)
{
  digitalWrite(LedPin[i], HIGH);
  delay(1000);
}

Every PIN from the 3rd Port to the 12th Port on the Uno board lights up once per second.

Now let’s light each LED separately.

for (int i= 0;i<10; i++)
{
  digitalWrite(LedPin[i], HIGH);
  delay(1000);
  digitalWrite(LedPin[i], LOW);
}

Here we make the first PIN HIGH and turn it on. Again after a delay, it turns off. This is done by a for loop, so the value of i increases by one. The LED corresponding to the next PIN will light up again. After another delay, it turns off.

Code:

int LedPin[] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

void setup() {
  for (int i = 0; i < 10; i++) {
    pinMode(LedPin[i], OUTPUT);
  }
}

void loop() {
  for (int i = 0; i < 10; i++) {
    digitalWrite(LedPin[i], HIGH);
    delay(1000);
    digitalWrite(LedPin[i], LOW);
  }
}

So, guys, we say goodbye for today. I will come back with another article like this. Don’t forget to comment on your suggestions and shortcomings. Good day

RELATED ARTICLES

Leave a reply

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Kaushi ki on Arduino IDE Lesson 02
Osiru Domnic on Identify Arduino Component