Countdown Timer(Minutes and Seconds) With Arduino and TM1637 4-Digit 7-Segment Display.
by Manodeep in Circuits > Arduino
7088 Views, 4 Favorites, 0 Comments
Countdown Timer(Minutes and Seconds) With Arduino and TM1637 4-Digit 7-Segment Display.
In this project, we will make a Countdown timer(in Minutes and Seconds) with Arduino and 4-Bit 7-Segement display.
Supplies
- Arduino Nano
- TM1637 4-Digit 7-Segment Display
- Breadboard
- Connecting Wire
Gather the Components
- Arduino board (e.g., Arduino Nano)
- TM1637 display module
- Jumper wires
- Breadboard
Connect the Components
- Connect the CLK pin of the TM1637 display module to any digital pin on the Arduino (e.g., pin 2).
- Connect the DIO pin of the TM1637 display module to another digital pin on the Arduino (e.g., pin 3).
- Ensure the power and ground connections are properly made between the Arduino and the TM1637 display module.
Install the TM1637Display Library
- Open the Arduino IDE software.
- Go to "Sketch" -> "Include Library" -> "Manage Libraries".
- In the Library Manager, search for "TM1637Display".
- Select the TM1637Display library by avishorp and click "Install".
Open a New Sketch
- Open a new Arduino sketch in the IDE.
Copy and Paste the Code
#include <TM1637Display.h>
// Countdown Timer
const unsigned long COUNTDOWN_TIME = 300; // 5 minutes in seconds
// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3
TM1637Display display(CLK_PIN, DIO_PIN);
unsigned long startTime;
unsigned long currentTime;
unsigned long elapsedTime;
void setup() {
display.setBrightness(7); // Set the brightness of the display (0-7)
display.clear(); // Clear the display
startTime = millis(); // Record the starting time
}
void loop() {
currentTime = millis(); // Get the current time
elapsedTime = (currentTime - startTime) / 1000; // Calculate elapsed time in seconds
if (elapsedTime <= COUNTDOWN_TIME) {
unsigned long remainingTime = COUNTDOWN_TIME - elapsedTime;
// Display remaining time in Minutes:Seconds format
unsigned int minutes = remainingTime / 60;
unsigned int seconds = remainingTime % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
if (remainingTime == 0) {
// Start blinking when countdown reaches 00:00
while (true) {
display.showNumberDecEx(0, 0b01000000, true); // Display "00:00"
delay(500);
display.clear(); // Clear the display
delay(500);
}
}
}
delay(1000); // Wait for 1 second
}
Verify and Upload the Sketch
- Verify that the code compiles without any errors by clicking the "Verify" button (checkmark icon) in the Arduino IDE.
- Once the code is successfully verified, upload it to the Arduino board by clicking the "Upload" button (right-arrow icon).
Test the Countdown Timer
- After uploading the code to the Arduino, the countdown timer will start immediately.
- The TM1637 display module will show the remaining time in the Minutes: Seconds format.
- When the countdown reaches 00:00, the display will continuously blink "00:00" with a 0.5-second interval.
Conclusion
That's it! You have successfully created a countdown timer using an Arduino and a TM1637 display. The display will show the remaining time in the Minutes:Seconds format and blink continuously at the end of the timer.