science tinker

Count 0–9 on a 7-segment display: Arduino project with wiring and code

Breadboard wiring for Count 0–9 on a 7-segment display, as drawn in the simulator.

Show the digits 0, 1, 2 … 9 on the 7-segment display, one per second, then start again. Segments a–g are on pins 2–8.

  • Arduino Uno
  • Intermediate level
  • 3 parts
  • Free, in your browser

You will learn: Arrays, bit patterns (one bit per segment), bitRead and writing your own function.

Project 18 of 62 in the project gallery.

Parts you need

PartHow manyWhat it does in this project
Arduino Uno1Runs your sketch and powers the circuit.
7-segment display1The display. Its seven LED bars (a to g) are lit in different patterns to draw the digits 0 to 9.
220 Ω resistor1Limits the current so the part it protects is not damaged.
Breadboard and jumper wires1Hold the parts and join them without soldering.

How to wire it

Put the parts on the breadboard, join the board's 5V and GND pins to the breadboard's power rails, then make these connections:

PartConnection
7-segment displaysegments: a pin 2, b pin 3, c pin 4, d pin 5, e pin 6, f pin 7, g pin 8

In the Studio, the 💡 guide rings show where each wire goes, and the ✔ Check button tells you which connection is missing.

Starter code

Start from this sketch and write the missing lines. The comments say what each part has to do.

int segPins[] = {2, 3, 4, 5, 6, 7, 8};   // segments a, b, c, d, e, f, g
// one byte per digit: bit 0 = segment a … bit 6 = segment g (1 = on)
byte digits[] = {0b0111111, 0b0000110, 0b1011011};   // 0, 1, 2: add 3 to 9

void showDigit(int n) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(segPins[i], bitRead(digits[n], i));
  }
}

void setup() {
  for (int i = 0; i < 7; i++) {
    pinMode(segPins[i], OUTPUT);
  }
}

void loop() {
  for (int n = 0; n < 3; n++) {   // count to 9 once the table is complete
    showDigit(n);
    delay(1000);
  }
}

Build it step by step

  1. Open the project. Press Build it in the Studio. The parts are already in the tray.
  2. Place and wire the parts. Follow the wiring table above, or switch on the guide rings.
  3. Write the code. Complete the starter sketch in the Code panel, in text or with blocks.
  4. Run it. Press ▶ Run and use the part's slider, button or switch to test it. The Serial Monitor shows what your sketch prints.
  5. Check it. Press ✔ Check: the simulator tests the circuit and the code and tells you exactly what to fix.

Questions students ask

What does the Count 0–9 on a 7-segment display project do?

Show the digits 0, 1, 2 … 9 on the 7-segment display, one per second, then start again. Segments a–g are on pins 2–8.

What parts do I need for the Count 0–9 on a 7-segment display project?

An Arduino Uno, 7-segment display, 1 × 220 Ω resistor, a breadboard and jumper wires.

How do I wire the Count 0–9 on a 7-segment display project?

7-segment display: segments: a pin 2, b pin 3, c pin 4, d pin 5, e pin 6, f pin 7, g pin 8. Power comes from the board's 5V (or 3.3V) and GND pins along the breadboard rails.

What will I learn from the Count 0–9 on a 7-segment display project?

Arrays, bit patterns (one bit per segment), bitRead and writing your own function.

Can I build this without real hardware?

Yes. The project runs in the free Science Tinker microcontroller simulator in your browser: place the parts, wire them, write the sketch and press Run. The ✔ Check button tests your circuit and code and tells you what to fix. Nothing to install and no account needed.

Where is the finished code?

The page gives the starter sketch so that you write the important lines yourself. If you are stuck, the 💡 Solution button in the Studio shows a complete, working sketch that you can run and study.

More intermediate projects

Components in this project

Know someone who would use this?

It’s free for every learner. Send it to your class, team or club.

Updated · Free, no sign-up ·