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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | 7-segment display | One digit. Segments A–G and DP share COM (common cathode by default). |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 2 | 7-segment display A |
| 2 | Arduino Uno pin 3 | 7-segment display B |
| 3 | Arduino Uno pin 4 | 7-segment display C |
| 4 | Arduino Uno pin 5 | 7-segment display D |
| 5 | Arduino Uno pin 6 | 7-segment display E |
| 6 | Arduino Uno pin 7 | 7-segment display F |
| 7 | Arduino Uno pin 8 | 7-segment display G |
| 8 | Arduino Uno GND | 7-segment display COM |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a 7-segment display from the parts palette.
- Wire 1. Connect Arduino Uno pin 2 to 7-segment display A.
- Wire 2. Connect Arduino Uno pin 3 to 7-segment display B.
- Wire 3. Connect Arduino Uno pin 4 to 7-segment display C.
- Wire 4. Connect Arduino Uno pin 5 to 7-segment display D.
- Wire 5. Connect Arduino Uno pin 6 to 7-segment display E.
- Wire 6. Connect Arduino Uno pin 7 to 7-segment display F.
- Wire 7. Connect Arduino Uno pin 8 to 7-segment display G.
- Wire 8. Connect Arduino Uno GND to 7-segment display COM.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator