Introduction

LCD Display:
  • LCD display is a flat panel display.
  • It does not emit light directly.
  • It will display arbitrary images or fixed images with low information.
Uses:
  • Computer Monitor
  • Televisions
  • Instrument Panels
    Figure 1: LCD Display
Potentiometer:
  • It can have the three terminals.
  • It can have sliding or rotating contact that forms a adjustable voltage divider.
  • It act as a variable resistor (or) rheostat.
    Figure 2: potentiometer
Push Button:
  • The push-button connects the two points.
  • The first pin in the push button are connected to 5Vc.
  • The second pin in the push button is connected to gnd.
    Figure3: Push Button
Parts Of List:
  • Arduino Uno
  • LCD Display
  • Potentiometer
  • Push Button
  • Bread Board
  • Hookup Wire
  • USB cable
Connection:
Step 1: Fix the LCD display in the breadboard and connect it to the Arduino UNO board as per the following figure 4.
Figure 4: LCD Connection.
Step 2: Fix the push button on the breadboard and connect to the Arduino UNO board as per the following figure 5.
Figure5: Pushbutton Connection.
Step 3:
Connect the potentiometer to the LCD display and breadboard. Potentiometer center leads to the LCD display 3pin.
Programming:
  1. #include < LiquidCrystal.h >
  2. LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
  3. int ledPin = 13;
  4. int buttonPin = 2;
  5. int value = LOW;
  6. int buttonState;
  7. int lastButtonState;
  8. int blinking; // condition for blinking - timer is timing
  9. int frameRate = 100; // the frame rate (frames per second) at which the stopwatch runs - Change to suit
  10. long interval = (1000 / frameRate); // blink interval
  11. long previousMillis = 0; // variable to store last time LED was updated
  12. long startTime; // start time for stop watch
  13. long elapsedTime; // elapsed time for stop watch
  14. int fractional; // variable used to store fractional part of Frames
  15. int fractionalSecs; // variable used to store fractional part of Seconds
  16. int fractionalMins; // variable used to store fractional part of Minutes
  17. int elapsedFrames; // elapsed frames for stop watch
  18. int elapsedSeconds; // elapsed seconds for stop watch
  19. int elapsedMinutes; // elapsed Minutes for stop watch
  20. char buf[10]; // string buffer for itoa function
  21. void setup()
  22. {
  23. lcd.begin(16, 2); // intialise the LCD.
  24. pinMode(ledPin, OUTPUT); // sets the digital pin as output
  25. pinMode(buttonPin, INPUT); // not really necessary, pins default to INPUT anyway
  26. digitalWrite(buttonPin, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
  27. }
  28. void loop()
  29. {
  30. digitalWrite(ledPin, LOW); // Initiate LED and Step Pin States
  31. buttonState = digitalRead(buttonPin); // Check for button press, read the button state and store
  32. if (buttonState == LOW && lastButtonState == HIGH && blinking == false)
  33. {
  34. startTime = millis(); // store the start time
  35. blinking = true; // turn on blinking while timing
  36. delay(10); // short delay to debounce switch
  37. lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
  38. } else if (buttonState == LOW && lastButtonState == HIGH && blinking == true)
  39. {
  40. blinking = false; // turn off blinking, all done timing
  41. lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
  42. // Routine to report elapsed time
  43. elapsedTime = millis() - startTime; // store elapsed time
  44. elapsedMinutes = (elapsedTime / 60000 L);
  45. elapsedSeconds = (elapsedTime / 1000 L); // divide by 1000 to convert to seconds - then cast to an int to print
  46. elapsedFrames = (elapsedTime / interval); // divide by 100 to convert to 1/100 of a second - then cast to an int to print
  47. fractional = (int)(elapsedFrames % frameRate); // use modulo operator to get fractional part of 100 Seconds
  48. fractionalSecs = (int)(elapsedSeconds % 60 L); // use modulo operator to get fractional part of 60 Seconds
  49. fractionalMins = (int)(elapsedMinutes % 60 L); // use modulo operator to get fractional part of 60 Minutes
  50. lcd.clear(); // clear the LDC
  51. if (fractionalMins < 10)
  52. {
  53. lcd.print("0"); // add a zero
  54. }
  55. lcd.print(itoa(fractionalMins, buf, 10)); //convert the int to a string and print a fractional part of 60 Minutes to the LCD
  56. lcd.print(":");
  57. if (fractionalSecs < 10)
  58. {
  59. lcd.print("0"); // add a zero
  60. }
  61. lcd.print(itoa(fractionalSecs, buf, 10)); // convert the int to a string and print a fractional part of 60 Seconds to the LCD
  62. lcd.print(":"); //print a colan.
  63. if (fractional < 10)
  64. {
  65. lcd.print("0"); // add a zero
  66. }
  67. lcd.print(itoa(fractional, buf, 10)); // convert the int to a string and print a fractional part of 25 Frames to the LCD
  68. } else
  69. {
  70. lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
  71. }
  72. if ((millis() - previousMillis > interval))
  73. {
  74. if (blinking == true) {
  75. previousMillis = millis(); // remember the last time we blinked the LED
  76. digitalWrite(ledPin, HIGH); // Pulse the LED for Visual Feedback
  77. elapsedTime = millis() - startTime; // store elapsed time
  78. elapsedMinutes = (elapsedTime / 60000 L); // divide by 60000 to convert to minutes - then cast to an int to print
  79. elapsedSeconds = (elapsedTime / 1000 L); // divide by 1000 to convert to seconds - then cast to an int to print
  80. elapsedFrames = (elapsedTime / interval); // divide by 40 to convert to 1/25 of a second - then cast to an int to print
  81. fractional = (int)(elapsedFrames % frameRate); // use modulo operator to get fractional part of 25 Frames
  82. fractionalSecs = (int)(elapsedSeconds % 60 L); // use modulo operator to get fractional part of 60 Seconds
  83. fractionalMins = (int)(elapsedMinutes % 60 L); // use modulo operator to get fractional part of 60 Minutes
  84. lcd.clear(); // clear the LDC
  85. if (fractionalMins < 10)
  86. {
  87. lcd.print("0"); // add a zero
  88. }
  89. lcd.print(itoa(fractionalMins, buf, 10)); // convert the int to a string and print a fractional part of 60 Minutes to the LCD
  90. lcd.print(":"); //print a colan.
  91. if (fractionalSecs < 10)
  92. {
  93. lcd.print("0"); // add a zero
  94. }
  95. lcd.print(itoa(fractionalSecs, buf, 10)); // convert the int to a string and print a fractional part of 60 Seconds to the LCD
  96. lcd.print(":"); //print a colan.
  97. if (fractional < 10)
  98. {
  99. lcd.print("0"); // add a zero
  100. }
  101. lcd.print(itoa((fractional), buf, 10)); // convert the int to a string and print a fractional part of 25 Frames to the LCD
  102. } else
  103. {
  104. digitalWrite(ledPin, LOW); // turn off LED when not blinking
  105. }
  106. }
  107. }
Explanation
  • In this article the stopwatch can work in LCD display.
  • It will show the time continuously and turn off using the push button.
Stopwatch uses
  • Factory
  • Schools and Colleges
  • Sports, etc