Stopwatch Using 4 Digit 7 Segment Display & Arduino
In this project, we have designed Simple Stopwatch Using 4 Digit 7 Segment Display & Arduino with Start, Stop & Reset Button. A stopwatch will always have 2 buttons or modes, a start, and a stop mode. It may have other features but it will always have these. Additionally, we have added reset function too. This can be done with the pressing reset button of Arduino. The stopwatch can be used to measure up to 999.9 seconds.
The millis feature of the Arduino Code allows the Arduino to display the functions up to the value in milliseconds to 100% accuracy. Here is our previous version of the same project: Stopwatch Using Arduino, where we used LCD Display instead of LED Display. We also built a Stopwatch using ESP32 and I2C LCD Display.
Components Required:
We just need the following components to make Stopwatch/Lap Timer. All of these components can be purchased from Amazon
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino Nano Board | 1 | Amazon | AliExpress |
| 2 | Common Anode 4 Digit 7 Segment Display | 1 | Amazon | AliExpress |
| 3 | LED Driver IC MAX7219 | 1 | Amazon | AliExpress |
| 4 | Push Button Switch | 1 | Amazon | AliExpress |
| 5 | Capacitor 0.1uF | 1 | Amazon | AliExpress |
| 6 | Capacitor 10uF | 1 | Amazon | AliExpress |
| 7 | Connecting Wires | 10-20 | Amazon | AliExpress |
| 8 | Breadboard | 1 | Amazon | AliExpress |
MAX7219 / MAX7221 8-Digit LED Display Driver
Maxim Integrated MAX7219 / MAX7221 8-Digit LED Display Drivers are compact, serial input/output common-cathode display drivers that interface\microprocessors to 7-segment numeric LED displays of up to 8 digits, to bar-graph displays, or to 64 individual LEDs. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers and an 8×8 static RAM that stores each digit.
Only one external resistor is required to set the segment current for all LEDs. A convenient 4-wire serial interface connects to all common microprocessors. Individual digits may be addressed and updated without rewriting the entire display. MAX7219 also allows the user to select code-B decoding or no-decode for each digit.
Go through MAX7219 Datasheets from here: MAX7219 Datasheets
You can check this project related to the application of MAX7219 IC: 8×8 LED Matrix MAX7219 with Arduino Circuit & Code
Circuit Diagram & Connections
Below is the circuit diagram for Stopwatch Using 4 Digit 7 Segment Display & Arduino. Assemble the circuit as shown in the figure below.
Pin D7 is connected to DataIn (DIN) of MAX7219
Pin D8 is connected to CLK (CLK) of MAX7219
Pin D9 is connected to LOAD (CS) of MAX7219
The 4 Digit 7 Segment Display used here is the Common Anode type. You can even use the Common Cathode type and reverse the Supply and GND.
Working & Operations
Once the code is uploaded to Arduino Board, it will display 000.0. So just press the start button and then the time elapsing starts. To stop the time elapsed just press the same button again. Hence the stopwatch will stop. Now if you want to reset the circuit, then simply press the reset button of the Arduino UNO Board.
The stopwatch can be used to measure up to 999.9 seconds.
Source Code/Program:
The Source Code for Lap Timer/Stopwatch for above circuit is given below. Simply upload the code to Arduino Board. But before that you need to add these two libraries below:
1. LED Control Library: Download
2. Bounce2 Library: Download
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#include <LedControl.h> // Library for LED control with MAX72XX #include <Bounce2.h> // Library for Bounce of switches /* Pins of Arduino Nano for LedControl: Pin #7 is connected to DataIn (DIN) Pin #8 is connected to CLK (CLK) Pin #9 is connected to LOAD (CS) There is only one display with MAX72XX */ LedControl lc = LedControl(7, 8, 9, 1); // LedControl(dataPin, clkPin, csPin, numDevices) int k, lastTime, diffTime; int a, b, c, d; int a1, b1, c1, d1; int pinStartStop = 4; // Start-Stop Pin bool statusSwitch1 = false; Bounce SW1 = Bounce(); // Define Bounce to read StartStop switch Bounce SW2 = Bounce(); // Define Bounce to read Lap switch void setup() { pinMode (pinStartStop, INPUT_PULLUP); // After setting up the button, setup the Bounce instance SW1.attach(pinStartStop); // Sets the pin (Internal Pull-Up) & matches the internal state SW1.interval(3); // Sets the debounce time in milliseconds lc.shutdown(0, false); // The MAX72XX is in power-saving mode on startup, we have to do a wakeup call lc.setIntensity(0, 5); // Set the brightness of display between 0 and 15 lc.clearDisplay(0); // Clear the display lc.setDigit(0, 7, 0, false); lc.setDigit(0, 6, 0, false); lc.setDigit(0, 5, 0, true); lc.setDigit(0, 4, 0, false); lc.setDigit(0, 3, 0, false); lc.setDigit(0, 2, 0, false); lc.setDigit(0, 1, 0, true); lc.setDigit(0, 0, 0, false); } void loop() { lastTime = 0; diffTime = 0; for (k = 0; k <= 9999; k++) { SW1.update(); if (SW1.fell()) { statusSwitch1 = !statusSwitch1; } if (statusSwitch1 == true) { a = k / 1000; b = (k - a * 1000) / 100; c = (k - a * 1000 - b * 100) / 10; d = k % 10; lc.setDigit(0, 7, a, false); lc.setDigit(0, 6, b, false); lc.setDigit(0, 5, c, true); lc.setDigit(0, 4, d, false); } else { k = k - 1; } SW2.update(); if (SW2.fell()) { diffTime = k - lastTime; lastTime = k; a1 = diffTime / 1000; b1 = (diffTime - a1 * 1000) / 100; c1 = (diffTime - a1 * 1000 - b1 * 100) / 10; d1 = diffTime % 10; lc.setDigit(0, 3, a1, false); lc.setDigit(0, 2, b1, false); lc.setDigit(0, 1, c1, true); lc.setDigit(0, 0, d1, false); } delay(99); } } |










6 Comments
Hi i try to make this with 2 digit decimal,can you help me to do that? Thanks!
Thanks for sharing btw!
i does work for me. i have common cathode display. what changes should i make???
Does this work for MAX7219ENG IC
good tutorial….
how to add more StartStop switch independent inputs and outputs … without error …in
thank you.
Bounce SW1 = Bounce(); // Define Bounce to read StartStop switch
Bounce SW2 = Bounce(); // Define Bounce to read StartStop switch
Bounce SW3 = Bounce(); // Define Bounce to read StartStop switch
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
bonjour j’ai besoin d’un contact sur un relai quand le chrono indique 8 secondes que dois je modifier au code pour cela
merci de m’aider si celavous est possible