Arduino Knight Rider

by Rezz on October 4, 2011

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);
}

Basically this arduino projects same as blink project, turn on the LED sequentially from LED 12 to LED 8 and return the order back to LED 12. The knight rider light coded is plain code of blink to make it easier to understand. This code can be simplify using array code. Have fun!

Leave a Comment

Previous post:

Next post: