The 16x2 LCD Keypad Shield is an Arduino-compatible shield that combines a 16x2 character LCD screen with a built-in keypad for user input. This shield is commonly used for projects that require both visual feedback (displaying text, sensor readings, etc.) and user interaction (button presses to control or navigate through menus).
The 16x2 LCD Keypad Shield connects directly to the Arduino board's pins, and the typical pinout for the buttons and LCD might look like this:
Pin Description:-
VCC Power (+5V)
GND Ground
VO LCD Contrast
RS Register Select (LCD)
RW Read/Write (LCD)
E Enable (LCD)
D0-D3 Data pins (LCD)
D4-D7 Data pins (LCD)
A0 Up button
A1 Down button
A2 Left button
A3 Right button
A4 Select button
The buttons are typically connected to the analog pins A0 to A4, and the shield handles reading the button states by reading the voltage at these pins, which changes based on which button is pressed.
Here’s a simple example code to get started with the 16x2 LCD Keypad Shield, where the LCD displays different messages based on button presses.
#include <LiquidCrystal.h> // Initialize the LCD (RS, E, D4, D5, D6, D7 pins) LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Button pin definitions const int buttonPinUp = A0; const int buttonPinDown = A1; const int buttonPinLeft = A2; const int buttonPinRight = A3; const int buttonPinSelect = A4; void setup() { // Start LCD and set up button pins lcd.begin(16, 2); // 16 columns and 2 rows pinMode(buttonPinUp, INPUT); pinMode(buttonPinDown, INPUT); pinMode(buttonPinLeft, INPUT); pinMode(buttonPinRight, INPUT); pinMode(buttonPinSelect, INPUT); // Display an initial message on the LCD lcd.setCursor(0, 0); lcd.print("Welcome!"); } void loop() { // Read the button states int upState = analogRead(buttonPinUp); int downState = analogRead(buttonPinDown); int leftState = analogRead(buttonPinLeft); int rightState = analogRead(buttonPinRight); int selectState = analogRead(buttonPinSelect); // Clear the LCD screen and display a new message based on button press lcd.setCursor(0, 1); // Move cursor to the second line if (upState < 100) { lcd.clear(); lcd.print("Up Button Pressed"); } else if (downState < 100) { lcd.clear(); lcd.print("Down Button Pressed"); } else if (leftState < 100) { lcd.clear(); lcd.print("Left Button Pressed"); } else if (rightState < 100) { lcd.clear(); lcd.print("Right Button Pressed"); } else if (selectState < 100) { lcd.clear(); lcd.print("Select Button Pressed"); } else { lcd.clear(); lcd.print("Waiting..."); } delay(100); // Small delay to debounce button presses }
Origin:- China
Brand:- Generic