Introduction
In this example, we will learn how to build an Arduino Stopwatch Using 4 Digit 7 Segment Display (TM1637). The stopwatch will have two buttons – one for starting the timer and the other for capturing split times. We will discuss the construction and functionality of the Arduino Stopwatch step by step.
Hardware Required
You will require the following Hardware Components for Arduino Stopwatch Using 4 Digit 7 Segment Display.
Components | # | Buy From Amazon |
---|---|---|
Arduino UNO | 1 | Buy Link |
4 Digit 7 Segment Display – TM1637 | 1 | Buy Link |
Push Buttons | 2 | Buy Now |
9v DC Adapter (Optional) | 1 | Buy Link |
Jumper Wires | 10 | Buy Link |
Breadboard | 1 | Buy Link |
What is the 4 Digit 7 Segment Display?
The 4-digit 7-segment display operates by selectively turning on or off the individual segments to form the desired numerical digit. Each segment of the display is labeled from “a” to “g” and represents a specific portion of the digit. By controlling the segment illumination, different digits can be displayed.
To use the 4-digit 7-segment display with an Arduino or other microcontroller, the common cathode or common anode configuration must be determined. In the common cathode configuration, the common terminal is connected to the ground (GND), and each segment is controlled by applying a high voltage (typically 5V) to illuminate it. In the common anode configuration, the common terminal is connected to the positive voltage supply, and each segment is controlled by grounding it to turn it on.
The Arduino is programmed to sequentially turn on the segments of each digit to display the desired numbers. By rapidly cycling through the digits, the display can create the illusion of showing multiple numbers simultaneously.
Pinout
Pin Configuration
Pin Name | Pin Type |
---|---|
VCC | 5v Power Supply |
SCLK | Clock Input Pin |
RCLK | Clock Input Pin |
DIO | Data Input/Out Pin |
GND | Ground Pin |
Specifications
- Digit Configuration: 4 digits
- Display Type: 7-segment LED display
- Common Cathode or Common Anode configuration
- Maximum Segment Current: Typically 10-20mA per segment
- Forward Voltage: Typically 1.8V – 2.5V per segment
Features
- Compact and easy-to-read numerical display
- Can display numbers from 0 to 9 and some additional characters
- Multiple digits for displaying larger numbers or alphanumeric characters
- Compatible with Arduino and other microcontrollers
- Low power consumption
Circuit Diagram
The following circuit shows you the connection of the Stopwatch Using 4 Digit 7 Segment Display and Arduino Please make the connection carefully
Construction
The stopwatch consists of a four-digit seven-segment display (TM1637) and two buttons – a start button and an intermediate time button. The start button is connected to digital pin 9, and the intermediate time button is connected to pin 8. Both buttons are also connected to the GND on one side.
The TM1637 segment display has an integrated controller and requires only two data lines connected to pin 2 (CLK) and pin 3 (DIO). Please ensure that you check the display for the labeling on the board, as it may vary.
Functionality
When the stopwatch is powered on, the four-digit seven-segment display will show four zeros. Pressing the start button will start the stopwatch, and the display will begin counting up the seconds. If you press the intermediate time button, the time on the display will stop, but the counting will continue in the background.
Pressing the intermediate time button again will show the currently running time on the display. If you press the start button again, the clock will stop both on the display and in the background. You can then choose to let the clock continue running by pressing the intermediate time button, or reset it to zero by pressing the start button again.
Installing Arduino IDE Software
First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow
Installing Libraries
Now when you are Ready to upload the code, to the Arduino Board you will need first to add the Following Libraries in Arduino, If you Learn How to add the library in the Arduino step-by-step guide click on how to install the library Button given Blow
Code
//For more Projects: www.arduinocircuit.com
#include <TM1637Display.h>
#define numberOfSeconds(_time_) ((_time_ / 1000) % 60)
#define numberOfMinutes(_time_) (((_time_ / 1000) / 60) % 60)
int startPin = 9; // start, stop, delete
int zwischenzeitPin = 8; // pause, continue
int stateStart;
int stateZwischenzeit;
int lastStateStart;
int lastStateZwischenzeit;
int programState = 0;
unsigned long startZeit = 0;
long zwischenzeit = 0;
long zeitAngehalten = 0;
TM1637Display display(2, 3);
void setup() {
Serial.begin(115200);
pinMode(startPin, INPUT_PULLUP);
pinMode(zwischenzeitPin, INPUT_PULLUP);
// Set brightness
display.setBrightness(0x0c);
}
void showTime(long theTime) {
unsigned long myTime = theTime - startZeit;
int seconds = numberOfSeconds(myTime);
int minutes = numberOfMinutes(myTime);
display.showNumberDecEx(seconds, 0, true, 2, 2);
if (seconds % 2 == 0) {
display.showNumberDecEx(minutes, 0b01000000, true, 2, 0);
} else {
display.showNumberDecEx(minutes, 0, true, 2, 0);
}
}
void loop() {
stateStart = digitalRead(startPin);
stateZwischenzeit = digitalRead(zwischenzeitPin);
switch (programState) {
case 0: // gestoppt
startZeit = 0;
display.showNumberDecEx(0, 0b01000000, true, 2, 2);
display.showNumberDecEx(0, 0b01000000, true, 2, 0);
// start
if ((stateStart == LOW) && (stateStart != lastStateStart)) {
startZeit = millis();
programState = 1;
}
break;
case 1: // gestartet
showTime(millis());
// zwischenzeit
if ((stateZwischenzeit == LOW) && (stateZwischenzeit != lastStateZwischenzeit)) {
zwischenzeit = millis();
programState = 2;
}
// stop
if ((stateStart == LOW) && (stateStart != lastStateStart)) {
zeitAngehalten = millis();
programState = 3;
}
break;
case 2: // zwischenzeit
showTime(zwischenzeit);
// zwischenzeit ausblenden
if ((stateZwischenzeit == LOW) && (stateZwischenzeit != lastStateZwischenzeit)) {
programState = 1;
}
break;
case 3: // gestoppt
// weiter laufen lassen
if ((stateZwischenzeit == LOW) && (stateZwischenzeit != lastStateZwischenzeit)) {
startZeit = startZeit + (millis() - zeitAngehalten);
programState = 1;
}
// löschen
if ((stateStart == LOW) && (stateStart != lastStateStart)) {
programState = 0;
}
break;
}
lastStateStart = stateStart;
lastStateZwischenzeit = stateZwischenzeit;
}
Applications
- Sports Timing: The stopwatch can be used for timing various sports activities such as running races, swimming laps, or cycling events.
- Cooking Timer: The stopwatch can be used as a kitchen timer to keep track of cooking or baking durations.
- Science Experiments: The stopwatch can be used in science experiments that require precise timing, such as reaction time measurements or interval observations.
- Fitness Training: The stopwatch can be used during fitness training sessions to measure exercise durations and rest intervals.
- Classroom Activities: The stopwatch can be used in educational settings for timed quizzes, games, or group activities.
Conclusion
By following the instructions provided and using the Arduino UNO, a four-digit seven-segment display (TM1637), and two buttons, you can easily build your own stopwatch. This project demonstrates the basic functionality of a stopwatch and can be expanded upon to suit your specific needs.
Remember to double-check the connections and labeling on your display to ensure everything works correctly. Have fun experimenting with different features and functionalities to enhance your stopwatch!