Countdown timers are not only fun to build but also have practical applications in various scenarios.
Whether you're working on a time-sensitive project, managing your study sessions, or creating a fun kitchen timer, this tutorial will equip you with the skills to build a countdown timer tailored to your needs.
Required Components
Arduino UNO
4- Digit 7 Segment Display (I2C)
Breadboard
3 Push Buttons
Buzzer
8 Male - Male Jumper Wires
4 Male - Female Jumper Wire
Wiring
Arduino UNO | Wiring to Component |
5V | 4 Digit Display (VCC) |
GPIO 02 | Push Button (Increment) |
GPIO 03 | Push Button (Next) |
GPIO 04 | Push Button (Star) |
GPIO 05 | Buzzer Vcc (Red) |
GPIO 06 | 4 Digit Display (CLK) |
GPIO 07 | 4 Digit Display (DIO) |
GND | Ground of 4 Digit Display, Buzzer, and Push Buttons |
Countdown timer using Arduino wiring
Related Video
Summary
Congratulations! You've successfully created a countdown timer using Arduino. This project serves as a great introduction to Arduino programming and electronics. Feel free to share your creation with others and explore further Arduino projects to expand your skills.
Now that you have a functional countdown timer, consider how you can integrate it into various applications, such as events, games, or productivity tools. The possibilities are endless when it comes to Arduino projects, so have fun exploring and creating!
Arduino Code
/* To install provided library:
Sketch--->Include library--->Add .Zip Library..
browse for the provided zip file and click open
*/
#include <TM1637Display.h>
// Define the connections pins:
#define increment_pin 2
#define next_pin 3
#define start_pin 4
#define buzzer 5
#define CLK 6
#define DIO 7
// Define a variable to set minutes or seconds
boolean minutes = true;
// Variable for storing minutes and seconds
int m = 0;
int s = 20;
// Create display object of type TM1637Display:
TM1637Display display = TM1637Display(CLK, DIO);
// Variables for debouncing of the Next and Increment buttons
int NextState;
int lastNext = LOW;
int IncrementState;
int lastIncrement = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
display.clear();
delay(1000);
display.setBrightness(7);
pinMode(increment_pin, INPUT_PULLUP);
pinMode(next_pin, INPUT_PULLUP);
pinMode(start_pin, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
// Show seconds initially (s = 20 seconds)
display.showNumberDecEx(s, 0b11100000, true, 4, 0);
}
void loop() {
increment(digitalRead(increment_pin)); // when incerement button pressed go to increment function
next(digitalRead(next_pin)); // when next button pressed go to next function
// Check if start button pressed
if (digitalRead(start_pin) == LOW) {
int i, j;
display.clear();
delay(500);
//Start coundtdown timer
for (i = m; i >= 0; i--) {
if (i == m) j = s; else j = 59;
for (j; j >= 0 ; j--) {
display.showNumberDecEx(i, 0b11100000, true, 2, 0);
display.showNumberDecEx(j, 0b11100000, true, 2, 2);
delay(1000);
}
}
// if timer finished then start the buzzer forever
while (1) {
tone(buzzer, 1000);
delay(200);
tone(buzzer, 700);
delay(200);
}
}
}
//Function to set seconds or minutes
void next(int reading) {
if (reading != lastNext) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != NextState) {
NextState = reading;
if (NextState == LOW) {
minutes = !minutes;
}
}
}
lastNext = reading;
}
//Function to increment the digits of seconds or minutes
void increment(int reading) {
if (reading != lastIncrement) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != IncrementState) {
IncrementState = reading;
if (IncrementState == LOW && minutes) {
if (m < 59)
m++;
else
m = 0;
display.showNumberDecEx(m, 0b11100000, true, 2, 0);
}
else if (IncrementState == LOW && !minutes) {
if (s < 59)
s++;
else
s = 0;
display.showNumberDecEx(s, 0b11100000, true, 2, 2);
}
}
}
lastIncrement = reading;
}
Comentarii