Arduino Stopwatch with LCD Display
The Arduino Stopwatch with LCD Display is a versatile project that utilizes Arduino and a LiquidCrystal display to create a functional stopwatch.
The circuit includes an LCD with buttons for start/stop/lap and reset functionalities. It offers precise timekeeping capabilities, making it suitable for various time measurement applications.
Component List:
Name | Quantity | Component |
---|---|---|
U1 | 1 | Arduino Uno R3 |
U2 | 1 | LCD 16 x 2 |
S1 S2 | 2 | Pushbutton |
Rpot1 | 1 | 250 kΩ Potentiometer |
R1 R2 | 2 | 1 kΩ Resistor |
R3 | 1 | 220 Ω Resistor |
The circuit consists of an Arduino board connected to an LCD with specified pins for RS, Enable, and data pins (D4-D7). Two buttons, Button 1 and Button 2, are connected to digital pins 6 and 7, respectively.
Additionally, a 10k resistor is used for pull-up purposes. The LCD displays hours, minutes, seconds, and milliseconds, providing accurate time measurements.
Arduino Code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int btn1 = 6, btn2 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long startTime, elapsedTime, totalTime;
int btn1State, btn1LastState, btn2State, btn2LastState;
int h, m, s, ms, rest;
bool running;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(4, 0);
pinMode(btn1, INPUT);
pinMode(btn2, INPUT);
lcd.print("ARDUINO");
delay(500);
lcd.setCursor(3, 1);
lcd.print("stopwatch");
delay(500);
lcd.clear();
lcd.print("000:00:00:000");
lcd.setCursor(0, 1);
lcd.print("000:00:00:000");
digitalWrite(btn1, HIGH);
digitalWrite(btn2, HIGH);
running = false;
totalTime = 0;
startTime = 0;
elapsedTime = 0;
}
void loop() {
btn1State = digitalRead(btn1);
btn2State = digitalRead(btn2);
if (btn1State == HIGH && btn1LastState == LOW) {
startStopLap();
} else if (btn2State == HIGH && btn2LastState == LOW) {
resetClock();
}
if (running) printTime(millis() - startTime, 0);
btn1LastState = btn1State;
btn2LastState = btn2State;
}
void startStopLap() {
if (running) {
elapsedTime = millis() - startTime;
running = false;
totalTime += elapsedTime;
lcd.setCursor(0, 0);
lcd.print("000:00:00:000");
printTime(totalTime, 1);
} else {
startTime = millis();
running = true;
}
delay(5); // for debouncing
}
void resetClock() {
running = false;
startTime = 0;
elapsedTime = 0;
totalTime = 0;
lcd.clear();
lcd.print("000:00:00:000");
lcd.setCursor(0, 1);
lcd.print("000:00:00:000");
delay(5); // for debouncing
}
void printTime(unsigned long time, int row) {
h = (int)time / 3600000;
rest = (int)time % 3600000;
m = rest / 60000;
rest = rest % 60000;
s = rest / 1000;
ms = rest % 1000;
lcd.setCursor(0, row);
if (h < 100) lcd.print(0);
if (h < 10) lcd.print(0);
lcd.print(h);
lcd.print(":");
if (m < 10) lcd.print(0);
lcd.print(m);
lcd.print(":");
if (s < 10) lcd.print(0);
lcd.print(s);
lcd.print(":");
if (ms < 100) lcd.print(0);
if (ms < 10) lcd.print(0);
lcd.print(ms);
}
This Arduino Stopwatch project combines hardware components and programming logic to create a user-friendly stopwatch with LCD feedback. The buttons facilitate easy control, allowing users to start, stop, and reset the stopwatch.
The LCD display provides a clear and organized representation of time, enhancing the user experience. This project is suitable for anyone interested in learning about Arduino-based timekeeping applications and can be customized for various timing needs.