GadhaGod
Published

Stopwatch

Stopwatch with 16x2 LCD with reset and pause controls.

IntermediateShowcase (no instructions)1,439
Stopwatch

Things used in this project

Hardware components

Slide Switch
Slide Switch
×1
button
×1
Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1

Story

Read more

Schematics

stopwatch_KGo8agPyBq.png

Code

Untitled file

C/C++
/*
 * 1. Wire the LCD with pins 7, 6, 5, 4, 3, and 2.
 * 2. Pin 9 to button to gnd
 * 3. Pin 8 to input of switch. Output to gnd
 
 * Change the spm variable to change the speed of the stopwatch for testing purposes.
 */

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int sec = 0;
int min = 0;
int hour = 0;
float spm = 60;
int i = 0;
String secStr;
String minStr;
String hourStr;

void setup() {
  lcd.begin(16, 2);
  // Print a message to the LCD.
  pinMode(9, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  Serial.begin(9600);

}
void running() {
  lcd.clear();

  sec++;
  if (sec == 60) {
    min++;
    sec = 0;
  }

  if (min == 60) {
    hour++;
    min = 0;
  }
  ////////////////////////
  if (sec < 10) {
    secStr = "0" + String(sec);
  }
  else {
    secStr = String(sec);
  }
  ///////////////////////
  if (min < 10) {
    minStr = "0" + String(min);
  }
  else {
    minStr = String(min);
  }
  ///////////////////////
  if (hour < 10) {
    hourStr = "0" + String(hour);
  }
  else {
    hourStr = String(hour);
  }
}
void loop() {
  lcd.setCursor(10, 0);
  lcd.print(secStr);
  lcd.setCursor(7, 0);
  lcd.print(minStr);
  lcd.setCursor(4, 0);
  lcd.print(hourStr);
  lcd.setCursor(6, 0);
  lcd.print(":");
  lcd.setCursor(9, 0);
  lcd.print(":");
  delay(spm);

  if (digitalRead(9) == LOW) {
    running();
  }

  if (digitalRead(8) == LOW){
    sec = 0;
    min = 0;
    hour = 0;
  }
}

Credits

GadhaGod
17 projects • 21 followers

Comments