Beginner
LED Control
Analog Input
Arduino Mega / Uno
Knight Rider LED Chaser with Speed Control
Recreate KITT's iconic front scanner from the TV show Knight Rider — 8 LEDs bouncing back and forth with adjustable speed controlled by a potentiometer. Perfect for learning arrays, loops, and analog input.
KITT:
01 Components Required
Arduino Mega 2560
or Arduino Uno*
8 × LEDs
Red recommended
8 × Resistors
220Ω each
1 × Potentiometer
10kΩ
Breadboard
Full or half size
Jumper Wires
Male-to-male
Using Arduino Uno? Change pins 22–36 to available digital pins (e.g., 2–9) and update the array in the code accordingly.
02 Circuit Connection Guide
LED Connections (Arduino Mega)
| LED | Arduino Pin | Resistor | Other End |
|---|---|---|---|
| LED 1 | 22 | 220Ω in series | Cathode → GND |
| LED 2 | 24 | 220Ω in series | Cathode → GND |
| LED 3 | 26 | 220Ω in series | Cathode → GND |
| LED 4 | 28 | 220Ω in series | Cathode → GND |
| LED 5 | 30 | 220Ω in series | Cathode → GND |
| LED 6 | 32 | 220Ω in series | Cathode → GND |
| LED 7 | 34 | 220Ω in series | Cathode → GND |
| LED 8 | 36 | 220Ω in series | Cathode → GND |
Potentiometer Connections
| Potentiometer Pin | Connect To | Wire Color |
|---|---|---|
| Left Pin | 5V | Red |
| Middle (Wiper) | A0 | Yellow / Green |
| Right Pin | GND | Black |
03 Step-by-Step Build Instructions
1
Set up your breadboard
Place the breadboard on your workspace. Connect the Arduino Mega's 5V rail to the breadboard's positive (+) rail using a red wire, and GND to the negative (–) rail using a black wire.
2
Place the 8 LEDs
Insert 8 red LEDs across the breadboard with equal spacing. The longer leg (anode, +) goes into one row and the shorter leg (cathode, –) into the adjacent row. Keep all LEDs oriented the same way.
3
Add 220Ω resistors
Connect a 220Ω resistor between each LED's cathode row and the GND rail. This limits current and protects both the LEDs and the Arduino pins from damage.
4
Wire LEDs to Arduino pins
Connect each LED's anode row to the corresponding Arduino digital pin: LED1→22, LED2→24, LED3→26, LED4→28, LED5→30, LED6→32, LED7→34, LED8→36 using jumper wires.
5
Connect the potentiometer
Place the potentiometer on the breadboard. Connect its left pin to 5V, middle wiper to A0, and right pin to GND. This creates a voltage divider that Arduino reads as 0–1023.
6
Upload the code
Open Arduino IDE, paste the code from Section 05 below, select Board: Arduino Mega 2560 and the correct COM port, then click Upload. All 8 LEDs will flash once to confirm the connections are working.
7
Test and adjust speed
Watch the KITT scanning effect! Rotate the potentiometer to the left for maximum speed, or to the right to slow the animation down to a crawl (up to ~1 second per LED).
04 How the Code Works
LED Activation
The current LED turns ON, then position moves forward (+1) or backward (–1) based on the direction variable.
Boundary Detection
When position reaches LED 8 or LED 1, the direction multiplies by –1, reversing the scan automatically.
Speed Control
analogRead(A0) returns 0–1023. That value directly becomes the delay() duration in milliseconds — higher = slower.05 Arduino Code
Arduino C++
// ============================================
// Knight Rider LED Chaser with Speed Control
// MakeMindz.com | wokwi.com/projects/459456978983209985
// ============================================
// Array of LED pin numbers
int led[] = {22, 24, 26, 28, 30, 32, 34, 36};
// Total number of LEDs (auto-calculated)
int number_of_leds = sizeof(led) / sizeof(int);
// Current LED position in the array
int position = 0;
// Movement direction: 1 = forward, -1 = backward
int direction = 1;
// Potentiometer connected to analog pin A0
int potentiometer = A0;
// Stores the potentiometer reading (0–1023)
int potentiometer_value = 0;
void setup() {
// Set all LED pins as OUTPUT and run a startup test
for (int i = 0; i < number_of_leds; i++) {
pinMode(led[i], OUTPUT);
digitalWrite(led[i], HIGH); // All LEDs ON for 500ms
}
delay(500);
// Turn all LEDs OFF after the test
for (int i = 0; i < number_of_leds; i++) {
digitalWrite(led[i], LOW);
}
}
void loop() {
// Turn ON the LED at current position
digitalWrite(led[position], HIGH);
// Move position forward or backward
position += direction;
// Reverse direction at boundaries (first or last LED)
if (position == number_of_leds - 1 || position == 0) {
direction *= -1;
}
// Turn OFF the next LED (creates the chaser effect)
digitalWrite(led[position], LOW);
// Read potentiometer and use as delay (speed control)
potentiometer_value = analogRead(potentiometer);
delay(potentiometer_value); // 0ms = fastest, 1023ms = slowest
}
06 Wokwi diagram.json
Paste this into your Wokwi project's diagram.json file to instantly recreate the full circuit layout.
📄 diagram.json — Wokwi Circuit File
{
"version": 1,
"author": "MakeMindz",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-breadboard", "id": "bb1", "top": -156.6, "left": -198.8, "attrs": {} },
{ "type": "wokwi-arduino-mega", "id": "mega", "top": 58.2, "left": -541.2, "attrs": {} },
{ "type": "wokwi-led", "id": "led1", "top": -42, "left": -169, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led2", "top": -42, "left": -140.2, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led3", "top": -42, "left": -111.4, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led4", "top": -42, "left": -82.6, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led5", "top": -42, "left": -53.8, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led6", "top": -42, "left": -25, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led7", "top": -42, "left": 3.8, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led8", "top": -42, "left": 32.6, "attrs": { "color": "red" } },
{ "type": "wokwi-resistor", "id": "r1", "top": -72, "left": -173.35, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r2", "top": -72, "left": -144.55, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r3", "top": -72, "left": -115.75, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r4", "top": -72, "left": -86.95, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r5", "top": -72, "left": -58.15, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r6", "top": -72, "left": -29.35, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r7", "top": -72, "left": -0.55, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-resistor", "id": "r8", "top": -72, "left": 28.25, "rotate": 90, "attrs": { "value": "220" } },
{ "type": "wokwi-slide-potentiometer", "id": "pot1", "top": 283.4, "left": -308.2, "attrs": { "travelLength": "30" } }
],
"connections": [
[ "led1:C", "mega:22", "green", [ "v0" ] ],
[ "led2:C", "mega:24", "green", [ "v0" ] ],
[ "led3:C", "mega:26", "green", [ "v0" ] ],
[ "led4:C", "mega:28", "green", [ "v0" ] ],
[ "led5:C", "mega:30", "green", [ "v0" ] ],
[ "led6:C", "mega:32", "green", [ "v0" ] ],
[ "led7:C", "mega:34", "green", [ "v0" ] ],
[ "led8:C", "mega:36", "green", [ "v0" ] ],
[ "r1:1", "bb1:tp.2", "green", [ "h0" ] ],
[ "r2:1", "bb1:tp.5", "green", [ "h0" ] ],
[ "r3:1", "bb1:tp.7", "green", [ "h0" ] ],
[ "r4:1", "bb1:tp.10", "green", [ "h0" ] ],
[ "r5:1", "bb1:tp.12", "green", [ "h0" ] ],
[ "r6:1", "bb1:tp.15", "green", [ "h0" ] ],
[ "r7:1", "bb1:tp.17", "green", [ "h0" ] ],
[ "r8:1", "bb1:tp.20", "green", [ "h0" ] ],
[ "led1:A", "bb1:4b.j", "", [ "$bb" ] ],
[ "led1:C", "bb1:3b.j", "", [ "$bb" ] ],
[ "led2:A", "bb1:7b.j", "", [ "$bb" ] ],
[ "led2:C", "bb1:6b.j", "", [ "$bb" ] ],
[ "led3:A", "bb1:10b.j", "", [ "$bb" ] ],
[ "led3:C", "bb1:9b.j", "", [ "$bb" ] ],
[ "led4:A", "bb1:13b.j", "", [ "$bb" ] ],
[ "led4:C", "bb1:12b.j", "", [ "$bb" ] ],
[ "led5:A", "bb1:16b.j", "", [ "$bb" ] ],
[ "led5:C", "bb1:15b.j", "", [ "$bb" ] ],
[ "led6:A", "bb1:19b.j", "", [ "$bb" ] ],
[ "led6:C", "bb1:18b.j", "", [ "$bb" ] ],
[ "led7:A", "bb1:22b.j", "", [ "$bb" ] ],
[ "led7:C", "bb1:21b.j", "", [ "$bb" ] ],
[ "led8:A", "bb1:25b.j", "", [ "$bb" ] ],
[ "led8:C", "bb1:24b.j", "", [ "$bb" ] ],
[ "r1:1", "bb1:4t.b", "", [ "$bb" ] ],
[ "r1:2", "bb1:4b.f", "", [ "$bb" ] ],
[ "r2:1", "bb1:7t.b", "", [ "$bb" ] ],
[ "r2:2", "bb1:7b.f", "", [ "$bb" ] ],
[ "r3:1", "bb1:10t.b", "", [ "$bb" ] ],
[ "r3:2", "bb1:10b.f", "", [ "$bb" ] ],
[ "r4:1", "bb1:13t.b", "", [ "$bb" ] ],
[ "r4:2", "bb1:13b.f", "", [ "$bb" ] ],
[ "r5:1", "bb1:16t.b", "", [ "$bb" ] ],
[ "r5:2", "bb1:16b.f", "", [ "$bb" ] ],
[ "r6:1", "bb1:19t.b", "", [ "$bb" ] ],
[ "r6:2", "bb1:19b.f", "", [ "$bb" ] ],
[ "r7:1", "bb1:22t.b", "", [ "$bb" ] ],
[ "r7:2", "bb1:22b.f", "", [ "$bb" ] ],
[ "r8:1", "bb1:25t.b", "", [ "$bb" ] ],
[ "r8:2", "bb1:25b.f", "", [ "$bb" ] ],
[ "mega:5V", "bb1:tp.1", "red", [ "v35.7", "h-180.1", "v-422.4", "h326.4", "v-0.3" ] ],
[ "pot1:VCC", "mega:5V", "red", [ "h0" ] ],
[ "pot1:SIG", "mega:A0", "green", [ "h0" ] ],
[ "pot1:GND", "mega:GND.2", "black", [ "v-48", "h-246.55" ] ]
],
"dependencies": {}
}
07 Run the Simulation
Try it instantly — no hardware needed!
Use the free Wokwi simulator to test the Knight Rider effect in your browser. Drag the potentiometer slider to control speed.
✓ No installation
✓ Interactive potentiometer
✓ Real-time LED animation
✓ Free forever
▶ Open Free Simulation on Wokwi
08 Expected Behavior
- ✓ LEDs scan from left (LED 1) to right (LED 8)
- ✓ At the last LED, direction reverses automatically
- ✓ Creates a smooth, continuous bouncing scanning effect
- ✓ Potentiometer controls animation speed in real time
- ✓ All 8 LEDs flash once at startup to confirm wiring
- ✓ Classic Knight Rider KITT front scanner pattern
09 Learning Outcomes
- Using arrays for pin management
- Understanding direction control logic
- Working with analog inputs
- Creating non-blocking-style animations
- Implementing boundary-based logic reversal
- Mapping sensor values to timing
10 Upgrade Ideas
PWM Fading Trail
Use analogWrite() to create a dimming trail behind the active LED for a smoother glow effect.
Add KITT Sound
Add a passive buzzer generating a swooping tone that syncs with the LED movement.
Shift Register (74HC595)
Reduce from 8 Arduino pins to just 3 using a 74HC595 shift register. Great pin-saving technique.
RGB Knight Rider
Replace single-color LEDs with RGB LEDs and shift through hues as the scanner moves.
millis() Instead of delay()
Replace delay() with millis()-based timing to keep the loop non-blocking for additional features.
32×8 LED Matrix
Scale up to a full 32×8 LED matrix scanner for a dramatic large-format display effect.
Comments
Post a Comment