Projects / Seven-segment direct drive test

Seven-segment direct drive test

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANO12:45

    Find the pins of your display

    Two are common cathodes, the others are segments.

  2. NANO12:45

    Wire the eight segments through resistors

    D2 to D9 in order a to dp.

  3. NANO12:45

    Join the common pin to GND

    Use either middle pin.

  4. NANO12:45

    Upload the sketch

    The segments light one at a time at the start.

  5. NANO12:45

    Match each segment to its letter

    Fix any that are out of order.

  6. NANO

    Watch it count 0 to 9

    Press the button to step.

In short

How do you build a seven-segment direct drive test?

Drive each of the seven segments and the dot of a single digit straight from Nano pins through resistors, then write a small table that turns the numbers 0 to 9 into segment patterns. It shows what a display driver chip does for you. You need Arduino Nano, 7-segment display 1 digit (common cathode), Resistor 330 Ω × 8, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Segment aNano D2 through a 330 ohm resistorTop bar
Segment bNano D3 through a 330 ohm resistorTop right
Segment cNano D4 through a 330 ohm resistorBottom right
Segment dNano D5 through a 330 ohm resistorBottom bar
Segment eNano D6 through a 330 ohm resistorBottom left
Segment fNano D7 through a 330 ohm resistorTop left
Segment gNano D8 through a 330 ohm resistorMiddle bar
Decimal pointNano D9 through a 330 ohm resistorThe dot
Common cathode pins (either middle pin)Nano GNDReturn path for every segment
ButtonNano D10 and GNDSteps to the next digit

Code

A seven-segment digit is eight LEDs in one package, and a common-cathode one joins all their negative ends together. Each segment needs its own resistor, 330 ohms here, so no pin has to carry more than a few milliamps. The sketch first lights each segment in turn so you can match the letters a to g and the dot to the pins you wired, then it counts from 0 to 9. The table at the top is the whole secret: each digit is one byte whose bits say which segments are on. This is exactly the lookup that a display driver chip hides inside. Check the pin layout of your own display, because the order of the pins varies between makers, and a quick test with the segment sweep will show any mistake. The button steps to the next digit straight away. Once it works, try changing the table to show letters such as A, b and C.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const uint8_t SEG_PINS[8] = {2, 3, 4, 5, 6, 7, 8, 9};   // a b c d e f g dp
const uint8_t BUTTON_PIN = 10;

// bit 0 = a, bit 1 = b ... bit 6 = g, bit 7 = dp
const uint8_t DIGITS[10] = {
  0x3F, // 0: a b c d e f
  0x06, // 1: b c
  0x5B, // 2: a b d e g
  0x4F, // 3: a b c d g
  0x66, // 4: b c f g
  0x6D, // 5: a c d f g
  0x7D, // 6: a c d e f g
  0x07, // 7: a b c
  0x7F, // 8: all seven
  0x6F  // 9: a b c d f g
};

void showPattern(uint8_t pattern) {
  for (int i = 0; i < 8; i++) digitalWrite(SEG_PINS[i], (pattern >> i) & 1);
}

void setup() {
  for (int i = 0; i < 8; i++) pinMode(SEG_PINS[i], OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  Serial.begin(9600);
  for (int i = 0; i < 8; i++) {            // segment test: one at a time
    showPattern(1 << i);
    Serial.print("Segment ");
    Serial.println(i);
    delay(400);
  }
}

int digit = 0;
unsigned long lastChange = 0;

void loop() {
  showPattern(DIGITS[digit]);
  bool pressed = digitalRead(BUTTON_PIN) == LOW;
  if (pressed || millis() - lastChange > 1000) {
    digit = (digit + 1) % 10;
    lastChange = millis();
    if (pressed) delay(250);               // simple debounce
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Segment 0
Segment 1
Segment 2
Segment 3
Segment 4
Segment 5

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Segment sweepEach bar lights in order a to g, then the dot
Digit 8All seven bars light
Digit 1Only the two right-hand bars
Button pressSteps straight to the next digit
Count0 to 9, then back to 0

If it does not work

Nothing lights

Check the common pin goes to GND, not 5V.

A segment never lights

Check its resistor and the wire to the pin.

Digits look wrong

Your pins may be in a different order, check the sweep.

Display is a common anode type

Join the common pin to 5V and invert the pattern in code.

Button skips two digits

Hold it only briefly.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the seven-segment direct drive test?

Arduino Nano, 7-segment display 1 digit (common cathode), Resistor 330 Ω × 8, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the seven-segment direct drive test take to build?

About 60 minutes for a beginner maker, in 6 steps.

How do I know the seven-segment direct drive test works?

Segment sweep: Each bar lights in order a to g, then the dot. Digit 8: All seven bars light. Digit 1: Only the two right-hand bars.

Nothing lights: what should I check?

Check the common pin goes to GND, not 5V.

A segment never lights: what should I check?

Check its resistor and the wire to the pin.

Digits look wrong: what should I check?

Your pins may be in a different order, check the sweep.

Display is a common anode type: what should I check?

Join the common pin to 5V and invert the pattern in code.