MyRoboPathOpen Robotics Lab
Arduino Uno #27 of 35
Est. 0.75 Hours
Budget: $2 - $4
Beginner

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.

Arduino Uno R37-Segment DisplayBinary BitmasksCommon CathodeNumeric Counter
Single-Digit 7-Segment LED Numeric Display Counter Blueprint
Single-Digit 7-Segment LED Numeric Display CounterCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Read standard 10-pin 7-segment DIP footprints (top row g-f-COM-a-b, bottom row e-d-COM-c-dp).
2Understand why per-segment resistors keep brightness constant between digit "1" (2 LEDs) and "8" (7 LEDs).
3Encode digits 0–9 efficiently into 7-bit binary lookup tables and extract bits with bitRead().
4Toggle between Common Cathode and Common Anode polarity cleanly in a single boolean flag.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

Each 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.

Single-Digit 7-Segment LED Numeric Display Counter Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for Single-Digit 7-Segment LED Numeric Display Counter
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$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 luminosity7$0.35
Breadboard & Jumper Wires10× breadboard jumpers1$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.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for Single-Digit 7-Segment LED Numeric Display Counter.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for Single-Digit 7-Segment LED Numeric Display Counter.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling 5161AS Single-Digit 7-Segment Display acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for Single-Digit 7-Segment LED Numeric Display Counter.
Figure: Firmware execution flow and state transitions for Single-Digit 7-Segment LED Numeric Display Counter.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Verify Common-Cathode vs. Common-Anode Part Number

Duration: 5 Mins

Read the tiny code stamped on the side: 5161AS = Common Cathode (COM→GND); 5161BS = Common Anode (COM→5V).

Single-Digit 7-Segment LED Numeric Display Counter hardware layout diagram
Stage 1: 5161AS Single-Digit 7-Segment Display hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • 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).
Engineering & Tuning Tip: If you have a Common-Anode display (5161BS), connect COM to 5V and set COMMON_ANODE = true in code!
2

Wire Seven 220Ω Resistors to Segments a–g

Duration: 15 Mins

Map standard 5161AS footprint pins through 220Ω resistors to Arduino D2–D8.

Single-Digit 7-Segment LED Numeric Display Counter breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Take 2 extra minutes to route neat jumper wires—it makes troubleshooting a swapped segment effortless.
3

Run Segment-by-Segment Walk Diagnostic

Duration: 5 Mins

Flash the pin walker so segments light clockwise a → b → c → d → e → f → g one at a time.

Single-Digit 7-Segment LED Numeric Display Counter power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈90mA all 7 segments lit)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: The clockwise a-b-c-d-e-f-g walk catches 100% of wiring swaps in 5 seconds!
4

Upload Bitmask 0–9 Counter Firmware

Duration: 5 Mins

Flash the compact binary lookup counter and verify every numeral 0 through 9 renders crisply.

Single-Digit 7-Segment LED Numeric Display Counter serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Using a single 10-byte array uses 7× less RAM and code than writing ten separate functions!
5

Inspect Brightness Uniformity

Duration: 5 Mins

Compare segment brightness on "1" vs "8" to confirm your seven 220Ω resistors keep luminance rock-steady.

Single-Digit 7-Segment LED Numeric Display Counter live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • 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!
Engineering & Tuning Tip: To drive 4-digit displays without burning 28 pins, use time-division multiplexing or a 2-wire TM1637 driver.

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 Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for 5161AS Single-Digit 7-Segment Display before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// 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); }
}
Expected Output: Illuminates segments a → b → c → d → e → f → g sequentially.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_7_segment_single_digit_display.ino
arduino_uno_7_segment_single_digit_display.inoArduino C++
/**
 * 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

1Double-check all 4 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Illuminates segments a → b → c → d → e → f → g sequentially.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for Single-Digit 7-Segment LED Numeric Display Counter
Input / StatePin / SignalDetected ConditionExpected Output
Digit 00b0111111a,b,c,d,e,f ONRender Numeral 0
Digit 10b0000110b,c ONRender Numeral 1
Digit 80b1111111All 7 Segments ONRender Numeral 8

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for Single-Digit 7-Segment LED Numeric Display Counter
ProblemLikely CauseDiagnostic CheckEngineering Solution
No segments illuminate at allCommon-Anode display wired to GND (or Common-Cathode wired to 5V)Check 5161AS vs 5161BS side codeMatch COM wire (GND vs 5V) and COMMON_ANODE boolean.
Digits look scrambled (e.g., "2" looks broken)Two segment jumpers swappedRun clockwise segment walk diagnosticVerify 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 hardwareInspect 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:

Level 1Electronic 6-Sided Dice

Add a push button on D10 that rolls a rapid animation and lands on random(1, 7).

Level 2Button Up/Down Scoreboard

Use two debounced buttons to increment and decrement 0–9.

Level 3Countdown Rocket Timer

Count down 9 → 0 with Project 5 buzzer beeps and flash an LED at zero.