Arduino Project Knight Rider
Arduino Project Knight Rider
In this tutorial, eight LED's are interfaced to the Arduino Uno board.
A program is then loaded to the Arduino that will turn the eight LEDs into a "Knight rider" display.
Components
Besides a breadboard, Arduino Uno and USB cable, you will need:
8 pcs 470 ohm resistor (yellow - violet - brown)
8 pcs 5mm red LED
9 Wire links
Circuit Diagram
The circuit diagram is shown below. It is simply eight LEDs interfaced to the Arduino pins 2 to 9.
Building the Circuit
Place the LEDs next to each other in the breadboard so that the anode (longer lead) is at the left and the cathode is on the right.
Insert the 470 ohm resistors connecting one lead to the LED's cathode and the other to the top rail.
Join the anodes of the LEDs to pins 2 to 9 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.
Loading the Program
The Knight Rider program listing is shown below. Copy it and pasted it into the Arduino IDE.
/*
Knight Rider
Knight rider display on 8 LEDs
*/
void setup() {
// set up pins 2 to 9 as outputs
for (int i = 2; i < 10; i++) {
pinMode(i, OUTPUT);
}
}
// function to switch all LEDs off
void allLEDsOff(void)
{
for (int i = 2; i < 10; i++) {
digitalWrite(i, LOW);
}
}
void loop() {
// move on LED to the right
for (int i = 2; i < 9; i++) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
// move on LED to the left
for (int i = 9; i > 2; i--) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
}
The following video shows what you will achieve:
In this tutorial, eight LED's are interfaced to the Arduino Uno board.
A program is then loaded to the Arduino that will turn the eight LEDs into a "Knight rider" display.
Components
Besides a breadboard, Arduino Uno and USB cable, you will need:
8 pcs 470 ohm resistor (yellow - violet - brown)
8 pcs 5mm red LED
9 Wire links
Circuit Diagram
The circuit diagram is shown below. It is simply eight LEDs interfaced to the Arduino pins 2 to 9.
Building the Circuit
Place the LEDs next to each other in the breadboard so that the anode (longer lead) is at the left and the cathode is on the right.
Insert the 470 ohm resistors connecting one lead to the LED's cathode and the other to the top rail.
Join the anodes of the LEDs to pins 2 to 9 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.
Loading the Program
The Knight Rider program listing is shown below. Copy it and pasted it into the Arduino IDE.
/*
Knight Rider
Knight rider display on 8 LEDs
*/
void setup() {
// set up pins 2 to 9 as outputs
for (int i = 2; i < 10; i++) {
pinMode(i, OUTPUT);
}
}
// function to switch all LEDs off
void allLEDsOff(void)
{
for (int i = 2; i < 10; i++) {
digitalWrite(i, LOW);
}
}
void loop() {
// move on LED to the right
for (int i = 2; i < 9; i++) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
// move on LED to the left
for (int i = 9; i > 2; i--) {
allLEDsOff();
digitalWrite(i, HIGH);
delay(200);
}
}
Load the program to the Arduino and if the circuit was built correctly, your knight rider circuit will start operating.
The following video shows what you will achieve: