Arduino Knight Rider Code

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

 

Arduino Knight Rider

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

Arduino Knight Rider Schematic

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!

 

Source: Arduino Knight Rider Code


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top