CNAP
03 / Templates · beginner

LED BAR GRAPH

Open in Playground

Knight Rider chaser on a 10-segment LED bar graph. A single lit dot sweeps forward and backward using pins 2–11.

beginnerLEDbar graphdigital outputanimation
Circuit
Code
sketch.inoArduino C++
24 lines
// LED Bar Graph — Knight Rider chaser
const int NUM_LEDS = 10;
const int PINS[NUM_LEDS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(PINS[i], OUTPUT);
  }
}

void loop() {
  // Sweep forward
  for (int i = 0; i < NUM_LEDS; i++) {
    digitalWrite(PINS[i], HIGH);
    delay(60);
    digitalWrite(PINS[i], LOW);
  }
  // Sweep backward
  for (int i = NUM_LEDS - 2; i > 0; i--) {
    digitalWrite(PINS[i], HIGH);
    delay(60);
    digitalWrite(PINS[i], LOW);
  }
}
Components
  • Arduino Uno
    01
  • LED Bar Graph (wokwi-led-bar-graph)
    02
  • Resistor 220Ω × 10
    03
Wiring
Component PinArduino Pin
Anodes A1–A10Pins 2–11 (each via 220 Ω resistor)
Cathodes C1–C10 (all tied together)GND