[Project 4] – LED 8 භාවිතයෙන් Arduino Knight Rider

You are here:
Estimated reading time: 1 min

In this project we will make knight rider with 8 LED. I will use arduino uno in the circuit design program.I use usually arduino mega 2560.  You can use the other arduino cards. This project for beginners.

Schema:

Materials:

  1. Arduino UNO / Other Arduino Cards    x 1
  2. Breadboard      x 1
  3. 220 ohm resistor    x 8
  4. LED    x 8
  5. Jumper Cable

Program 1:

// [Project 4] - Arduino Knight Rider With 8 LED

int ledPin1 = 13; 
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
int ledPin7 = 7;
int ledPin8 = 6; 
const int delayTime = 50; 

 void setup () 
 
{
 pinMode(ledPin1, OUTPUT); 
 pinMode(ledPin2, OUTPUT); 
 pinMode(ledPin3, OUTPUT); 
 pinMode(ledPin4, OUTPUT); 
 pinMode(ledPin5, OUTPUT); 
 pinMode(ledPin6, OUTPUT); 
 pinMode(ledPin7, OUTPUT); 
 pinMode(ledPin8, OUTPUT);
} 


 void loop() { 
 
 
 digitalWrite(ledPin1,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin1,LOW); // LED OFF

 digitalWrite(ledPin2,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin2,LOW); // LED OFF
 
 digitalWrite(ledPin3,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin3,LOW); // LED OFF
 
 digitalWrite(ledPin4,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin4,LOW); // LED OFF
 
 digitalWrite(ledPin5,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin5,LOW); // LED OFF
 
 digitalWrite(ledPin6,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin6,LOW); // LED OFF
 
 digitalWrite(ledPin7,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin7,LOW); // LED OFF
 
 digitalWrite(ledPin8,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin8,LOW); // LED OFF
 
 //turn
 
 digitalWrite(ledPin8,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin8,LOW); // LED OFF

 digitalWrite(ledPin7,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin7,LOW); // LED OFF
 
 digitalWrite(ledPin6,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin6,LOW); // LED OFF
 
 digitalWrite(ledPin5,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin5,LOW); // LED OFF
 
 digitalWrite(ledPin4,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin4,LOW); // LED OFF
 
 digitalWrite(ledPin3,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin3,LOW); // LED OFF
 
 digitalWrite(ledPin2,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin2,LOW); // LED OFF
 
 digitalWrite(ledPin1,HIGH); // LED ON
 delay(delayTime); 
 digitalWrite(ledPin1,LOW); // LED OFF
 
}

Program 2:

int ledPin1 = 13; 
int ledPin2 = 12;
int ledPin3 = 11; 
int ledPin4 = 10;
int ledPin5 = 9; 
int ledPin6 = 8; 
int ledPin7 = 7; 
int ledPin8 = 6; 
const int delayTime = 50; 
int pinArray[] = {6, 7, 8, 9, 10, 11, 12, 13};
int count = 0;
void setup () 
{ 
 pinMode(ledPin1, OUTPUT); 
pinMode(ledPin2, OUTPUT); 
pinMode(ledPin3, OUTPUT); 
pinMode(ledPin4, OUTPUT); 
pinMode(ledPin5, OUTPUT); 
pinMode(ledPin6, OUTPUT); 
pinMode(ledPin7, OUTPUT); 
pinMode(ledPin8, OUTPUT); 
} 
void loop() { 
 for (count=0;count<8;count++) {
 digitalWrite(pinArray[count], HIGH);
 delay(delayTime);
 digitalWrite(pinArray[count], LOW);
 delay(delayTime);
 }
 for (count=7;count>=0;count--) {
 digitalWrite(pinArray[count], HIGH);
 delay(delayTime);
 digitalWrite(pinArray[count], LOW);
 delay(delayTime);
 }
}

Project Related Images:

 

Was this article helpful?
Dislike 0
Views: 1059

Leave a Reply

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