LED bar graph

Ten rectangular LEDs side by side in one 20-pin block. Aliases: 10 segment bar graph, DC-10, LED level meter.

There is no chip inside and nothing shared: it is ten separate LEDs, each with its own anode and its own cathode, in a package that fits a breadboard like a DIP chip.

Pins

Pins 1 to 10 along the bottom are the anodes of bars 1 to 10. The cathodes come back along the top, numbered the way a DIP is, so bar 1's cathode is pin 20, straight across from its anode, and bar 10's is pin 11.

Pin What it does
A1 to A10 The anode of each bar.
C1 to C10 The cathode of each bar, opposite its anode.

Pin 1 is at the chamfered corner. Pushed into a breadboard across the channel, each bar has its anode in one half and its cathode in the other.

Properties

color: red, green, blue, yellow or white.

What the model gets right

Each bar is the same diode as the LED: a forward drop set by the color, the current your resistor allows, and nothing at all when it is reversed. Ten bars want ten resistors, or a resistor network; a single resistor in a shared return would dim every bar as more came on, as it does on the bench. Brightness is what the eye sees, so a bar dimmed with PWM looks dimmer rather than flickering.

What it does not model

Bar-to-bar brightness spread, the mixed-color versions (green, yellow and red bars in one block), and anything to do with heat.

Code

A level meter from a potentiometer on A0, with the anodes on pins 2 to 11 through 220 ohm resistors and every cathode to ground:

void setup() {
  for (int pin = 2; pin <= 11; pin++) pinMode(pin, OUTPUT);
}

void loop() {
  int level = map(analogRead(A0), 0, 1023, 0, 10);
  for (int bar = 0; bar < 10; bar++) {
    digitalWrite(2 + bar, bar < level ? HIGH : LOW);
  }
}

Common mistakes

The part in the wrong way around: every bar is reversed and nothing lights. A single resistor on the common ground instead of one per bar.

See it in action

Level meter at /templates is this circuit on a breadboard, ten resistors and all, with the top bar dimmed by PWM. Turn the knob.