Arduino 20 LED Knight Rider using arduino mega

Arduino Knight Rider LED effects project consist of 20 LEDs and Arduino mega, refer circuit diagram for LED connections to Arduino. This example makes use of 20 LEDs connected to the pins 22 – 41 on the board using 40 Ohm resistors and LED driver IC ULN2003. The code example will make the LEDs blink in a sequence, one by one using only digitalWrite(pinNum, HIGH/LOW) and delay(time).

Hardware Requirement

  • Arduino Mega
  • ULN2003 X 3 IC
  • 470 Ohms X 20 Resistors
  • Blue LED X 20 ( SMD 0805 LED)

Download Arduino Code



Video of the Project



Arduino Code


/*
Arduino 20 LEDs Knight Rider
Hardware 20 LED board, Arduino Mega 2560
Circuit diagram, PCB layout and code of the project is
available from our website www.twovolt.com

*/
//
int ledPin1 = 22;
int ledPin2 = 23;
int ledPin3 = 24;
int ledPin4 = 25;
int ledPin5 = 26;
int ledPin6 = 27;
int ledPin7 = 28;
int ledPin8 = 29;
int ledPin9 = 30;
int ledPin10 = 31;
int ledPin11 = 32;
int ledPin12 = 33;
int ledPin13 = 34;
int ledPin14 = 35;
int ledPin15 = 36;
int ledPin16 = 37;
int ledPin17 = 38;
int ledPin18 = 39;
int ledPin19 = 40;
int ledPin20 = 41;

const int delayTime = 25;
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);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
pinMode(ledPin13, OUTPUT);
pinMode(ledPin14, OUTPUT);
pinMode(ledPin15, OUTPUT);
pinMode(ledPin16, OUTPUT);
pinMode(ledPin17, OUTPUT);
pinMode(ledPin18, OUTPUT);
pinMode(ledPin19, OUTPUT);
pinMode(ledPin20, 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

digitalWrite(ledPin9,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin9,LOW); // LED OFF

digitalWrite(ledPin10,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin10,LOW); // LED OFF

digitalWrite(ledPin11,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin11,LOW); // LED OFF

digitalWrite(ledPin12,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin12,LOW); // LED OFF

digitalWrite(ledPin13,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin13,LOW); // LED OFF

digitalWrite(ledPin14,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin14,LOW); // LED OFF

digitalWrite(ledPin15,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin15,LOW); // LED OFF

digitalWrite(ledPin16,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin16,LOW); // LED OFF

digitalWrite(ledPin17,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin17,LOW); // LED OFF

digitalWrite(ledPin18,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin18,LOW); // LED OFF

digitalWrite(ledPin19,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin19,LOW); // LED OFF

digitalWrite(ledPin20,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin20,LOW); // LED OFF

//turn

digitalWrite(ledPin20,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin20,LOW); // LED OFF

digitalWrite(ledPin19,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin19,LOW); // LED OFF

digitalWrite(ledPin18,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin18,LOW); // LED OFF

digitalWrite(ledPin17,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin17,LOW); // LED OFF

digitalWrite(ledPin16,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin16,LOW); // LED OFF

digitalWrite(ledPin15,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin15,LOW); // LED OFF

digitalWrite(ledPin14,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin14,LOW); // LED OFF

digitalWrite(ledPin13,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin13,LOW); // LED OFF

digitalWrite(ledPin12,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin12,LOW); // LED OFF

digitalWrite(ledPin11,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin11,LOW); // LED OFF

digitalWrite(ledPin10,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin10,LOW); // LED OFF

digitalWrite(ledPin9,HIGH); // LED ON
delay(delayTime);
digitalWrite(ledPin9,LOW); // LED OFF

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

}

Leave a Reply

Your email address will not be published.