Tuesday, March 3, 2020

Knight Rider LED pattern with Arduino Uno

Knight Rider

  The Knight Rider is one of the perfect Arduino projects for beginners. What is Knight Rider? It’s a set of LEDs that blinks one after another.


Components

  1. 5mm LEDs
  2. Arduino UNO
  3. Breadboard
  4. Jumper wires

Apps 

  1. Arduino IDE

Building the circuit 

  1. Place the LEDs next to each other in the breadboard so that the anode(+) is at the left and the cathode(-) is on the right.
  2. Join the anodes of the LEDs to pins 2 to 10 of the Arduino from left to right using single-core wire. Join the top rail to one of the GND pins of the Arduino.
  3. When finished building the circuit, connect the Arduino to the PC via the USB cable.

  4. The Knight Rider program code is shown below. Copy it and paste it into the Arduino IDE.
------------------------------------------------------------------------------------------------------------------------------
//copy this and paste it into the IDE


void setup(){
  for (int pin=1; pin<11; pin++){
    pinMode(pin, OUTPUT);
    }
  }

  void loop(){
//you can change the value of int t to change the blinking speed
    int t = 20;

    for(int i=1; i<11; i++){
      digitalWrite(i, HIGH);
      delay(t);
      digitalWrite(i+1, HIGH);
      delay(t);
      digitalWrite(i+2, HIGH);
      delay(t);
      digitalWrite(i, LOW);
      delay(t);
      digitalWrite(i+1, LOW);
      delay(t);
      }

      for(int i =10; i>1; i--){
        digitalWrite(i, HIGH);
      delay(t);
      digitalWrite(i-1, HIGH);
      delay(t);
      digitalWrite(i-2, HIGH);
      delay(t);
      digitalWrite(i, LOW);
      delay(t);
      digitalWrite(i-1, LOW);
      delay(t);
        }
    
    }

------------------------------------------------------------------------------------------------------------------------------
Upload the program to the Arduino and if the circuit was built correctly, your knight rider circuit will start operating.

check here for full video - https://youtu.be/TM5-WAe5WHo
Thank you.........

No comments:

Post a Comment