Go Down

Topic: 1602 LCD with Keypad / Need data sheet or book (Read 2636 times) previous topic - next topic


Hello All:

This is my first post. Just getting started. I purchased the 1602 2x16 LCD with keypad through ebay at:


and I was impressed that it just plugged into the Arduino Uno and worked with a sketch I downloaded from another ebay seller. Here is the sketch:

  The circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD BL pin to digital pin 10
* KEY pin to analogl pin 0

#include <LiquidCrystal.h>

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

char msgs[5][16] = {
  "Right Key OK ",
  "Up Key OK    ",               
  "Down Key OK  ",
  "Left Key OK  ",
  "Select Key OK" };

int adc_key_val[5] = {50, 200, 400, 600, 800 };
int NUM_KEYS = 5;
int adc_key_in;
int key = -1;
int oldkey = -1;

void setup()
  lcd.begin(16, 2);
  lcd.print("Shield key test:");

void loop()
  adc_key_in = analogRead(0);      // read the value from the sensor
  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) {   
      lcd.setCursor(0, 1);
      oldkey = key;
      if (key >=0) {


// Convert ADC value to key number
int get_key(unsigned int input)
    int k;
    for (k = 0; k < NUM_KEYS; k++) {
      if (input < adc_key_val[k])
        return k;
    if (k >= NUM_KEYS)             // No valid key pressed
      k = -1;

    return k;

But now I need to write my own sketch converting those keys that interact with the display and a register or two in the Arduino. I need reference material showing me how to convert a key to a value that I can place in a register. I see from this sketch that the pressed key creates an analog voltage which is converted to a message. I need it to increment a stored number from 1 to 99.

I simply want to create a timer that the user can punch in a value from 01 to 99 (for 1 to 99 minutes) and when an input pin goes high this set number of minutes starts counting down and when it reaches zero to set a digital output pin high. Pretty simple, but apparently the coding is not so simple. I'm ready to tackle it but I suppose I need some good reference material to go by and also to go buy. I don't find the Arduino reference as very complete. I see the delay function shows that you can delay in miliseconds but it does not state a limit. I read on this forum that delay() works to 30K. Well, that's 30 seconds. I suppose I can use two of those to make a minute, and I can use 198 of them to make 99 minutes. Right? I don't need the Arduino to do anything else while it's waiting. Of course if the mills() instruction might do the trick too but again the reference is not clear to me. I'd love some help with this even if it is just pointing me to a good book to purchase. A data sheet on the 1602 would be good but I notice all the ebay sellers do not provide a darn thing. Thanks in advance for any help you all might provide me. Hope I can do the favor back some day.


For the LCD look at the LiquidCrystal library on the arduino main site.

If you want example code to hack, look at the libraries at the location in my signature block. I have a small library that handles the buttons on an LCD and also a sketch to implement a countdown timer. Not exactly the same as your requiremens but probably a good starting point.


It's a DF Robot LCD Keypad Shield, or one of many clones, and everything you need is on teh DF Robot site

First link if you use Google



Please use the # key in the editor to enclose your code inside code tags

Go Up