Arduino - LCD Keypad Shield

The Arduino LCD Keypad Shield is a useful module that combines a 16x2 LCD display with six push buttons (Right, Up, Down, Left, Select, and Reset) for user interaction. This tutorial will guide you through setting up and programming this shield using an Arduino board.

Hardware Required

1×Official Arduino Uno
1×Alternatively, DIYables ATMEGA328P Development Board
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×LCD Keypad Shield
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

About LCD Keypad Shield

The LCD Keypad Shield has:

  • A 16x2 LCD controlled by the LiquidCrystal library
  • 5 push buttons connected to a single analog pin (A0)
  • A reset button to restart the Arduino
  • A potentiometer to adjust LCD contrast

Pinout

LCD Keypad Shield Pinout

The table below illustrates the pin mapping between the LCD Keypad Shield and the Arduino when the shield is stacked onto the board.

Shield Pin Function Arduino Pin
DB4 Data 4
DB5 Data 5
DB6 Data 6
DB7 Data 7
RS Register Select 8
E Enable 9
Analog A0 Button Input A0

Reset Button

The shield includes a reset button, which is connected to the Arduino's reset pin. Pressing this button will restart the Arduino, resetting the program.

Potentiometer

The shield features a small potentiometer near the LCD display. This is used to adjust the contrast of the LCD screen. If the text is not visible, try turning the potentiometer slowly to improve visibility.

Wiring Diagram

Simply plug the LCD Keypad Shield onto your Arduino board. The pins will align automatically.

Arduino LCD Keypad Shield Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Arduino Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-lcd-keypad-shield */ #include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); void setup() { Serial.begin(9600); Serial.println("Started"); // Debugging lcd.begin(16, 2); lcd.print("Hello!"); delay(3000); } void loop() { int key = analogRead(A0); //Serial.println(key); // Debugging lcd.clear(); if (key < 50) lcd.print("RIGHT"); else if (key < 200) lcd.print("UP"); else if (key < 400) lcd.print("DOWN"); else if (key < 600) lcd.print("LEFT"); else if (key < 800) lcd.print("SELECT"); else if (key < 1000) lcd.print("RST"); // If RST has a value, add here else lcd.print("Press key!"); delay(200); }

Quick Steps

  • Stack the LCD Keypad Shield on Arduino
  • Connect Arduino to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • Copy the above code and paste it to the Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Press each button on the shield one by one and check if the corresponding text appears on the LCD.
  • Check out the result on LCD display

If the LCD remains blank, ensure:

  • The shield is properly connected to the Arduino.
  • The potentiometer is adjusted for proper contrast.
  • The uploaded code matches the example provided.
  • The Arduino board is powered correctly.

Following these steps should help you get your Arduino LCD Keypad Shield working properly!

For more functions on controlling the LCD display, please refer to this Arduino LiquidCrystal LCD tutorial.

To improve modularity and readability, we reorganize the previous code into separate functions:

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-lcd-keypad-shield */ #include <LiquidCrystal.h> // Define constants for key representations const int KEY_RIGHT = 0; const int KEY_UP = 1; const int KEY_DOWN = 2; const int KEY_LEFT = 3; const int KEY_SELECT = 4; const int KEY_NONE = 5; LiquidCrystal lcd(8, 9, 4, 5, 6, 7); int getKey() { int analogValue = analogRead(A0); //Serial.println(analogValue); // Debugging if (analogValue < 50) return KEY_RIGHT; else if (analogValue < 200) return KEY_UP; else if (analogValue < 400) return KEY_DOWN; else if (analogValue < 600) return KEY_LEFT; else if (analogValue < 800) return KEY_SELECT; else return KEY_NONE; } void setup() { Serial.begin(9600); Serial.println("Started"); // Debugging lcd.begin(16, 2); lcd.print("Hello!"); delay(3000); } void loop() { lcd.clear(); int key = getKey(); switch (key) { case KEY_RIGHT: lcd.print("RIGHT"); break; case KEY_UP: lcd.print("UP"); break; case KEY_DOWN: lcd.print("DOWN"); break; case KEY_LEFT: lcd.print("LEFT"); break; case KEY_SELECT: lcd.print("SELECT"); break; default: lcd.print("Press key!"); break; } delay(200); }

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES