Header Ads

How to make Led sequencer use Arduino

In this Arduino tutorial we will learn how to make a Led sequencer. Here we are used 8 Leds for sequentially Leds On and Off.
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 are used 100 R resistor for limit the Led 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(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  pinMode(led5,OUTPUT);
  pinMode(led6,OUTPUT);
  pinMode(led7,OUTPUT);
  pinMode(led8,OUTPUT);

}

void loop() {
  for(i=1;i<8;i++){
      digitalWrite(i,HIGH);    // Led is active
      delay(100);
      digitalWrite(i,LOW);    // Led is deactive
      }
    for(i=8;i>0;i--){
      digitalWrite(i,HIGH);    // Led is active
      delay(100);
      digitalWrite(i,LOW);    // Led is deactive
      }
  }

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


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

In the loop section we have to create two for loop for Leds are sequentially Blinking. In the first loop we have to  set the character variable value is 1 and we create a condition for check the valued value. Here we are used increment operator ++ for increase the value of i. We have to write digitalWrite() function for HIGH and LOW state for Arduino pins. Here we are used character variable i which means the Arduino pin number. If the value of the i is 8 that indicate the selected pin is 8. In this case i value is 1 the pin 1 or Led1 is active.
we have to create  delay function for 100 millisecond HIGH state  of the Led. The value of i is incremented when loop is  continue and check the condition. When the  condition is false then exit the loop.
   
The next for loop works same as the first for loop. The different of these loop are condition.


Source file:



No comments

Theme images by 5ugarless. Powered by Blogger.