ARDUINO AND 16X2 LCD BASED STOP WATCH

Simple 16X2 LCD based stop watch, the project tested on multi LCD shield, circuit includes 3 switches, start, stop and reset, project works with 7-12V DC supply or USB power input, code is written for Arduino Nano.

Arduino Connections

  • Switch 1 Arduino Pin A3  RESET SWITCH
  • Switch 2 Arduino Pin D6 TIMER START SWITCH
  • Switch 3 Arduino Pin D7 TIMER STOP SWITCH

Arduino Pins LCD

  • 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
  • LCD R/W pin to ground

Arduino Pins Vs. Various options Multi-Purpose Shield

  • Switch 1 Arduino Pin A3  RESET SWITCH
  • Switch 2 Arduino Pin D6 TIMER START SWITCH
  • Switch 3 Arduino Pin D7 TIMER STOP SWITCH
  • Current Sensor ACS714 Arduino Pin A5
  • Trimmer Potentiometer Arduino Pin A0
  • LM35 Sensor Arduino Pin A4
  • Power Mosfet Arduino Pin D9
  • Relay Arduino Pin D8


ARDUINO CODE


/*Simple LCD stopwatch program with Start, Stop, Reset Switches.
Schematic and PCB layout available at www.twovolt.com Code is modification
of original code from author TechWithZan*/

//including liblary for LCD
#include <LiquidCrystal.h>

//setting up LCD INPUT pins
LiquidCrystal lcd(12,11,5,4,3,2);

//setting hours, minutes, secound and miliseconds to 0
int h=0;
int m=0;
int s=0;
int ms=0;

//defines pin for all buttons
const int start_pin = 6;
const int stop1_pin = 7;
const int reset_pin = 17;

//defines starting points (in my case 0)
int start=0;
int stop1=0;
int reset=0;

void setup()
{

lcd.begin(16 ,2); //starting LCD

//defining pins if they are INPUT or OUTPUT pins
pinMode(start_pin, INPUT);
pinMode(stop1_pin, INPUT);
pinMode(reset_pin, INPUT);
}
void loop()
{
lcd.setCursor(0,1);
lcd.print(“STOP-WATCH”);
lcd.setCursor(0,0);
lcd.print(“TIME:”);
lcd.print(h);
lcd.print(“:”);
lcd.print(m);
lcd.print(“:”);
lcd.print(s);

start = digitalRead(start_pin); //reading buton state
if(start == HIGH)
{
stopwatch(); //goes to sub program stopwatch
}

}

void stopwatch()
{
lcd.setCursor(0,0); //setting start point on lcd
lcd.print(“TIME:”); //writting TIME
lcd.print(h); //writing hours
lcd.print(“:”);
lcd.print(m); //writing minutes
lcd.print(“:”);
lcd.print(s); //writing seconds
ms=ms+10;
delay(10);

if(ms==590)
{
lcd.clear(); //clears LCD
}

if(ms==590) //if state for counting up seconds
{
ms=0;
s=s+1;
}

if(s==60) //if state for counting up minutes
{
s=0;
m=m+1;
}

if(m==60) //if state for counting up hours
{
m=00;
h=h+01;
}

lcd.setCursor(0,1);
lcd.print(“STOP-WATCH”);

stop1 = digitalRead(stop1_pin); //reading buton state
if(stop1 == HIGH) //checking if button is pressed
{
stopwatch_stop(); //going to sub program
}
else
{
stopwatch(); //going to sub program
}
}

void stopwatch_stop()
{
lcd.setCursor(0,0);
lcd.print(“TIME:”);
lcd.print(h);
lcd.print(“:”);
lcd.print(m);
lcd.print(“:”);
lcd.print(s);

lcd.setCursor(0,1);
lcd.print(“STOP-WATCH”);

start = digitalRead(start_pin); //reading buton state
if(start == HIGH)
{
stopwatch(); //going to sub program
}

reset = digitalRead(reset_pin); //reading buton state
if(reset == HIGH)
{
stopwatch_reset(); //going to sub program
loop();
}
if(reset == LOW)
{
stopwatch_stop(); //going to sub program
}
}

void stopwatch_reset()
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“STOPWATCH”);
h=00; //seting hours to 0
m=00; //seting minutes to 0
s=00; //seting seconds to 0
return; //exiting the program and returning to the point where entered the program
}

Watch Video Of This Project

Download Code

Download PDF Schematic

Leave a Reply

Your email address will not be published. Required fields are marked *