Wiring guide

How to wire a 7-segment display to an Arduino Uno

To wire a 7-segment display to an Arduino Uno, connect A to pin 2, B to pin 3, C to pin 4, D to pin 5, E to pin 6, F to pin 7, G to pin 8 and COM1 to GND. One 220 ohm resistor on the common pin limits the current to about 14 mA per segment at 5 V, inside the pin’s 20 mA. The sketch below uses no library beyond what the board includes. It counts through the digits and shows each one.

  • 5 V logic
  • Library: none
  • 8 wires, 1 helper parts
Arduino Uno · 7-segment displaylive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

7-segment display to Arduino Uno wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

7-segment display pinArduino Uno pinWire colorWhy
Segment apin 2amberSegments are named a to g, clockwise from the top, with g across the middle.
Segment bpin 3green
Segment cpin 4cyan
Segment dpin 5violet
Segment epin 6red
Segment fpin 7blue
Segment gpin 8gray
Common (COM)GND, through 220 ohmgrayA common cathode display: every segment returns its current through this one resistor.

Helper parts

The extra parts in the circuit above, and where their wires go:

FromToWire color
R1 (220 Ω) pin 2GNDblue
Voltage

Power and logic levels for 7-segment display and Arduino Uno

Logic level

The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

This pair

At 5 V a red segment through 220 ohm gets about 14 mA, inside the pin’s 20 mA. One resistor on the common is a shortcut: the more segments are lit, the less each one gets, so an 8 is dimmer than a 1. The better wiring is one resistor per segment.

Pins to leave alone

Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.

The sketch

The working code for the Arduino Uno

Library: none, the sketch drives each segment with digitalWrite(). This is the sketch the circuit above runs.

7-segment counter on Arduino Uno
// Segments a to g, in order. The common cathode goes to GND through 220 ohm.
const int SEG_PINS[] = {2, 3, 4, 5, 6, 7, 8};

// One bit per segment: bit 0 is a, bit 6 is g.
const byte DIGITS[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

void show(byte mask) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(SEG_PINS[i], (mask >> i) & 1);
  }
}

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 7; i++) pinMode(SEG_PINS[i], OUTPUT);
}

void loop() {
  for (int d = 0; d < 10; d++) {
    show(DIGITS[d]);
    Serial.print("Showing ");
    Serial.println(d);
    delay(400);
  }
}
Output

What you should see

The display steps through the digits. The serial monitor, at 9600 baud, prints Showing and the digit as it changes.

This is a common cathode display, so the common pin goes to ground. A common anode display needs the common pin on power and the segment levels inverted.

The serial monitor prints this, recorded from the circuit above running:

Showing 0
Showing 1
Showing 2
Showing 3
Showing 4
Showing 5
Pitfalls

Common mistakes wiring a 7-segment display to an Arduino Uno

The wrong display type

A common anode display needs the common on the supply and every bit inverted. Run common cathode code on it and each digit shows as its own negative. The part has a common property in the editor.

Wiring by position, not by letter

The pins on the package are not in segment order. Wire each by its letter, from the pin table, not from the order they sit on the body.

No current limit

Each segment is an LED. Without a resistor somewhere in its path it draws more than a pin can give, and a real display or pin can burn out.

Build your own 7-segment display project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.