Single-Digit 7-Segment LED Numeric Display Counter
Decode binary digit bitmasks (0–9) across seven individual LED segments with current-limiting resistors.
Learn how classic digital clocks, scoreboards, and multimeters display crisp numerals! Wire a 1-digit Common-Cathode 7-segment LED display (segments a–g + decimal point) to Arduino Uno pins D2–D8 via seven 220Ω resistors, build a compact byte lookup table, and run a 0–9 counter.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerEach lit LED segment draws ~13mA through its 220Ω series resistor. Displaying digit "8" lights all 7 segments (~91mA total), safely within the Arduino Uno ATmega328P 200mA package VCC/GND limit. Use a dedicated 220Ω resistor on EVERY segment pin (a–g) so digit "8" stays just as bright as digit "1" and pin currents remain safe.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| Single-Digit 7-Segment LED (5161AS) | Common Cathode (5161AS) or Common Anode (5161BS) | 1 | $0.80 |
| 220Ω Resistors (1/4W) | One per segment a–g for uniform luminosity | 7 | $0.35 |
| Breadboard & Jumper Wires | 10× breadboard jumpers | 1 | $2.00 |
Electrical & System Architecture
Connect common pin(s) (middle pins 3 and 8) to GND (for Common Cathode). Wire segments a→D2, b→D3, c→D4, d→D5, e→D6, f→D7, g→D8 each through its own 220Ω current-limiting resistor.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling 5161AS Single-Digit 7-Segment Display acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Verify Common-Cathode vs. Common-Anode Part Number
Read the tiny code stamped on the side: 5161AS = Common Cathode (COM→GND); 5161BS = Common Anode (COM→5V).
- Straddle the 10-pin display vertically across the center breadboard groove (decimal point at bottom-right).
- Locate the two center pins (top middle = pin 8, bottom middle = pin 3)—both are internally connected Common.
- Connect Common pin 3 (or 8) to GND for Common Cathode (or 5V for Common Anode).
Wire Seven 220Ω Resistors to Segments a–g
Map standard 5161AS footprint pins through 220Ω resistors to Arduino D2–D8.
- Top row (left to right): Pin 10=g(D8), Pin 9=f(D7), Pin 8=COM(GND), Pin 7=a(D2), Pin 6=b(D3).
- Bottom row (left to right): Pin 1=e(D6), Pin 2=d(D5), Pin 3=COM(GND), Pin 4=c(D4), Pin 5=dp(optional).
- Place one 220Ω resistor in series with each segment wire from D2 through D8.
Run Segment-by-Segment Walk Diagnostic
Flash the pin walker so segments light clockwise a → b → c → d → e → f → g one at a time.
- Upload the diagnostic snippet below.
- Watch segments trace the perimeter clockwise starting at top bar (a) and finishing at center bar (g).
- Swap any jumper wire whose segment lights out of sequence.
Upload Bitmask 0–9 Counter Firmware
Flash the compact binary lookup counter and verify every numeral 0 through 9 renders crisply.
- Upload the production sketch below.
- Watch digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 step smoothly every 800ms.
- Verify Serial Monitor echoes the active digit.
Inspect Brightness Uniformity
Compare segment brightness on "1" vs "8" to confirm your seven 220Ω resistors keep luminance rock-steady.
- Confirm digit "8" does not dim relative to digit "1".
- Verify every horizontal and vertical bar is crisp and evenly lit.
- Try extending the table to Hex digits A, b, C, d, E, F!
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: 5161AS Single-Digit 7-Segment Display Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for 5161AS Single-Digit 7-Segment Display before running the full project firmware.
// Diagnostic: Walk Segments a(D2) through g(D8) Clockwise
void setup() { for (int p=2; p<=8; p++) pinMode(p, OUTPUT); }
void loop() {
for (int p=2; p<=8; p++) { digitalWrite(p, HIGH); delay(400); digitalWrite(p, LOW); }
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 27: Single-Digit 7-Segment LED Bitmask Counter (0-9)
* Board: Arduino Uno R3 | Pins: a=D2, b=D3, c=D4, d=D5, e=D6, f=D7, g=D8
*/
const uint8_t SEG_PINS[7] = {2, 3, 4, 5, 6, 7, 8}; // a, b, c, d, e, f, g
const bool COMMON_ANODE = false; // Set true for Common-Anode (5161BS)
// Bit order: bit0=a, bit1=b, bit2=c, bit3=d, bit4=e, bit5=f, bit6=g
const uint8_t DIGIT_MASKS[10] = {
0b0111111, // 0
0b0000110, // 1
0b1011011, // 2
0b1001111, // 3
0b1100110, // 4
0b1101101, // 5
0b1111101, // 6
0b0000111, // 7
0b1111111, // 8
0b1101111 // 9
};
void showDigit(uint8_t num) {
if (num > 9) return;
uint8_t mask = DIGIT_MASKS[num];
for (uint8_t i = 0; i < 7; i++) {
bool lit = bitRead(mask, i);
digitalWrite(SEG_PINS[i], COMMON_ANODE ? !lit : lit);
}
}
void setup() {
Serial.begin(115200);
for (uint8_t i = 0; i < 7; i++) pinMode(SEG_PINS[i], OUTPUT);
Serial.println(F("7-Segment Display Counter Ready"));
}
void loop() {
for (uint8_t d = 0; d <= 9; d++) {
showDigit(d);
Serial.print(F("Displaying Digit: "));
Serial.println(d);
delay(800);
}
}Firmware Architecture Explanation:
- Encodes all 10 numerals in a compact 10-byte bitmask array using standard bit0=a through bit6=g mapping.
- Uses bitRead() to drive all 7 output pins cleanly in one 4-line loop.
- Supports both Common-Cathode and Common-Anode displays via COMMON_ANODE inversion.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Digit 0 | 0b0111111 | a,b,c,d,e,f ON | Render Numeral 0 |
| Digit 1 | 0b0000110 | b,c ON | Render Numeral 1 |
| Digit 8 | 0b1111111 | All 7 Segments ON | Render Numeral 8 |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| No segments illuminate at all | Common-Anode display wired to GND (or Common-Cathode wired to 5V) | Check 5161AS vs 5161BS side code | Match COM wire (GND vs 5V) and COMMON_ANODE boolean. |
| Digits look scrambled (e.g., "2" looks broken) | Two segment jumpers swapped | Run clockwise segment walk diagnostic | Verify a→D2, b→D3, c→D4, d→D5, e→D6, f→D7, g→D8. |
| Segments light inverted (all ON except target digit) | COMMON_ANODE flag opposite of hardware | Inspect digit "8" vs "1" | Toggle COMMON_ANODE between true and false. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Add a push button on D10 that rolls a rapid animation and lands on random(1, 7).
Use two debounced buttons to increment and decrement 0–9.
Count down 9 → 0 with Project 5 buzzer beeps and flash an LED at zero.