Build it step by step
0 of 8 doneWire the display
VCC and GND, DIN to D12, CLK to D11, CS to D10.
Wire the buttons
Count on D2, reset on D3, both to GND.
Upload the sketch
The display shows 00000000.
Press the count button
The last digit goes up.
Press it ten times
The tens digit changes.
Wait five seconds, then unplug and replug
The count is remembered.
Hold the reset button for two seconds
The count returns to zero.
Try changing the brightness
Edit the setIntensity value.
How do you build an eight-digit event counter?
A big counter shows visitors, laps or parts counted using an eight-digit display and a button or sensor. You need Arduino Nano, 8-digit 7-segment module (MAX7219), Tactile push button 6 mm × 2 and Breadboard 830 Tie Points. It takes 8 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 4
Parts list
- Development BoardsBuyArduino Nano × 1
- DisplaysBuy
- SwitchesBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Module VCC | Nano 5V | Power |
| Module GND | Nano GND | Ground |
| Module DIN | Nano D12 | Data |
| Module CLK | Nano D11 | Clock |
| Module CS | Nano D10 | Chip select |
| Count button | Nano D2 to GND | Adds one |
| Reset button | Nano D3 to GND | Hold for two seconds to reset |
Code
The MAX7219 is a display driver chip that scans up to eight seven-segment digits for you, so the board only sends numbers over three wires and the chip keeps them lit and bright. The LedControl library gives a setDigit function for each digit position. The sketch splits the count into digits and sends each one, filling unused places with zeros. A button adds one to the count; a debounce delay avoids double counts. The reset button must be held for two seconds so an accidental press does not wipe the number. The count is saved in the board's EEPROM, which keeps it through a power cut, but because EEPROM cells wear out after about a hundred thousand writes, the sketch waits until counting has paused for five seconds before saving. Replace the button with a sensor such as an infrared break-beam to count visitors, laps or parts on a line. Set the brightness with setIntensity: a lower value is easier on the eyes and uses less current.
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).
#include <LedControl.h>
#include <EEPROM.h>
LedControl lc(12, 11, 10, 1); // DIN, CLK, CS, one chip
const int COUNT_BTN = 2, RESET_BTN = 3;
unsigned long count = 0;
unsigned long lastChange = 0;
bool dirty = false;
void showCount() {
unsigned long v = count;
for (int pos = 0; pos < 8; pos++) { // position 0 is the right-most digit
lc.setDigit(0, pos, v % 10, false);
v /= 10;
}
}
void setup() {
pinMode(COUNT_BTN, INPUT_PULLUP);
pinMode(RESET_BTN, INPUT_PULLUP);
lc.shutdown(0, false);
lc.setIntensity(0, 4);
lc.clearDisplay(0);
EEPROM.get(0, count);
if (count > 99999999UL) count = 0; // blank EEPROM reads as a huge number
showCount();
}
void loop() {
if (digitalRead(COUNT_BTN) == LOW) {
delay(30);
if (digitalRead(COUNT_BTN) == LOW) {
count++; dirty = true; lastChange = millis();
showCount();
while (digitalRead(COUNT_BTN) == LOW) {}
delay(30);
}
}
if (digitalRead(RESET_BTN) == LOW) {
unsigned long t0 = millis();
while (digitalRead(RESET_BTN) == LOW && millis() - t0 < 2000) {}
if (millis() - t0 >= 2000) { count = 0; dirty = true; lastChange = millis(); showCount(); }
while (digitalRead(RESET_BTN) == LOW) {}
}
if (dirty && millis() - lastChange > 5000) { // save only after the counting pauses, to spare the EEPROM
EEPROM.put(0, count);
dirty = false;
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Ten presses | Display shows 00000010 |
| Hold the count button | One count only |
| Power cycle after counting | Count restored |
| Reset held 2 seconds | 00000000 |
| Reset tapped | No change |
If it does not work
Display blank
Check power, DIN, CLK and CS wires and the shutdown call.
Digits in reverse order
Change the position order in showCount.
Counts jump by two
Increase the debounce delay.
Number resets after power cut
Wait five seconds after the last count before power off.
Dim display
Raise the setIntensity value.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the eight-digit event counter?
Arduino Nano, 8-digit 7-segment module (MAX7219), Tactile push button 6 mm × 2 and Breadboard 830 Tie Points.
How long does the eight-digit event counter take to build?
About 120 minutes for a beginner maker, in 8 steps.
How do I know the eight-digit event counter works?
Ten presses: Display shows 00000010. Hold the count button: One count only. Power cycle after counting: Count restored.
Display blank: what should I check?
Check power, DIN, CLK and CS wires and the shutdown call.
Digits in reverse order: what should I check?
Change the position order in showCount.
Counts jump by two: what should I check?
Increase the debounce delay.
Number resets after power cut: what should I check?
Wait five seconds after the last count before power off.
