Introduction
LCD Display:
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
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:
- #include < LiquidCrystal.h >
- LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
- int ledPin = 13;
- int buttonPin = 2;
- int value = LOW;
- int buttonState;
- int lastButtonState;
- int blinking;
- int frameRate = 100;
- long interval = (1000 / frameRate);
- long previousMillis = 0;
- long startTime;
- long elapsedTime;
- int fractional;
- int fractionalSecs;
- int fractionalMins;
- int elapsedFrames;
- int elapsedSeconds;
- int elapsedMinutes;
- char buf[10];
- void setup()
- {
- lcd.begin(16, 2);
- pinMode(ledPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- digitalWrite(buttonPin, HIGH);
- }
- void loop()
- {
- digitalWrite(ledPin, LOW);
- buttonState = digitalRead(buttonPin);
- if (buttonState == LOW && lastButtonState == HIGH && blinking == false)
- {
- startTime = millis();
- blinking = true;
- delay(10);
- lastButtonState = buttonState;
- } else if (buttonState == LOW && lastButtonState == HIGH && blinking == true)
- {
- blinking = false;
- lastButtonState = buttonState;
-
- elapsedTime = millis() - startTime;
- elapsedMinutes = (elapsedTime / 60000 L);
- elapsedSeconds = (elapsedTime / 1000 L);
- elapsedFrames = (elapsedTime / interval);
- fractional = (int)(elapsedFrames % frameRate);
- fractionalSecs = (int)(elapsedSeconds % 60 L);
- fractionalMins = (int)(elapsedMinutes % 60 L);
- lcd.clear();
- if (fractionalMins < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa(fractionalMins, buf, 10));
- lcd.print(":");
- if (fractionalSecs < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa(fractionalSecs, buf, 10));
- lcd.print(":");
- if (fractional < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa(fractional, buf, 10));
- } else
- {
- lastButtonState = buttonState;
- }
- if ((millis() - previousMillis > interval))
- {
- if (blinking == true) {
- previousMillis = millis();
- digitalWrite(ledPin, HIGH);
- elapsedTime = millis() - startTime;
- elapsedMinutes = (elapsedTime / 60000 L);
- elapsedSeconds = (elapsedTime / 1000 L);
- elapsedFrames = (elapsedTime / interval);
- fractional = (int)(elapsedFrames % frameRate);
- fractionalSecs = (int)(elapsedSeconds % 60 L);
- fractionalMins = (int)(elapsedMinutes % 60 L);
- lcd.clear();
- if (fractionalMins < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa(fractionalMins, buf, 10));
- lcd.print(":");
- if (fractionalSecs < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa(fractionalSecs, buf, 10));
- lcd.print(":");
- if (fractional < 10)
- {
- lcd.print("0");
- }
- lcd.print(itoa((fractional), buf, 10));
- } else
- {
- digitalWrite(ledPin, LOW);
- }
- }
- }
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