How to wire a 7-segment display to an Arduino Nano
To wire a 7-segment display to an Arduino Nano, 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
7-segment display to Arduino Nano 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 pin | Arduino Nano pin | Wire color | Why |
|---|---|---|---|
| Segment a | pin 2 | amber | Segments are named a to g, clockwise from the top, with g across the middle. |
| Segment b | pin 3 | green | |
| Segment c | pin 4 | cyan | |
| Segment d | pin 5 | violet | |
| Segment e | pin 6 | red | |
| Segment f | pin 7 | blue | |
| Segment g | pin 8 | gray | |
| Common (COM) | GND, through 220 ohm | gray | A 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:
| From | To | Wire color |
|---|---|---|
| R1 (220 Ω) pin 2 | GND | blue |
Power and logic levels for 7-segment display and Arduino Nano
Logic level
The Arduino Nano’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
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
Library: none, the sketch drives each segment with digitalWrite(). This is the sketch the circuit above runs.
// 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);
}
}
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 5Common mistakes wiring a 7-segment display to an Arduino Nano
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.