Header Ads

How to make a Led sequencer use Arduino part 3

In this Arduino tutorial we will learn how to make a Led sequencer and how it works. Here we are used 8 Leds for sequentially blink. This is the third part of the Led sequencer tutorial.  

You con watch the following video or read the written tutorial below.


                                             







The circuit diagram is very quick simple. The Leds are sequentially connected to pin 1, 2, 3, 4, 5, 6, 7 and 8.
Here we have connected eight LEDs with eight 100 ohm resistors . Which limit the Leds forward current.



Arduino Code:

int led1 =1 ;     // Led1 is connected to pin 1
int led2 =2 ;     // Led2 is connected to pin 2
int led3 =3 ;     // Led3 is connected to pin 3
int led4 =4 ;     // Led4 is connected to pin 4
int led5 =5;      // Led5 is connected to pin 5
int led6 =6 ;     // Led6 is connected to pin 6
int led7 =7 ;     // Led7 is connected to pin 7
int led8 = 8;     // Led8 is connected to pin 8

char i=0;
void setup() {
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);

}

void loop() {
      for(i=1;i<9;i++){
          digitalWrite(i,HIGH);    // Led is active
          delay(100);
           
      }

      for(i=8;i>0;i--){
          digitalWrite(i,LOW);    // Led is deactive
          delay(100);

      }
                  
  }

Code Explain:
This is our example code. First we have to define Leds pin connections. In this case the pin number 1 of Arduino board is connected to Led1, pin 2 is connected to Led2 and so one.
We have defined a character variable which mane is i.


In the setup we have to define the Led pin mode. In this case pin 1 , 2, 3, 4, 5, 6, 7 and 8 of the Arduino board is an output pin. 

In the loop section we have to create two for loop for Leds are periodically activate and deactivate. The first loop activates the LED periodically for 100 milliseconds. Here we have set the value of i variable to 1 and We have imposed a condition. We have increased the value of i one by one with each loop rotation. We will HIGH specific pins for 100 milliseconds.



Source file:


1 comment:

Theme images by 5ugarless. Powered by Blogger.