Circuit 3D

Seven-segment display

A seven-segment display is seven bar-shaped LEDs, labeled a to g, arranged as a figure 8, usually with a decimal point, so lighting the right segments shows any digit from 0 to 9. Each segment is an LED with its own resistor, 330 Ω for red segments on 5 V.

R = (Vs − Vf) ÷ I

where Vs is the supply, Vf a segment’s forward voltage, about 2 V for red, and I the current per segment, often 5 to 10 mA.

A digit’s segments share one pin: their anodes in a common-anode display, their cathodes in a common-cathode one.

What is a seven-segment display?

A seven-segment display is a package of seven bar-shaped LEDs, named a to g, laid out as a figure 8 so that lighting a chosen set shows a digit.

Most add an eighth LED for the decimal point, DP, and each digit’s segments share one common pin. In Figure 1, the lab’s 4-digit display sits across the breadboard’s center gap, and a 3 V battery lights one segment at a time through a 100 Ω resistor.

Segment b, pin 7: the battery’s + reaches pin 7 through 100 Ω, and digit 3’s common pin 8 goes to −, so b lights on digit 3 alone, at about (3 V − 2 V) ÷ 100 Ω = 10 mA.

Figure 1. The lab’s common-cathode 4-digit display across the center gap, in a common 12-pin layout. A 3 V battery and a 100 Ω resistor feed the yellow lead to one segment pin; digit 3’s common pin 8 goes to −.

How does a seven-segment display show numbers?

A seven-segment display shows numbers by lighting a different set of segments for each digit: a is the top bar, b to f run clockwise round the edge, and g is the middle bar.

So 1 lights just b and c, 7 adds a, and 8 lights all seven. A microcontroller keeps the ten patterns in a table and sends the one it needs, as Figure 2 shows for each digit.

a 0 b 1 c 1 d 0 e 0 f 1 g 1 common pin to 0 V

4 on common cathode: the common pin goes to 0 V; drive b, c, f and g HIGH and a, d and e LOW, which is 0110011 for abcdefg.

Figure 2. Segments a to g, clockwise from the top with g across the middle, and the level on each segment pin that shows the digit, on 5 V. The lit segments’ pins are outlined.

What is the difference between common anode and common cathode?

Common anode and common cathode differ in which end of the LEDs is shared: a common-cathode display joins every cathode to one ground pin, while a common-anode display joins every anode to one supply pin.

On common cathode, a segment lights when its pin is driven HIGH; on common anode, when its pin is pulled LOW, so every pattern is inverted. The two look identical, so check the part number or test it. Decoder chips suit one or the other: the CD4511 drives common cathode.

What resistor does a seven-segment display need?

A seven-segment display needs one resistor per segment, sized like any LED’s resistor: (5 V − 2 V) ÷ 10 mA = 300 Ω, so 330 Ω, for red segments on 5 V.

A single resistor in the common line is tempting but uneven: its current is shared between however many segments are lit, so a 1 glows brighter than an 8. Figure 3 compares the two.

9.09 mA 1.3 mA each segment

8, one shared resistor: its 9.09 mA splits between 7 lit segments, about 1.3 mA each, so the more segments a digit lights, the dimmer each one glows.

Figure 3. Red segments on 5 V with 330 Ω resistors, either one in each segment line or one in the common line, taking each segment as 2 V.

How do you find a seven-segment display’s pinout?

To find a seven-segment display’s pinout, touch a 3 V supply through a 330 Ω resistor across pairs of pins and see which segment lights.

When a segment lights, the pin on the negative side is a common cathode, or the pin on the positive side a common anode. A multimeter’s diode test does the same, lighting a segment faintly. Many 4-digit displays follow the 12-pin layout in the 3D display above, but check the datasheet.

How do you drive a seven-segment display?

To drive a seven-segment display, use eight microcontroller pins, one per segment and decimal point, each through a resistor, with the common pin to ground or the supply.

To save pins, a decoder such as the CD4511 turns a 4-bit number into the seven segment lines, a 74HC595 shift register sends them over three wires, and driver chips such as the MAX7219 or TM1637 run several digits on their own. For words or graphics, use an LCD or OLED display instead.

How do multi-digit displays work?

Multi-digit displays work by multiplexing: every digit shares the same eight segment lines, and each digit’s common pin is switched on in turn, too fast for the eye to see.

That lets a 4-digit display use 12 pins rather than 33. Each digit is lit a quarter of the time, so it looks dimmer, and its common pin carries every lit segment’s current, often more than a microcontroller pin should, so a transistor usually switches it.

How do you work out a segment’s resistor and current?

To work out a segment’s resistor, divide the leftover voltage by the current; add the lit segments for the common pin’s current: an 8 at 10 mA each takes 70 mA.

Example 1: a segment’s resistor

What resistor does each red segment need on 5 V for 10 mA a segment?

Given
red segments, about 2 V each, on 5 V, at 10 mA a segment
Find
the resistor for each segment
Solution
R = (Vs − Vf) ÷ I = (5 V − 2 V) ÷ 10 mA = 300 ΩThe next standard size up is 330 Ω, which gives 3 V ÷ 330 Ω = 9.09 mA a segment
Answer
330 Ω in each of the eight segment lines

Example 2: a digit’s common-pin current

An Arduino Uno pin switches a digit’s common pin. How much current flows through it showing 8, at 5 mA a segment?

Given
the digit 8, at 5 mA a segment, with its common pin on an Arduino Uno pin
Find
the common pin’s current
Solution
8 lights 7 segments: a, b, c, d, e, f and gI = 7 × 5 mA = 35 mA, over the 20 mA an Uno pin is rated for, so switch the common pin with a transistor
Answer
35 mA through the common pin

Summary

Key equations

  • R = (Vs − Vf) ÷ I each segment’s resistor
  • Icommon = n × I n segments lit

Key terms

Segment
One LED bar, a to g.
DP
The decimal point.
Common pin
The anodes or cathodes, joined.
Multiplexing
Lighting digits in turn, fast.

Practice problems

  1. Which segments light to show 1?

  2. On a common-anode display, how do you light a segment?

  3. What resistor gives about 10 mA a segment from 5 V, with 2 V red segments?

  4. How many segments does 8 light, not counting the decimal point?

  5. Why use a resistor per segment rather than one on the common pin?

FAQ

What is a seven-segment display used for?

Showing numbers simply and brightly: clocks, timers, counters, meters, scoreboards and appliance panels.

How many pins does a seven-segment display have?

A single digit usually has 10: one per segment, one for the decimal point, and two joined common pins. A 4-digit display usually has 12.

How do I tell common anode from common cathode?

Check the part number, or test it: if a segment lights with the common pin on the negative side, it is common cathode.

Do I need a resistor for every segment?

Yes, for even brightness. One resistor on the common pin works, but digits with more segments lit look dimmer.

Can I connect a seven-segment display straight to an Arduino?

The segment pins, yes, each through its resistor. A common pin can carry more than a pin’s 20 mA rating, so multi-digit displays switch it with a transistor.

Can a seven-segment display show letters?

Some: A, b, C, d, E, F, H, L, P and U read well. Letters such as K, M, W and X can’t be drawn clearly.