⚡ LED Chaser / Knight Rider Effect using Arduino Nano
🔰 Project Overview
In this project, we’ll create the famous Knight Rider effect using three LEDs connected to an Arduino Nano.
The lights move from left to right and back again, resembling the moving scanner effect seen on the KITT car.
This project helps you learn:
- How to control multiple outputs in sequence
- How to use loops and logic to create visual effects
- Timing and animation using simple
delay()functions
⚙️ Components Required
| Component | Quantity | Description |
|---|---|---|
| Arduino Nano | 1 | Main microcontroller |
| LEDs (any color) | 3 | Used to create the chasing effect |
| 220Ω Resistors | 3 | To limit LED current |
| Breadboard | 1 | For connections |
| Jumper Wires | Several | For wiring connections |
🧩 Circuit Connection (Text Description)
| LED No. | Arduino Nano Pin | Connection Details |
|---|---|---|
| LED 1 | A3 | Anode (+) → A3 via 220Ω resistor, Cathode (–) → GND |
| LED 2 | A4 | Anode (+) → A4 via 220Ω resistor, Cathode (–) → GND |
| LED 3 | A5 | Anode (+) → A5 via 220Ω resistor, Cathode (–) → GND |
🔌 Power & Ground Connections
- Connect all LED negative legs (–) to Arduino GND
- Use Arduino’s 5V pin as power source (through USB or external)
🪛 Quick Wiring Summary
A3 → 220Ω → LED1 → GND
A4 → 220Ω → LED2 → GND
A5 → 220Ω → LED3 → GND
✅ Same wiring as your previous Traffic Light project — no change needed!
💻 Arduino Code – Knight Rider Effect
// Knight Rider / LED Chaser Effect
// Using Arduino Nano pins A3, A4, A5
int leds[] = {A3, A4, A5}; // LED pins
int numLeds = 3; // Total LEDs
int delayTime = 200; // Delay between LED transitions (milliseconds)
void setup() {
for (int i = 0; i < numLeds; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop() {
// Move light from left → right
for (int i = 0; i < numLeds; i++) {
turnOnOneLed(i);
delay(delayTime);
}
// Move light from right → left
for (int i = numLeds - 2; i > 0; i--) {
turnOnOneLed(i);
delay(delayTime);
}
}
// Helper function to light only one LED at a time
void turnOnOneLed(int index) {
for (int j = 0; j < numLeds; j++) {
digitalWrite(leds[j], (j == index) ? HIGH : LOW);
}
}
🧠 Code Explanation
- Array for LEDs:
All LED pins (A3, A4, A5) are stored in an array for easy looping. - Setup Section:
Each pin is set asOUTPUTto allow the Arduino to control it. - Main Loop:
- The first
forloop turns ON LEDs from left to right (A3 → A4 → A5). - The second
forloop moves right to left (A5 → A4 → A3). - Between each step, a short
delay()creates the moving effect.
- The first
- turnOnOneLed Function:
This ensures only one LED lights at a time, turning off the rest — giving a clean chasing effect.
🔄 Output Sequence
🟢 LED1 → LED2 → LED3 → LED2 → LED1 → repeat…
Looks like a sweeping motion of light!
💬 Project Summary
This simple Knight Rider effect introduces:
- Loop-based animation
- Sequential control of multiple LEDs
- Timing logic using delay()
You can extend this by:
- Adding more LEDs for smoother scanning
- Controlling the speed with a potentiometer
- Adding a fade effect using PWM pins for smoother glow
Pingback: Arduino Demo Kit Projects - Motion Demo Kit (With Arduino) - Project List - EDGENext Learning