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
- 5mm LEDs
- Arduino UNO
- Breadboard
- Jumper wires
Apps
- Arduino IDE
Building the circuit
- 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.
- 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.
- When finished building the circuit, connect the Arduino to the PC via the USB cable.
- 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.
No comments:
Post a Comment