4DVolt

7-segment display: pinout and wiring

The 7-segment display shows numbers by lighting seven LEDs in a figure-8 shape, plus the decimal point. See the pinout, the difference between common cathode and common anode, the table for each digit, the code and try it in the simulator.

Single-digit 7-segment display
7-segment display

Specifications

Segments
7 (a to g) + decimal point (dp)
Pins
10: 8 for segments and 2 commons
Types
Common cathode or common anode
Voltage per segment
≈ 2 V (red)
Current per segment
10 to 20 mA
Typical resistor
220 Ω to 330 Ω at 5 V, one per segment
Colors
Red, green, blue, yellow, white
Sizes
0.36", 0.56", 1" and others

Pinout

With the decimal point at the bottom right, the 5 pins on the bottom run left to right (E, D, common, C, DP) and so do the top ones (G, F, common, A, B). The two common pins are joined inside.

Display (10 pins)

1 E Lower left segment
2 D Bottom segment
3 COM Common (cathode or anode)
4 C Lower right segment
5 DP Decimal point
6 B Upper right segment
7 A Top segment
8 COM Common (joined to pin 3 inside)
9 F Upper left segment
10 G Middle segment

7-segment display simulator

Choose the digit and the display type to see which segments light and the logic level each pin receives.

Display type
Digit
Byte (dp g…a)

How to wire it

Common cathode: connect the common to GND. Each segment lights when its pin gets HIGH (5 V). Common anode: connect the common to 5 V and each segment lights when its pin gets LOW (0 V).

Put a 220 Ω to 330 Ω resistor in series with each segment (seven or eight resistors). A single resistor on the common makes digits dimmer as more segments light.

Connect segments A to G (and DP if you want) to eight Arduino digital pins, for example D2 to D9. Storing digits in a byte table keeps the code simple.

For many digits, the Arduino runs out of pins. Use a shift register (74HC595), a driver such as the MAX7219 or TM1637, and drive the digits by multiplexing.

To tell whether the display is common cathode or anode, connect the common to GND and a segment to 5 V through a resistor: if it lights, it is common cathode. If not, reverse it.

Example code (Arduino)

Sketch for a common cathode display that counts from 0 to 9 using a segment table.

// Segments on pins 2 to 8 (a, b, c, d, e, f, g)
const int segments[7] = {2, 3, 4, 5, 6, 7, 8};

// One byte per digit: bit 0 = a ... bit 6 = g (common cathode)
const byte digits[10] = {
  0x3F, 0x06, 0x5B, 0x4F, 0x66,
  0x6D, 0x7D, 0x07, 0x7F, 0x6F
};

void show(int n) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(segments[i], bitRead(digits[n], i));   // use ! for common anode
  }
}

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

void loop() {
  for (int n = 0; n < 10; n++) {
    show(n);
    delay(1000);
  }
}

Common mistakes

  • Forgetting the segment resistors: the LEDs burn out or overload the pins.
  • Mixing up common cathode and anode: digits appear inverted (what should be off is lit).
  • Reading the pinout upside down: check the decimal point, which sits at the bottom right corner.
  • Connecting the two commons to different rails: they are already joined inside, use only one.
  • Lighting several digits through the same resistors without multiplexing: brightness becomes uneven.

Always check the manufacturer's datasheet for your exact model: pin order can vary between modules.

Frequently asked questions

How do I connect a 7-segment display to Arduino?

A 220 Ω resistor on each segment, segments to digital pins and the common to GND (common cathode) or 5 V (common anode).

How can I tell if the display is common cathode or anode?

By the printed part number (for example 5161AS is common cathode and 5161BS is common anode) or by testing with a 5 V source and a resistor.

What is the difference between common cathode and common anode?

On common cathode the LED cathodes are tied to GND and a segment lights with HIGH. On common anode the anodes are tied to 5 V and a segment lights with LOW.

Can I connect the display straight to an ESP32?

Yes, with 330 Ω resistors on each segment, using 3.3 V outputs. Brightness will be a bit lower than at 5 V.

Other components