Easy Arduino Stopwatch

by ugur23 in Circuits > Arduino

9862 Views, 23 Favorites, 0 Comments

Easy Arduino Stopwatch

Easy Arduino Chronometer

Hello. I will explain how did i make this simple stopwatch.

Connections

LCD_bb.png

Only connection is between arduino and 16x2 LCD screen.

Same as Arduino.cc tutorials

"LCD RS pin to digital pin 12

LCD Enable pin to digital pin 11

LCD D4 pin to digital pin 5

LCD D5 pin to digital pin 4

LCD D6 pin to digital pin 3

LCD D7 pin to digital pin 2

Additionally, wire a 10k pot to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3). A 220 ohm resistor is used to power the backlight of the display, usually on pin 15 and 16 of the LCD connector"

Includes

We should include and declare LCD to use it. With adding those lines to beginning of sketch

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Then declare Second , Minute and Hour

int sec=0;
int min=0;

int hr=0;

You can change those if you want start Stopwatch from another hr/min/sec

Ex : int sec=50 will start stopwatch from 50. second

Setup

We will start the 16x2 in void setup()

void setup() {
lcd.begin(16,2);

}

Hint : We can add countdown before stopwatch starts with adding these lines to void setup

lcd.print("CHRONOMETER");
delay(1000);

lcd.setCursor(0,0);

lcd.print("STARTS IN 5");

delay(1000);

lcd.clear();

lcd.print("STARTS IN 4");

delay(1000);

lcd.clear();

lcd.print("STARTS IN 3");

delay(1000);

lcd.clear();

lcd.print("STARTS IN 2");

delay(1000);

lcd.clear();

lcd.print("STARTS IN 1");

delay(1000);

lcd.clear();

lcd.setCursor(0,0);

Loop !

This part counts second

main key is

sec=sec+1;

this line adds 1 to second on every loop

we will add

sec=sec+1;
delay(1000);

to mainloop for counting second

Oh Wait ! Forgot Minutes and Hours

We will add those lines for convert second to hours and minutes

if(sec == 60){ //This "if" will add 1Minute to min and reset second
sec=00;

min=min+1;

}else;

if(min == 60){ //This "if" will add 1Hour to hr and reset minute

min=0;

hr=hr+1; }

else;

Print to LCD !

Easy Arduino Chronometer

We will add those lines to beginning of loop for print values to lcd

lcd.setCursor(2,2);
lcd.print("CHRONOMETER");

lcd.setCursor(4,0);

lcd.print(hr);

lcd.setCursor(6,0);

lcd.print(":");

lcd.print(min);

lcd.setCursor(9,0);

lcd.print(":");

lcd.print(sec);

and add

lcd.clear();

to end of loop for clear lcd on every loop

Full Code

/*Arduino Chronometer V1.0*/
#include LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int sec=00; int min=00; int hr=00;

void setup() { lcd.begin(16,2); lcd.setCursor(2,1); lcd.print("CHRONOMETER"); delay(1000); lcd.setCursor(0,0); lcd.print("STARTS IN 5"); delay(1000); lcd.clear(); lcd.print("STARTS IN 4"); delay(1000); lcd.clear(); lcd.print("STARTS IN 3"); delay(1000); lcd.clear(); lcd.print("STARTS IN 2"); delay(1000); lcd.clear(); lcd.print("STARTS IN 1"); delay(1000); lcd.clear(); lcd.setCursor(0,0); }

void loop() {

lcd.setCursor(2,2); lcd.print("CHRONOMETER"); lcd.setCursor(4,0); lcd.print(hr); lcd.setCursor(6,0); lcd.print(":"); lcd.print(min); lcd.setCursor(9,0); lcd.print(":"); lcd.print(sec); sec=sec+1; delay(1000);

if(sec == 60){ sec=00; min=min+1; }else; if(min == 60){ min=0; hr=hr+1; }else;

lcd.clear(); }