Projects / Knight-rider LED chaser

Knight-rider LED chaser

Beginner2 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Place the chip

    Straddle the breadboard centre gap.

  2. NANO

    Wire power and control pins

    Pin 16 and 10 to 5V, pin 8 and 13 to GND.

  3. NANO

    Wire the three signal pins

    D2 to pin 14, D3 to pin 11, D4 to pin 12.

  4. NANO8.5 mA

    Wire the LEDs

    Each output through 330 ohm to an LED to GND.

  5. NANO

    Wire the pot

    Outer legs to 5V and GND, middle to A0.

  6. NANO

    Upload the sketch

    A single light sweeps along the row.

  7. NANO

    Turn the pot

    The sweep speeds up and slows down.

  8. NANO

    Try other patterns

    Replace the loop with show(0b10101010) and similar.

In short

How do you build a knight-rider LED chaser?

A shift register drives eight LEDs in a back-and-forth sweep with only three Arduino pins. You need Arduino Nano, 74HC595 Shift Register, LED 5 mm red × 8, Resistor 330 Ω × 8, Potentiometer 10 kΩ and Breadboard 830 Tie Points. It takes 8 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
74HC595 pin 16 (VCC) and pin 10 (SRCLR)Nano 5VPower, and keep the clear pin high
74HC595 pin 8 (GND) and pin 13 (OE)Nano GNDGround, and keep the outputs enabled
Nano D274HC595 pin 14 (DS)Serial data
Nano D374HC595 pin 11 (SHCP)Shift clock
Nano D474HC595 pin 12 (STCP)Latch clock
74HC595 pins 15 and 1 to 7 (QA to QH)Eight red LED anodes through 330 ohmLED cathodes go to GND
Pot middle legNano A0Speed control, outer legs to 5V and GND

Code

A 74HC595 turns three Arduino pins into eight outputs. You clock one byte of data in, bit by bit, on the data and clock pins. Nothing changes on the outputs until you pulse the latch pin, which copies the whole byte to the eight output pins at once. That is why the sketch sets the latch low, shifts one byte and sets the latch high. Two chips in a chain give sixteen outputs from the same three pins. The sweep lights one LED at a time and moves it along, then back again, like the light on a famous TV car. The knob changes the delay between steps. The 330 ohm resistors keep each LED to about 9 milliamps, and because only one LED is lit at a time the chip stays well within its total current limit of about 70 milliamps; if you try patterns with many LEDs lit at once, use larger resistors. The output enable pin is tied low to switch the outputs on and the clear pin is tied high so the stored byte is never wiped by accident.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const int DATA = 2;
const int CLOCK = 3;
const int LATCH = 4;
const int SPEED_POT = A0;

void show(byte pattern) {
  digitalWrite(LATCH, LOW);
  shiftOut(DATA, CLOCK, MSBFIRST, pattern);   // bit 0 appears on the first output QA
  digitalWrite(LATCH, HIGH);
}

int stepDelay() {
  return map(analogRead(SPEED_POT), 0, 1023, 30, 300);   // 30 to 300 milliseconds
}

void setup() {
  pinMode(DATA, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(LATCH, OUTPUT);
  show(0);
}

void loop() {
  for (int i = 0; i < 8; i++) {                // sweep left to right
    show(1 << i);
    delay(stepDelay());
  }
  for (int i = 6; i > 0; i--) {                // and back, without repeating the ends
    show(1 << i);
    delay(stepDelay());
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onOne LED sweeps left then right
Pot fully downFast sweep
Pot fully upSlow sweep
Show 0xFF brieflyAll eight LEDs light
Pin 13 left floatingOutputs may flicker, tie it to GND

If it does not work

No LEDs light

Check pin 16, pin 8 and pin 13 and the LED direction.

Wrong LED order

Check the output pin order QA to QH.

Random flicker

Pin 10 or pin 13 is floating, tie them as shown.

Chip warms up

Too many LEDs lit at once, use larger resistors.

Sweep too fast to see

Raise the delay range in stepDelay().

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the knight-rider LED chaser?

Arduino Nano, 74HC595 Shift Register, LED 5 mm red × 8, Resistor 330 Ω × 8, Potentiometer 10 kΩ and Breadboard 830 Tie Points.

How long does the knight-rider LED chaser take to build?

About 120 minutes for a beginner maker, in 8 steps.

How do I know the knight-rider LED chaser works?

Power on: One LED sweeps left then right. Pot fully down: Fast sweep. Pot fully up: Slow sweep.

No LEDs light: what should I check?

Check pin 16, pin 8 and pin 13 and the LED direction.

Wrong LED order: what should I check?

Check the output pin order QA to QH.

Random flicker: what should I check?

Pin 10 or pin 13 is floating, tie them as shown.

Chip warms up: what should I check?

Too many LEDs lit at once, use larger resistors.