Arduino 7-Segment Display Counter: Wiring, Code and Simulator

To build this Arduino 7-Segment Display Counter project you need an Arduino Uno and a 7-segment display. Pins 2–8 drive segments A–G of a common-cathode display, counting 0 to 9. Make the 8 connections in the wiring table, upload the Arduino C++ code, and watch the digits count up. Each digit is just a pattern of seven lit segments.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
17-segment displayOne digit. Segments A–G and DP share COM (common cathode by default).

Wiring

#FromTo
1Arduino Uno pin 27-segment display A
2Arduino Uno pin 37-segment display B
3Arduino Uno pin 47-segment display C
4Arduino Uno pin 57-segment display D
5Arduino Uno pin 67-segment display E
6Arduino Uno pin 77-segment display F
7Arduino Uno pin 87-segment display G
8Arduino Uno GND7-segment display COM

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a 7-segment display from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 2 to 7-segment display A.
  4. Wire 2. Connect Arduino Uno pin 3 to 7-segment display B.
  5. Wire 3. Connect Arduino Uno pin 4 to 7-segment display C.
  6. Wire 4. Connect Arduino Uno pin 5 to 7-segment display D.
  7. Wire 5. Connect Arduino Uno pin 6 to 7-segment display E.
  8. Wire 6. Connect Arduino Uno pin 7 to 7-segment display F.
  9. Wire 7. Connect Arduino Uno pin 8 to 7-segment display G.
  10. Wire 8. Connect Arduino Uno GND to 7-segment display COM.
  11. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  12. Run it. Press Run. Watch the digits count up. Each digit is just a pattern of seven lit segments.

Arduino C++ code

// 7-segment counter: count 0 to 9 on a common-cathode display.
// Segments A..G are on pins 2..8. Each digit is a pattern of lit segments.
const int SEG[7] = {2, 3, 4, 5, 6, 7, 8};

// Bits for segments A B C D E F G, one byte per digit.
const byte DIGITS[10] = {
  0b1111110, 0b0110000, 0b1101101, 0b1111001, 0b0110011,
  0b1011011, 0b1011111, 0b1110000, 0b1111111, 0b1111011,
};

void show(int d) {
  for (int s = 0; s < 7; s++) {
    digitalWrite(SEG[s], (DIGITS[d] >> (6 - s)) & 1);
  }
}

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

void loop() {
  for (int d = 0; d < 10; d++) {
    show(d);
    Serial.println(d);
    delay(700);
  }
}

What to try

Watch the digits count up. Each digit is just a pattern of seven lit segments.

Frequently asked questions

How do I wire the 7-Segment Display Counter project on an Arduino Uno?

Make 8 connections: Arduino Uno pin 2 to 7-segment display A; Arduino Uno pin 3 to 7-segment display B; Arduino Uno pin 4 to 7-segment display C; Arduino Uno pin 5 to 7-segment display D; Arduino Uno pin 6 to 7-segment display E; Arduino Uno pin 7 to 7-segment display F; Arduino Uno pin 8 to 7-segment display G; Arduino Uno GND to 7-segment display COM.

What parts do I need for this Arduino project?

An Arduino Uno and a 7-segment display.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Pins 2–8 drive segments A–G of a common-cathode display, counting 0 to 9.

More Arduino Uno projects