Bench NotesUno handbook

Seven-Segment Displays: Common Anode vs Common Cathode

Identify your display's polarity and drive digits 0–9 with one switch for either type.

IntermediateSeven-segmentResistor

Overview

A seven-segment display is eight LEDs sharing one common connection. In a common-cathode (CC) display the cathodes are joined: connect COM to GND and drive a segment HIGH to light it. In a common-anode (CA) display the anodes are joined: connect COM to 5V and drive a segment LOW to light it.

You will need

  • Arduino Uno R3
  • Seven-segment display (either type)
  • 8 × 330 Ω resistors
  • Breadboard

Wiring

Uno pinConnects toNotes
2Segment a through 330 Ω
3Segment b through 330 Ω
4Segment c through 330 Ω
5Segment d through 330 Ω
6Segment e through 330 Ω
7Segment f through 330 Ω
8Segment g through 330 Ω
9Segment dp through 330 Ω
GND or 5VCOMGND for common cathode; 5V for common anode

Finding out which you have

Connect COM to GND and touch any segment pin to 5V through a 1 kΩ resistor. If a segment lights, it is common cathode. If not, swap: COM to 5V, segment to GND through the resistor. If that lights it, it is common anode. Part numbers often hint too (for example 5161AS is usually CC and 5161BS CA), but check, because suppliers vary.

Diagram

Segment-to-pin mapSeven-segment digit with segments labelled a (top), b (upper right), c (lower right), d (bottom), e (lower left), f (upper left), g (middle) and dp (decimal point). segment a to pin 2, segment b to pin 3, segment c to pin 4, segment d to pin 5, segment e to pin 6, segment f to pin 7, segment g to pin 8, segment dp to pin 9.agdfbecdpSegment → Uno pinapin 2via 330 Ωbpin 3via 330 Ωcpin 4via 330 Ωdpin 5via 330 Ωepin 6via 330 Ωfpin 7via 330 Ωgpin 8via 330 Ωdppin 9via 330 ΩCOM to GND (CC) or to 5V (CA)
Same pin map as the LUCE and LAOS projects.

The sketch

seven_segment_digits.ino
// Set to true for a common-anode display, false for common-cathode.
const bool COMMON_ANODE = false;
const int FIRST_SEGMENT_PIN = 2;   // a=2, b=3, ... g=8, dp=9

// Segments a b c d e f g dp, 1 = lit
const byte DIGITS[10][8] = {
  {1,1,1,1,1,1,0,0}, // 0
  {0,1,1,0,0,0,0,0}, // 1
  {1,1,0,1,1,0,1,0}, // 2
  {1,1,1,1,0,0,1,0}, // 3
  {0,1,1,0,0,1,1,0}, // 4
  {1,0,1,1,0,1,1,0}, // 5
  {1,0,1,1,1,1,1,0}, // 6
  {1,1,1,0,0,0,0,0}, // 7
  {1,1,1,1,1,1,1,0}, // 8
  {1,1,1,1,0,1,1,0}  // 9
};

void showDigit(int digit) {
  for (int segment = 0; segment < 8; segment++) {
    bool lit = DIGITS[digit][segment] == 1;
    if (COMMON_ANODE) {
      lit = !lit;                       // CA: LOW lights the segment
    }
    digitalWrite(FIRST_SEGMENT_PIN + segment, lit ? HIGH : LOW);
  }
}

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

void loop() {
  for (int digit = 0; digit <= 9; digit++) {
    showDigit(digit);
    delay(700);
  }
}

How the code works

The data stays in "1 = lit" form and only the final write is inverted, so the same tables work for both display types. Note that "all off" on a CA display means writing every pin HIGH, which is why the LUCE and LAOS sketches (written for CC) show inverted letters on a CA part.

What you should observe

  • The digits 0 to 9 count up, 0.7 s each.
  • Inverted digits: flip COMMON_ANODE. Scrambled digits: segment wires swapped.