Display data on LCD 16×2 on an input by a switch using Arduino

In this program we will see how to print different string 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 arduino those are 12 and 13 and to store their states two variables buttonState12 and buttonState13 and initialize to 0.

Whenever any button get pressed a different message will going to display on 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 read as high then clear the screen set cursor position to (0,0) and print “HELLO” and provide delay of 1 second (1000 millisecond) for the next input.

(4) If pin 13 read as high then clear the screen set cursor position to (0,0) and print “World” and provide 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: 1577
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Translate »
0
Would love your thoughts, please comment.x
()
x