LCD & Keypad Shield Quickstart Guide using arduino

The 16×2 LCD And Keypad Shield is very simple to use because it’s fully compatible with the Arduino “LiquidCrystal” library. You can initialise the LCD and display messages on it with just a few lines of code, but it also gives you the flexibility to do more advanced projects such as display menu items and select them using the buttons.

Power Requirements

The LCD & Keypad Shield requires a good 5V power supply to ensure the backlight fully illuminates and the display contrast is high, and if you power your Arduino from USB with the LCD Shield attached you may experience a voltage drop over the USB cable. If you have trouble with display contrast or backlight brightness, try attaching a power supply of around 7 to 9Vdc to the 2.1mm DC jack on the Arduino. A typical symptom in an undervoltage situation is that one line of the LCD will show pale rectangles in place of the characters, and the other line will show nothing at all. The Arduino may even continue running normally because it’s quite happy at just 4V or so, but the LCD & Keypad Shield won’t function.

LCD & Keypad Shield Quickstart Guide

Library Requirements

All the hard work of interfacing with the LCD Shield is handled by the LiquidCrystal library, which is included as part of the official Arduino distribution. You can check whether you have it installed by starting up the IDE and looking under Files -> Examples -> LiquidCrystal. If it exists, you’re good to go.

Minimal Display Example

To start up the LCD and display a message, open a new sketch in the Arduino IDE and paste in the following code:

#include <Wire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

void setup(){  lcd.begin(16, 2);  lcd.print(“hello, world!”);}

void loop(){    // your main loop code here…}

Reading The Buttons

The LCD Shield includes 5 buttons designed for use as navigational or control input. The buttons are arranged in a handy pattern and referred to as UP, DOWN, LEFT, RIGHT, and SELECT, but of course it’s totally up to your sketch to decide what to do when any particular button is pressed.
All the buttons are connected to a single analog input, A0, using a chain of resistors that causes a different reference voltage to be applied to A0 depending on which button is pressed. This section of the shield schematic shows the input buttons and associated resistors:
As you can see, if no button is being pressed the voltage on A0 will be pulled all the way up to 5V by the 2K resistor called R6. In that situation none of the other resistors have any effect at all, and the analog reading on A0 will be hard on the upper limit of 1023. Therefore if you perform an analogRead() call on A0 and it returns 1023 (or any value above about 1000) you know that no buttons are being pressed.
Now consider what happens if the “DOWN” button is pressed. Now A0 is being presented with a voltage that is divided between the 2K resistor that is trying to pull it up to 5V, and the 330R and 620R resistors in series (totaling 950R) that are trying to pull it down to 0V. The voltage presented to A0 in that case is about 1.61V, which means if you perform an analogRead() on A0 it will return a value of about 329. So if you read a value of about 329 from A0 you know the “DOWN” button is being pressed.
The same principle applies for the other buttons, with the voltages and equivalent analogRead() values shown on the schematic above.
This is a neat way to provide a whole set of input buttons while only using up one of the I/O pins on your Arduino, leaving more pins free for use in your project.

Complex Example

The extensive example below combines a number of techniques to demonstrate how to show messages on the LCD, read from the buttons, and change the display message depending on which buttons are pressed.

Example code for the Freetronics LCD & Keypad Shield:

by Marc Alexander, 7 September 2011
This example code is in the public domain.

This program demonstrates button detection, LCD text/number printing,
and LCD backlight control on the Freetronics LCD & Keypad Shield, connected to an Arduino board.

After powerup, the screen looks like this:

|Freetronics 16×2|
|Btn:          0 | <- This time value counts up the number of seconds since reset (overflows at 99)

When a button is pressed, a label appears for it:

|Freetronics 16×2|
|Btn:RIGHT     0 |
LCD & Keypad Shield Quickstart Guide
SELECT-FLASH makes the LCD backlight flash off and on when held down.

Pins used by LCD & Keypad Shield:

A0: Buttons, analog input from voltage ladder
D4: LCD bit 4
D5: LCD bit 5
D6: LCD bit 6
D7: LCD bit 7
D3: LCD Backlight (high = on, also has pullup high so default is on)

ADC voltages for the 5 buttons on analog input pin A0:

RIGHT:  0.00V :   0 @ 8bit ;   0 @ 10 bit
UP:     0.71V :  36 @ 8bit ; 145 @ 10 bit
DOWN:   1.61V :  82 @ 8bit ; 329 @ 10 bit
LEFT:   2.47V : 126 @ 8bit ; 505 @ 10 bit
SELECT: 3.62V : 185 @ 8bit ; 741 @ 10 bit*/


For more detail: LCD & Keypad Shield Quickstart Guide

This Post / Project can also be found using search terms:

  • arduino lcd keypad shield project
Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Arduino Esplora Light Calibrator
Arduino Esplora Light Calibrator

This sketch shows you how to read and calibrate the Esplora's light sensor. Because light levels vary from one location...

Scroll to top