--> Project I - 4 Stopwatch Using LCD Display (Arduino Uno Based) | basic arduino tutorial

Sunday, August 6, 2017

Project I - 4 Stopwatch Using LCD Display (Arduino Uno Based)

| Sunday, August 6, 2017
Stopwatch Using LCD Display



Such a stop watch in general is used to calculate a certain time lag in milliseconds. There are two buttons, START and PAUSE button used to start time calculation and pause also, and the RESET button is used to reset the calculation results. LCD as the viewer of stopwatch calculation results.

Hardware Requirement
  • LCD 2X16 Module
  • 2 Push Button
  • Arduino UNO
  • Power supply +5 Volt


Block diagram


Schematic

Arduino-LCD Wiring


Arduino-Button Wiring



Source Code/Sketch
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
unsigned long mulai, selesai, dataStopWatch;
int i=0;
int fPaus = 0;
long lastButton = 0;
long delayAntiBouncing = 50;
long dataPaus = 0;
void setup(){
pinMode(A0,INPUT);
pinMode(A1,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" Arduino");
lcd.setCursor(0, 1);
lcd.print(" StopWatch");
delay(2000);
lcd.clear();
lcd.print(" Tekan Tombol");
lcd.setCursor(0, 1);
lcd.print(" Start / Stop");
}
void loop(){
if (digitalRead(A0)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (i==0){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Start Timer");
mulai = millis();
fPaus = 0;
}
else if (i==1){
lcd.setCursor(0, 0);
lcd.print("Stop Timer ");
dataPaus = dataStopWatch;
fPaus = 1;
}
i =!i;
}
lastButton = millis();
}
else if (digitalRead(A1)==0 && fPaus == 1){
dataStopWatch = 0;
dataPaus = 0;
lcd.clear();
lcd.print("Reset Stopwatch");
lcd.setCursor(0, 1);
lcd.print("0:0:0.0");
delay(2000);
lcd.clear();
lcd.print(" Tekan Tombol");
lcd.setCursor(0, 1);
lcd.print(" Start / Stop");
}
if (i==1){
selesai = millis();
float jam, menit, detik, miliDetik;
unsigned long over;
// MATH time!!!
dataStopWatch = selesai - mulai;
dataStopWatch = dataPaus + dataStopWatch;
jam = int(dataStopWatch / 3600000);
over = dataStopWatch % 3600000;
menit = int(over / 60000);
over = over % 60000;
detik = int(over / 1000);
miliDetik = over % 1000;
lcd.setCursor(0, 1);
lcd.print(jam, 0);
lcd.print(":");
lcd.print(menit, 0);
lcd.print(":");
lcd.print(detik, 0);
lcd.print(".");
if (jam < 10){
lcd.print(miliDetik, 0);
lcd.print(" ");
}
}
}

How it Works

1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. LCD will display "Arduino Stopwatch" for first time use


     It mean "Press The Start / Stop Button"

5. After 2 second, LCD will display like this


6. Press the Start/Stop Button so the Stopwatch


7. Press Start / Stop button once again to stop the timer


8. To resume the counter of the timer, just press the Start / Stop button again


9. If you want to reset the timer, just press the Reset button while stopwatch in Stop position.


Video for Project I - 4 Stopwatch Usingiw LCD Display (Arduino Uno Based)





Download the required file.

Related Posts

No comments:

Post a Comment