Arduino Knight Rider light effect, a simple variation of blink code.
Parts List;
1) 5x 5mm red LED
2) 1x Arduino
3) 5x 330Ω resistor
4) Jumper wire
Instruction;
1) Connect all LED as diagram below, make sure cathode lead of LED at ground wire.
2) Connect all 330Ω resistor to anode lead of LED.
3) Connect all jumper wire to digital pin 12, 11, 10, 9 and 8.
Upload this code to your arduino
/* Knight Rider Create LED chasing effect as knight rider light. Coded by: arduinoprojects101.com */ void setup() { // initialize the digital pin 12, 11, 10, 9, 8 as an output. pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); } void loop() { digitalWrite(12, HIGH); delay(80); digitalWrite(12, LOW); digitalWrite(11, HIGH); delay(80); digitalWrite(11, LOW); digitalWrite(10, HIGH); delay(80); digitalWrite(10, LOW); digitalWrite(9, HIGH); delay(80); digitalWrite(9, LOW); digitalWrite(8, HIGH); delay(80); digitalWrite(8, LOW); // reverse digitalWrite(8, HIGH); delay(80); digitalWrite(8, LOW); digitalWrite(9, HIGH); delay(80); digitalWrite(9, LOW); digitalWrite(10, HIGH); delay(80); digitalWrite(10, LOW); digitalWrite(11, HIGH); delay(80); digitalWrite(11, LOW); digitalWrite(12, HIGH); delay(80); digitalWrite(12, LOW); }
Essentially, this arduino project is similar to the blink project, as it turns on the LED lights in sequence from LED 12 to LED 8, before returning the sequence back to LED 12. The knight rider light code is simply a coded sequence of blinking for easier comprehension. This code can be made simpler using array code. Enjoy yourself!
Source: Arduino Knight Rider Code