Stop at ten seconds challenge
Press a button to start a hidden stopwatch and press again when you think ten seconds have passed, and the display shows how close you got.
Build it step by step
0 of 8 doneWire the display
CLK to D6, DIO to D7, with 5V and GND.
Wire the button
D2 to GND.
Wire the buzzer
D8 and GND.
Install the library
TM1637Display from the Library Manager.
Upload the sketch
The display shows 00:00.
Press once
The clock runs for two seconds, then hides.
Press at ten seconds
Your time and error are shown.
Play again
A press resets, the best score stays.
How do you build a stop at ten seconds challenge?
Press a button to start a hidden stopwatch and press again when you think ten seconds have passed, and the display shows how close you got. You need Arduino Nano, TM1637 4-digit display, Tactile push button 6 mm, Passive buzzer, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- DisplaysBuy
- SwitchesBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TM1637 CLK | Nano D6 | Display clock |
| TM1637 DIO | Nano D7 | Display data |
| TM1637 VCC and GND | Nano 5V and GND | Power |
| Button leg 1 | Nano D2 | Start and stop input |
| Button leg 2 | Nano GND | Pressed pulls D2 low |
| Passive buzzer positive | Nano D8 | Result beeps |
| Passive buzzer negative | Nano GND | Common ground |
Code
Estimating ten seconds without a clock is harder than it sounds. In this game the stopwatch is visible for only the first two seconds and then the display shows dashes, so you must keep time in your head. Press the button once to start and again when you think ten seconds have passed. The Nano measures the real elapsed time with millis, which counts milliseconds from power-up, and then shows two numbers in turn: your time in seconds, using the colon of the display as a decimal point, and your error in hundredths of a second, where a minus sign means you stopped early. A result within 0.05 seconds earns a happy double beep. The sketch is a small state machine with three states, idle, running and result, and a press moves it from one to the next. The buttons are debounced with a 40 millisecond lockout. The best error so far is kept in memory and printed on the serial monitor so you can compete with friends. Try counting out loud, tapping a foot or closing your eyes, and see which method works best.
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 <TM1637Display.h>
TM1637Display disp(6, 7); // CLK, DIO
const int BTN = 2, BUZZ = 8;
const unsigned long TARGET_MS = 10000UL;
const unsigned long SHOW_FOR_MS = 2000UL; // the clock is visible for the first two seconds only
enum State { IDLE, RUNNING, RESULT };
State state = IDLE;
unsigned long startMs = 0, stopMs = 0, elapsed = 0;
long errorMs = 0;
long bestAbsError = 99999;
bool wasPressed = false;
unsigned long lastPress = 0;
void showTime(unsigned long ms) {
unsigned int hundredths = (unsigned int)min(ms / 10UL, 9999UL);
disp.showNumberDecEx(hundredths, 0b01000000, true); // colon works as the decimal point: 10:00 is 10.00 s
}
void showHidden() {
const uint8_t dashes[] = {0x40, 0x40, 0x40, 0x40};
disp.setSegments(dashes);
}
void setup() {
pinMode(BTN, INPUT_PULLUP);
disp.setBrightness(4);
Serial.begin(9600);
showTime(0);
Serial.println("Press to start. Press again at 10.00 seconds.");
}
void loop() {
bool pressed = (digitalRead(BTN) == LOW);
bool edge = pressed && !wasPressed && (millis() - lastPress > 40);
wasPressed = pressed;
if (edge) lastPress = millis();
if (state == IDLE) {
if (edge) { startMs = millis(); state = RUNNING; tone(BUZZ, 1200, 60); }
} else if (state == RUNNING) {
unsigned long t = millis() - startMs;
if (t < SHOW_FOR_MS) showTime(t); else showHidden();
if (edge) {
stopMs = millis();
elapsed = stopMs - startMs;
errorMs = (long)elapsed - (long)TARGET_MS;
if (abs(errorMs) < bestAbsError) bestAbsError = abs(errorMs);
state = RESULT;
if (abs(errorMs) <= 50) { tone(BUZZ, 1800, 150); delay(200); tone(BUZZ, 2200, 250); }
else tone(BUZZ, 500, 200);
Serial.print("Time "); Serial.print(elapsed / 1000.0, 2);
Serial.print(" s, error "); Serial.print(errorMs / 1000.0, 2);
Serial.print(" s, best "); Serial.print(bestAbsError / 1000.0, 2); Serial.println(" s");
}
} else { // RESULT: alternate time and error every 2 seconds
unsigned long phase = ((millis() - stopMs) / 2000UL) % 2;
if (phase == 0) showTime(elapsed);
else disp.showNumberDec((int)(errorMs / 10), false); // signed hundredths of a second, minus means early
if (edge) { state = IDLE; showTime(0); }
}
}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.
Press to start. Press again at 10.00 seconds.
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power on | Display shows 00:00 |
| First press | Clock counts for two seconds then shows dashes |
| Stop at exactly 10.00 s | Display shows 10:00 and the error 0 |
| Stop at 9.80 s | Shows 09:80 then an error of -20 |
| Serial monitor | Time, error and best error printed |
If it does not work
Display blank
Check CLK on D6 and DIO on D7 and the 5V wire.
Button seems to start and stop at once
Increase the 40 millisecond lockout.
Digits look odd
The colon is used as a decimal point, so 10:00 means 10.00 seconds.
No beep
Use a passive buzzer on D8.
Timing is wrong
Check the sketch uses millis and the button is on D2.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the stop at ten seconds challenge?
Arduino Nano, TM1637 4-digit display, Tactile push button 6 mm, Passive buzzer, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the stop at ten seconds challenge take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the stop at ten seconds challenge works?
Power on: Display shows 00:00. First press: Clock counts for two seconds then shows dashes. Stop at exactly 10.00 s: Display shows 10:00 and the error 0.
Display blank: what should I check?
Check CLK on D6 and DIO on D7 and the 5V wire.
Button seems to start and stop at once: what should I check?
Increase the 40 millisecond lockout.
Digits look odd: what should I check?
The colon is used as a decimal point, so 10:00 means 10.00 seconds.
No beep: what should I check?
Use a passive buzzer on D8.
