Exercise 3 - Knight Rider LED

STEMTera™ Breadboard - Kinght Rider LED

The Knight Rider LED is inspired by the advanced artificial intelligent self-aware car from the 80’s Knight Rider TV series. The car was a customized 1982 Pontiac Trans-Am easily identified by its light scanning from left to right. This exercise is to simulate the scanner light using LEDs.

Schematic Title
STEMTera™ Breadboard - Exercise 3 - Arduino Knight Rider LED Schematic Diagram
Part Title
RES_220Rx5
LED_REDx5
JUMPER_WIREx5
  1. Connect a JUMPER WIRE to GND and 31J.
  2. Connect a JUMPER WIRE to 31G and 33G.
  3. Connect a JUMPER WIRE to 33H and 35H.
  4. Connect a JUMPER WIRE to 35G and 37G.
  5. Connect a JUMPER WIRE to 37H and 39H.
  6. Connect a 220Ω RESISTOR to PIN2 and 40J.
  7. Connect a 220Ω RESISTOR to PIN3 and 38J.
  8. Connect a 220Ω RESISTOR to PIN4 and 36J.
  9. Connect a 220Ω RESISTOR to PIN5 and 34J.
  10. Connect a 220Ω RESISTOR to PIN6 and 32J.
  11. Connect the anode (longer) pin of a RED LED to 40F and cathode (shorter) pin to 39F.
  12. Connect the anode (longer) pin of a RED LED to 38F and cathode (shorter) pin to 37F.
  13. Connect the anode (longer) pin of a RED LED to 36F and cathode (shorter) pin to 35F.
  14. Connect the anode (longer) pin of a RED LED to 34F and cathode (shorter) pin to 33F.
  15. Connect the anode (longer) pin of a RED LED to 32F and cathode (shorter) pin to 31F.
Breadboard Title
STEMTera™ Breadboard - Exercise 3 - Arduino Knight Rider LED Inkscape Breadboard Diagram

Write and Upload the Knight Rider Sketch

In order to execute the sketch for this exercise, launch Arduino IDE then

Click File -> New.

A new sketch editing window will appear. Copy the whole block of code below and paste it into the new sketch window, overwriting the empty setup() and loop() that was pre-created. Ensure that the board selected is Arduino Uno and the right COM port is chosen according to “Board Selection” chapter.

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int timer = 100;

void setup(){
    // Configure PIN2 - PIN 6 as OUTPUT
    pinMode(pin2, OUTPUT);
    pinMode(pin3, OUTPUT);
    pinMode(pin4, OUTPUT);
    pinMode(pin5, OUTPUT);
    pinMode(pin6, OUTPUT);
}

void loop() {
    digitalWrite(pin2, HIGH);   // Turn ON LED on PIN2
    delay(timer);               // delay
    digitalWrite(pin2, LOW);    // Turn OFF LED on PIN2
    delay(timer);

    digitalWrite(pin3, HIGH);
    delay(timer);
    digitalWrite(pin3, LOW);
    delay(timer);

    digitalWrite(pin4, HIGH);
    delay(timer);
    digitalWrite(pin4, LOW);
    delay(timer);

    digitalWrite(pin5, HIGH);
    delay(timer);
    digitalWrite(pin5, LOW);
    delay(timer);

    digitalWrite(pin6, HIGH);
    delay(timer);
    digitalWrite(pin6, LOW);
    delay(timer);

    digitalWrite(pin5, HIGH);
    delay(timer);
    digitalWrite(pin5, LOW);
    delay(timer);

    digitalWrite(pin4, HIGH);
    delay(timer);
    digitalWrite(pin4, LOW);
    delay(timer);

    digitalWrite(pin3, HIGH);
    delay(timer);
    digitalWrite(pin3, LOW);
    delay(timer);
}

Click arduino_ide_upload button Upload, and the Arduino IDE will prompt you to Save sketch folder as. Enter Excercise_3 into the filename field and click save. Once saved, the Arduino IDE will start to compile the sketch. After the compilation is completed, the Arduino IDE will start to upload the compiled sketch into the STEMTera™ Breadboard. During this stage both yellow LEDs on the STEMTera™ Breadboard will start blinking indicating the Arduino IDE is uploading the sketch to the STEMTera™ Breadboard.

Understanding the Knight Rider Sketch

The sketch start by making PIN2 to PIN6 as OUTPUT so that they can drive the LED ON or OFF. The concept of Knight Rider LED is to turn ON and OFF each LED in sequence from right to left. PIN2 ON, delay, PIN2 OFF then PIN3 ON, delay, PIN3 OFF,…..PIN6 ON, delay, PIN6 OFF. As soon as the last LED on PIN6 is turned OFF, the ON and OFF sequence is preformed in a reverse sequence from PIN6 to PIN2.

When the right to left and left to right sequence is performed in a loop, the LEDs will look like the Knight Rider’s scanner light.