Have you ever wished you had your own Knight Industries Two Thousand (KITT) car — you know, from the Knight Rider? Take your dream one step closer to reality by creating an LED scanner! Here is the end result:

What you need
This project does not need many details, and there can be many:
- 1 x Arduino UNO or similar
- 1 x breadboard
- 8 x red LEDs
- 8 x 220 ohm resistors
- 1 x 10 kΩ potentiometer
- Man to man connect wires
If you have an Arduino starter kit you probably have all these parts (what can you do with a starter kit? )
Almost any Arduino will work as long as it has eight available pins (Never used an Arduino before? here). You can use shift register programming to drive the LEDs, although this is not required for this project as the Arduino has enough pins.
Construction plan
This is a very simple project. Although it may look complicated due to the large number of wires, every single part is very simple. Each LED is connected to its own Arduino pin. This means that each LED can be turned on and off individually. The potentiometer is connected to an analog Arduino at the pins that will be used to adjust the speed of the scanner.
Scheme
Connect the outer left pin (when viewed from the front, pins down) of the potentiometer to ground. Connect the opposite outer pin to +5v. If this doesn’t work properly, swap those pins. Connect the middle pin to the Arduino analog via 2.
Connect the anode (long leg) of each LED to digital pins one through eight. Connect the cathodes (short leg) to Arduino ground.
The code
Create a new sketch and save it as «knightRider». Here is the code:
const int leds[] = {1,2,3,4,5,6,7,8}; // Led pins const int totalLeds = 8; int time = 50; // Default speed void setup() { // Initialize all outputs for(int i = 0; i <= totalLeds; ++i) { pinMode(leds[i], OUTPUT); } } void loop() { for(int i = 0; i < totalLeds - 1; ++i) { // Scan left to right time = analogRead(2); digitalWrite(leds[i], HIGH); delay(time); digitalWrite(leds[i + 1], HIGH); delay(time); digitalWrite(leds[i], LOW); } for(int i = totalLeds; i > 0; --i) { // Scan right to left time = analogRead(2); digitalWrite(leds[i], HIGH); delay(time); digitalWrite(leds[i - 1], HIGH); delay(time); digitalWrite(leds[i], LOW); } }
Let’s deal with this. Each LED pin is stored in an array:
const int leds[] = {1,2,3,4,5,6,7,8};
An array is essentially a collection of related elements. These elements are defined as «const», which means that they cannot be changed later. You don’t need to use a constant (the code will work just fine if you remove «const»), although it’s recommended.
Array elements are accessed using square brackets («[]”) and an integer called the index. Indexes start at zero, so «leds [2]» would return the third element in the array — pin 3. Arrays make code faster and more readable, they make the computer do the hard work!