LED Chaser / Knight Rider Effect using Arduino Nano

⚡ 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

ComponentQuantityDescription
Arduino Nano1Main microcontroller
LEDs (any color)3Used to create the chasing effect
220Ω Resistors3To limit LED current
Breadboard1For connections
Jumper WiresSeveralFor wiring connections

🧩 Circuit Connection (Text Description)

LED No.Arduino Nano PinConnection Details
LED 1A3Anode (+) → A3 via 220Ω resistor, Cathode (–) → GND
LED 2A4Anode (+) → A4 via 220Ω resistor, Cathode (–) → GND
LED 3A5Anode (+) → 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

  1. Array for LEDs:
    All LED pins (A3, A4, A5) are stored in an array for easy looping.
  2. Setup Section:
    Each pin is set as OUTPUT to allow the Arduino to control it.
  3. Main Loop:
    • The first for loop turns ON LEDs from left to right (A3 → A4 → A5).
    • The second for loop moves right to left (A5 → A4 → A3).
    • Between each step, a short delay() creates the moving effect.
  4. 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

This Post Has One Comment

Leave a Reply