Copyright: www.nuelectronics.com
New Ideas - New Projects - New Electronics


LCD Keypad shield on Arduino

Project note — LCD Keypad shield V1.0

1. Schematic

The LCD Keypad shield is developed for Arduino compatible boards, to provide a user-friendly interface that allows users to go through the menu, make selections etc. It consists of a 1602 white character blue backlight LCD and 5 pushbuttons that form a joystick-style keypad.

LCD Keypad V1.0 Schematic

Fig 1. LCD Keypad Schematic

2. LCD Interface

The LCD interaface uses HD44780D 4-bit compatible interface. In order to preserve the SPI interface for future use, a different set of IO pins is used. The following diagram shows the IO pins used to drive the LCD, you can modify the original 4bit LCD libaray [download here] or you can download the modified 4-bit LCD library [download here] .

LCD interface
Fig 2. LCD Interface
int USING_RW = false;

//RS, RW and Enable can be set to whatever you like

int RS = 8;

int RW = 11;

int Enable = 9;

//DB should be an unseparated group of pins 

int DB[] = {4, 5, 6, 7}; //wire these to DB4~7 on LCD. 

List 1. Code example — modified pin definition in 4Bit LCD library

3. Keypad Interface

The joystick style keypad consists of 5 keys — select, up, right, down and left. To save the digital IO pins, the keypad interface only uses one ADC channel. The key value is read through a 5 stage voltage divider as shown below.

When a key is pressed, the ADC reads the voltage value through the voltage divider; the the voltage value is compared to the voltage threshold values stored in an array to identify which key is pressed.

Keypad Interface
Fig 3. Joystick style Keypad, uses ONE ADC channel
 int adc_key_val[5] ={30, 150, 360, 535, 760 };

int NUM_KEYS = 5;

....

void loop() 

{ adc_key_in = analogRead(0); // read the value from the

sensor digitalWrite(13, HIGH); 

key = get_key(adc_key_in); // convert into key press 

if (key != oldkey) // if keypress is detected {

delay(50); // wait for debounce time 

adc_key_in = analogRead(0); //read the value from the sensor

key = get_key(adc_key_in); // convert into key press

 if (key != oldkey) { 

oldkey = key; 

if (key >=0){

lcd.cursorTo(2, 0); //line=2, x=0 

lcd.printIn(msgs[key]); 

} 

} 

}

digitalWrite(13, LOW); }
List 2. Code example — reading key values from the loop()

4. Examples

Two exmaples for LCD keypad shield are included in the midified LCD 4-bit library [download here]

  • Example 1 — Joystick keypad test routine, keypress shown on the LCD screen
  • Example 2 — Temperature measurenemt, using prototype shield & LCD keypad shield

lcd temperature measurement
Fig 4. Temperature measurement using LCD keypad shield

5. Links & Downloads

Tags: , , , , ,

Leave a Reply



Your IP Address is: 38.107.191.111
Copyright © 2010 nuelectronics. Powered by Zen Cart