DISPLAY DATA ON LCD 16X2 ON AN INPUT BY A SWITCH USING ARDUINO

In this program, we will see how to print different strings or messages with different input signals or how to display data on LCD 16×2 on an input by a switch using Arduino.

CIRCUIT DIAGRAM

Here we are defining two pins as input to the arduino that are 12 and 13 and to store their states two variables buttonState12 and buttonState13 and initialize to 0.

Whenever any button gets pressed a different message will going to display on the LCD.

Circuit Diagram of Interfacing of LCD 16x2 and button with Arduino Uno
Circuit Diagram of Interfacing of LCD 16×2 and button with Arduino Uno

ARDUINO PROGRAMMING CODE : DISPLAY DATA ON LCD 16X2 ON AN INPUT BY A SWITCH USING ARDUINO

#define del 1000
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//(1)
int buttonpin13 = 13, buttonpin12 = 12;
int buttonState13 = 0, buttonState12 = 0;

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

void loop() {
  //(2)
  buttonState12 = digitalRead(buttonpin12);
  buttonState13 = digitalRead(buttonpin13);
  // (3)
  if (buttonState12 == HIGH) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("HELLO ");
    delay(del);
  }
  // (4)
  else if (buttonState13 == HIGH) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("World");
    delay(del);
  }

}// END of Loop

PROGRAMMING CODE EXPLANATION

(1) Here we are defining two pins as input to arduino those are 12 and 13 and to store their states two variables buttonState12 and buttonState13 and initialize to 0.

(2) Then we will read the state of both input pins 12 and 13.

(3)  If pin 12 reads as high then clear the screen, set cursor position to (0,0) and print “HELLO” and provide a delay of 1 second (1000 millisecond) for the next input.

(4) If pin 13 reads as high then clear the screen, set cursor position to (0,0) and print “World” and provide a delay of 1 second (1000 millisecond) for the next input.

OUTPUT:

DISPLAY DATA ON LCD 16X2 ON AN INPUT BY A SWITCH USING ARDUINO
DISPLAY DATA ON INPUT ON LCD

READ NEXT
DISPLAY HINDI OR CUSTOM CHARACTER ON LCD 16×2 USING ARDUINO


 

Total Visits: 3524
5 1 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Segun Boronle
Segun Boronle
1 month ago

This is great, superb and a very good works. Please keep it up. I love it.

1
0
Would love your thoughts, please comment.x
()
x