Display data on LCD 16×2 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);
  delay(50);
  // (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);
  }
  // (5)
  else {
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
  }

}// 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.

(5) If both pins 12 and 13 read as LOW then set the cursor position to (0,0) and print “Press a Button.

OUTPUT:

DISPLAY DATA ON INPUT ON LCD


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


 

5 3 votes
Article Rating
Subscribe
Notify of
guest
10 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Segun Boronle
Segun Boronle
4 years ago

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

Imam Musthofa
Imam Musthofa
3 years ago

#ask
Good evening, what if:
5 buttons, arduino Uno, LCD16x2.
Button 1 is pressed, the lcd displays “sw1 pressed”. The lcd release button appears “standby”.
Button 2 is pressed, the lcd displays “sw2 pressed”. The lcd release button appears “standby”.
Etc. up to five buttons.
How do you make the five buttons press the same time, the LCD shows “sw1 pressed”, “sw2 pressed”, etc. alternately ?

Mahesh
Mahesh
3 years ago

Hello I want an answer

Bipin kishan
Bipin kishan
2 years ago

Can u give me answer for embeded programing for lcd display no. For dialpad…like any no. Pressed it should display on lcd like phone…but without using keyboard matrix…only using switches…

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