Arduino Nano 7-Segment Display Simulator: Wiring, Code and a Live Circuit
This is a single-digit common cathode 7-segment display wired to an Arduino Nano and counting from 0 to 9, live: the drawing shows the lit segments and the serial monitor names the digit.
- 5 V logic
- No library
- Segments on 2, 3, 4, 5, 6, 7, 8
- Common cathode, 220 ohm
Wiring the 7-Segment Display to the Arduino Nano
Eight connections: seven segment pins from pin 2 onward, and the common through a 220 ohm resistor to GND. Open it in the editor and change the DIGITS table to draw letters.
Every connection in the circuit above, with the board’s own pin names.
| 7-Segment Display pin | Arduino Nano pin | Why |
|---|---|---|
| Segment a | pin 2 | Segments are named a to g, clockwise from the top, with g across the middle. |
| Segment b | pin 3 | |
| Segment c | pin 4 | |
| Segment d | pin 5 | |
| Segment e | pin 6 | |
| Segment f | pin 7 | |
| Segment g | pin 8 | |
| Common (COM) | GND, through 220 ohm | A common cathode display: every segment returns its current through this one resistor. |
Power
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 on the Arduino Nano
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.
On a real bench
The Nano plugs into the breadboard itself, straddling the center channel, so the 7-Segment Display goes in a few columns along and every connection is a short jumper. The silkscreen labels its pins D2 to D13 and A0 to A7; in code D2 is simply 2. A Nano clone with a CH340 USB chip needs that driver on a real computer.
The code, and what it does.
The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.
// 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);
}
}
A seven-segment digit is seven LEDs and a decimal point in one package, with the cathodes joined into a common pin. Each digit is stored as one byte with a bit per segment, so 0x06 lights b and c and shows a 1, and 0x7F lights all seven for an 8.
show() writes each bit of the byte to its pin. The loop walks the ten bytes and holds each for 400 ms, and the serial monitor says which digit it is on. On a common anode display the common goes to the supply instead and every bit is inverted.
Serial.begin(9600) opens the serial monitor. Serial is the USB port, as on the Uno; a clone with a CH340 chip needs that driver on a real computer, which the simulator does not.
Common mistakes with the 7-Segment Display on the 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.
Questions and answers
Can I simulate a 7-segment display with an Arduino Nano?
Yes. The circuit at the top of this page is an Arduino Nano with a 7-segment display, running in your browser on a simulated ATmega328P. The segments are solved as real LEDs, so the brightness changes with the resistor and with how many segments are lit. Press Run it in the editor to change the wiring or the code; it is free and needs no account.
How many pins does a 7-segment display need?
Seven for the segments, an eighth for the decimal point if you use it, and the common. Drive more digits with a shift register or a driver such as the TM1637, which this site also covers.
How do I show the decimal point?
It is an eighth LED on the DP pin. Wire it to another output pin through its own resistor and write it HIGH. This page leaves it unused.
Why does an 8 look dimmer than a 1?
Because all the lit segments share one resistor on the common pin. Put a 220 ohm resistor in series with each segment instead and every digit is equally bright.
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.