Release 2016.10.2 / Update 2017.12.27

Reproducing Knight Rider LED with Arduino.

“Knight Rider” is a drama which I was looking keen in old days. In this article, I am going to imitate illuminations of the lamp on “Knight 2000”, with arduino.

To make movement of the round trip on the LED



Connect Arduino pins to LED. Write a sketch to set the LED on and off in order. Basically, this is all you need. But, this way is too meaningless to be a article. So, I’m going to mention to efficient sketching.

Using ‘For’


Knight 2000 LED light flow lined, has repeatedly come repetitive motion that back and go to the end. So, you can do that with simple method by ‘HIGH’ and ‘LOW’ in ‘digitalWrite’.

This method is troublesome. The repetitive work is simplified by using ‘For’.

It will be simple by ‘array’ and ‘define’ pin number.

Now, you can repeat the work.

“LED_SIZE – 1” is needed for stopping repeat before motion reaches to the end.


And it will be more simple by combine each repeat once.

Ten times repeat is needed for total 6 LED motion. In short,

Repeat times = ( LED_SIZE-1 ) * 2

“Starting from zero” makes me confused always. Anyway, it will be a circulation following.


And if you get to the halfway point, count value need to be ‘decreased’. So I make new argument ‘count’ for that task.

You can separate ‘decrease’ task from ‘increase’ using ‘if’ like this.

By the way, syntax of ‘if’ is omissible.

=(Judgment formula)? value ‘TRUE’ : value ‘FALSE’;

Watch out for colon in the middle, not semicolon. It makes the sketch more simple.

Sketch:motion of LED

summary, so far.

It is more simple to define total repeat time as “LOOP_SIZE”.

Variable speed

Sketch of LED motion finished. But probably you say it slow. You can change speed by value of delay, of course.

Well, why don’t you make it variable speed?



Simply connect a variable resistance to A0.

Reading a variable resistance.

Description of the analog input here will be omitted. For more information is here.

So, I will make a function of returning reasonable number of seconds (20 ms~200ms) by reading of the variable resistor.

Sketch:Variable speed by a variable resistance

And set the function to the argument.


Not enough? Yes, there are no afterimages on motion. We have to reproduce the afterimages.

Sketch:LED motion with the afterimages.

There is no difficult to make afterimages if you use ‘analogWrite’.

Here is a trick. It becomes simple by making array of luma value for each LED. Keeping divide anyway goes to 0 in the end. And give it max value just to leads one. You can change times of afterimage by divide number.


Surveillance mode

In the drama, LED can be stopped by surveillance mode button. So, let it make.



Check here, if you want to know about “switch function without chattering”.

To memorize on or off, make ‘surveillance_mode’ variable. And modify function ‘VOL_READ’ as ‘EXT_CONTROL’, which contains switch reading.

Sketch:Knight Rider LED

This is so simple sketch, isn’t it?

In the end

There are only six pins for PWM on Arduino UNO. So this article is modeled after the spec. But you can control more PWM pins in some other machines. Like ‘Arduino DUE’, ‘Arduino MEGA’ and ‘M0’.

In that case, you can easily expand the function. All you need is change to two arguments. For example, if you want to use 8 pin on ‘Arduino DUE’,

Max current is 20mA on Arduino. But using transistors lets you use huge LED.

I hope you will try and enjoy it.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.