- Gather the materials you'll need:
- Arduino board
- 8 LEDs
- 8 220-ohm resistors
- Breadboard
- Jumper wires
Connect the LEDs to the Arduino board using the breadboard and jumper wires. Connect the positive (anode) leg of each LED to a digital output pin on the Arduino board, and connect the negative (cathode) leg of each LED to the breadboard's ground rail through a 220-ohm resistor.
Upload the following code to the Arduino board:
int pins[] = {2, 3, 4, 5, 6, 7, 8, 9};
int delayTime = 100;
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(pins[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < 8; i++) {
digitalWrite(pins[i], HIGH);
delay(delayTime);
digitalWrite(pins[i], LOW);
}
for (int i = 6; i > 0; i--) {
digitalWrite(pins[i], HIGH);
delay(delayTime);
digitalWrite(pins[i], LOW);
}
}
This code will control the LEDs to create the Knight Rider light effect, where the LEDs light up in sequence and then turn off in sequence.
- Once you've uploaded the code, your Knight Rider light should be ready to use! The speed of the sequence can be adjusted by changing the value of the
delayTime
variable in the code.