Home / Learn Embedded C / Project: Knight Rider LED Chaser

Project: Knight Rider LED Chaser

Build the full bouncing-LED-chaser project across several real LEDs.

In shortBuild the full bouncing-LED-chaser project across several real LEDs.

What's actually going on

Chaser motionLight position 0Advance positionHit the end, flipdirectionAdvance backtoward 0
Chaser motion

In plain terms

A row of LEDs where a single lit position bounces back and forth, built as a complete, runnable project on top of the "knight rider" lesson from the GPIO group.

Why we use it

Real projects are where embedded C patterns become habits instead of theory.

Under the hood

Work through the steps in order; do not skip the checklist.

Real-world use

  • Portfolio project
  • Interview preparation
  • Real hardware practice

What you will build

A row of LEDs where a single lit position bounces back and forth, built as a complete, runnable project on top of the "knight rider" lesson from the GPIO group.

LevelTime needed
Beginner1-2 hours

What you need (tools and setup)

ToolWhat it isWhy you need itCost
This course's live C sandboxA small in-browser C interpreter with simulated GPIO/UART/ADC/PWM.Every project in this course can be tried here first with zero setup, no board required.free, built in
Code editor (VS Code or similar)The program you write firmware source files in.You need somewhere to write and organise the real .c/.h files for the project.free
A real development board (Arduino/AVR, STM32 Nucleo, or ESP32 dev board) — optionalThe actual microcontroller hardware.Lets you move from the simulated board to a real one once the logic works here.low cost, optional

Step 1: see it working in the sandbox

A 4-LED chaser bouncing back and forthC: edit and run

Only one LED is HIGH at a time; the rest are explicitly driven LOW each step so the previous LED turns off.

Step by step

  1. Wire 4+ LEDs (with current-limiting resistors) to separate GPIO pins.
  2. Store the pin numbers in an array and configure each as OUTPUT.
  3. Track pos and dir, lighting only the current position and turning all others off each step.
  4. Flip dir when pos reaches either end of the array.
  5. Tune the per-step delay until the motion looks smooth, not jerky or too fast to see.

Checklist before you call it done

CheckWhy it mattersHow to verify
Exactly one LED lit at any instantConfirms the "turn others off" logic is correctWatch closely at a slow delay
Motion bounces cleanly at both endsConfirms direction-flip boundary logicWatch a few full back-and-forth cycles
Delay value tuned for visible, smooth motionPure usability of the finished projectTry several delay values and compare
Tip:Commit the first working version and every later improvement as separate commits, so the diff itself becomes a teaching example.
Adding a trailing fade effect to the chaserC: edit and run

Using PWM_WRITE instead of a plain on/off GPIO_WRITE lets neighboring LEDs glow dimly, giving the chaser a trailing-fade look.

Quick quiz

1. Why must every other LED be explicitly driven LOW each step, not just the new one driven HIGH?