Arduino Knight Rider Reboot – ElectroSchematics.com

Good News! The 80s classic action series Knight Rider is being made into a feature film. The film will be directed by James Wan. Former video game writer TJ Fixman will write the film (https://deadline.com/2020/08/knight-rider-feature-spyglass-media-james-wan-tj-fixman-scripting-1203006206/).

Knight Rider is an American action crime drama television series originally broadcast on NBC from 1982 to 1986 (https://en.wikipedia.org/wiki/Knight_Rider). The show created and produced by Glen A. Larson stars David Hasselhoff (https://en.wikipedia.org/wiki/David_Hasselhoff) as Michael Knight, a high-tech, modern crime fighter assisted by KITT (https://en. wikipedia.org/wiki/KITT), an advanced, artificially intelligent, self-aware, and nearly indestructible car.

My first (mid-80’s) Knight Rider project (based on transistors) was printed in an Australian electronics magazine. Unfortunately, I do not have a copy of that article right now. I thought it would be interesting to make an improved reproduction of the project. In this post I will show you how to render Knight Rider patterns with a handful of LEDs and an Arduino microcontroller. You probably noticed there are a vast number of Knight Rider projects on internet. Honestly, my design ideas also follow those concepts closely but in a distinct manner. Let us get to work. Following is a simple code that does the magic of turning an Arduino microcontroller into a fabulous Knight Rider.

[code]

const int lamps[] = {2,3,4,5,6,7,8,9};

const int maxLamps = 8;

void setup() { 

    for(int i = 0; i <= maxLamps; ++i) {

        pinMode(lamps[i], OUTPUT);
    }
}

void loop() {
    for(int i = 0; i < maxLamps - 1; ++i) {

     delay(analogRead(0)/4);

        digitalWrite(lamps[i], HIGH);

      delay(analogRead(0)/4);

        digitalWrite(lamps[i + 1], HIGH);

       delay(analogRead(0)/4);

        digitalWrite(lamps[i], LOW);

    }

    for(int i = maxLamps; i > 0; --i) {

     delay(analogRead(0)/4);

        digitalWrite(lamps[i], HIGH);

 delay(analogRead(0)/4);

        digitalWrite(lamps[i - 1], HIGH);

        delay(analogRead(0)/4);

        digitalWrite(lamps[i], LOW);

    }

}
[/code]

Like you, I know that employing a powerful microcontroller brain like the ATmega328P (https://components101.com/sites/default/files/component_datasheet/ATMega328P%20Datasheet.pdf) to run a couple of common LEDs is certainly overkill. A small microcontroller in the Attiny series (2313 or 85) can do the job well. But my pick is intentional, as later we can modify/upgrade the basic design with more mesmeric components like NeoPixel LEDs, EL wires, Dot Matrix displays, etc. So, stay a bit longer–the ideas are still fresh.

Back to my Knight Rider code above, it’s a little piece of code tailored to control a total of 8 standard 5mm LEDs (red) through the Arduino Uno microcontroller (http://cactus.io/platform/arduino/arduino-uno). There’s also a 10K trimpot to change the transition speed (scanning interval). The entire assembly can be powered by one 6F22 9V Li-ion battery pack or the like (500mA @ 9VDC recommended).

The first thing to look is to the value of the LED current limiter resistor. According to datasheets, the absolute maximum source current per I/O of Arduino Uno is 40mA, and 20mA is the good design value. A textbook red LED has a forward voltage (Vf) of 1.8V and a forward current (If) of 25mA. Since the Arduino I/O has an output voltage close to 5V, value of the current limiter series resistor is 5V-1.8V/25mA = 128Ω. Although the closest and easiest to find standard resistance value is 150Ω, I chose 220Ω/ ¼ W resistor to trim the current to be slightly under 15mA. The leeway is permissible in this little hobby project.

The basic hardware wiring diagram:

There are a few improvements that can be made to this basic hardware setup. One is to include a power LED driver circuit to handle husky LEDs or LED strings/strips. And of course, you’ll need to build an 8-channel LED driver circuit. Look at the single-channel (1/8) LED driver circuit provided below.

As I discussed in previous posts, the thing that makes the driver hardware setup neat is the logic-level power MOSFET. Originally, it’s accomplished with a IRLZ44 N-channel logic-level power MOSFET, but you can try similar logic-level MOSFETs, the IRL540 for example. Remember you have to gather a total of 8 pieces to complete the project.

Below you can see another (downgraded) version of the Knight Rider code but suitable for the same hardware setup. This time the trimpot feature is omitted, and I’ve simplified the code and thus the resultant scanning pattern (comparatively not beauteous but worthful).

[code]

const int lampCount = 8;
int lampPins[] = { 2, 3, 4, 5, 6, 7, 8, 9 };

void setup() {

  for (int i = 0; i < lampCount; i++) {

    pinMode(lampPins[i], OUTPUT);

  }

}

void loop() {

  for (int i = 0; i < lampCount; i++) {

    lampDisplay(i);

  }

}

void lampDisplay(int lampOn) {

  for (int i = 0; i < lampCount; i++) {

    if (i == lampOn)

      digitalWrite(lampPins[i], HIGH);

    else

      digitalWrite(lampPins[i], LOW);

  }

  delay(100);

}

[/code]

An agile code breakdown for tyros:

  • const int lampCount – the number of LEDs in the LED row
  • int lampPins[] – an array of pin numbers to which LEDs are attached
  • setup() – loop over the pin array and set them all to output pins
  • loop() – the ith LED of the LED row will light up in turn
  • void lampDisplay – make the “lampOn”th LED of the LED row ON and the others OFF

  • The “const” keyword is used to define read-only variables
  • The array “int lampPins” is used to record a set of variables, where “int” is the type of the array and “8” is an element of the array, ie here the array stores 8 int types of elements
  • The operator “i++” is equivalent to “i=i+1” (And “i–” equivalent to “i=i-1”)

Note: You can modify the code inside the function() loop to make the LEDs run in forward and then in reverse order cyclically.

void loop() {

  for (int i = 0; i < lampCount; i++) {

    lampDisplay(i);

  }

  for (int i = lampCount; i > 0; i--) {

    lampDisplay(i - 1);

}

}

This is a random shot of my Arduino Knight Rider prototype. I used a 10-LED Bar graph module as the display unit, and 8 LEDS out of the 10 was wired to conduct my quick test. Compact, right?

I am happy with the outcomes – both code versions work great and are adaptable. Once you get deep into this it is not hard to play with unique Knight Rider ideas. However, if you are a beginner you might have to dig deeper to understand why a circuit or code is a certain way.

One minor drawback to note: Some Knight Riders features a multi-mode button to alter the scanning pattern, these simple codes do not. Perhaps a theme for a future post (maybe that would be a good exercise for you as well).

Finally, I do enjoy sharing these things with you. I hope they are informative and helpful!

Leave a Comment