16 X 2 LCD Keypad Shield for Arduino V2

From LinkSprite Playgound
Jump to: navigation, search

Introduction

We wanted to make it easier for people to get these LCD into their projects so we devised a shield that lets you control a 16x2 Character LCD backlight with a potentiometer AND 5 keypad pins using 6 digital pins on the Arduino!

This shield is perfect for when you want to build a stand-alone project with its own user interface. The 4 directional buttons plus select button allows basic control without having to attach a bulky computer.
  • Comes with a 16x2 green backlight LCD, negative display
  • Plug and play with any Arduino 'classic' - UNO, duemilanove, diecimilla, etc.
  • Uses 6 pins of Arduino to control LCD and A0 pin for 5 buttons.

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight, plug it straight in on top of your Arduino board or other project shields. The display is set behind the shield for a low profile fitment and nice look and we've included panel mounting screw holes in the corners.
It's great when you want to build a stand-alone project with its own user interface that doesn't require a computer attached to send commands to your Arduino.
Works perfectly in 4-bit mode with the "LiquidCrystal" library included with the Arduino IDE, allowing you to control the LCD with a total of just 6 digital I/O lines. We've deliberately picked D4-D9 so that it doesn't interfere with pins required by other popular products such as the Ethernet Shield and EtherTen, so you can stack this on top of other shields to give you a local display.
There are 5 buttons, and when press any combination of these buttons, each will give an unique value. That means that it is able to tell 32 different possibility.
The LCD backlight can be controlled for on/off by Arduino program, and the potentiometer can adjusts the contrast of the display.

SHD 1602V2.jpg

Features

  • 16x2 LCD using HD44780-compatible display module (black characters on green background).
  • •5 buttons on one analog input (A0). Any combination of the 5 buttons lead to 32 different key values.
  • LCD backlight with current limiting, brightness and on/off controllable by a adjustable potentiometer.
  • Recessed LCD, panel mount screw holes and button layout suitable for panel or cabinet mounting if desired.
  • Reset button.
  • Power supply smoothing capacitor.

Application Ideas

test code
/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7/11/2014
 by Jingjing Yi, LinkSprite
 
 This example code is in the public domain.
 
http://www.arduino.cc/en/Tutorial/LiquidCrystal
 
 */
 
#define Rbase ((unsigned long)47)
#define Rup ((unsigned long)75)  
#define Rdown  ((unsigned long)62) 
#define Rleft  ((unsigned long)47)  
#define Rright ((unsigned long)39)  
#define Rselect  ((unsigned long)28) 
 
// include the library code:
#include <LiquidCrystal.h>
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
int sensorValue ;
int KeyTable[31];
 
void GenerateKeyTable(int vcc,int* array)
{
  float resistor;
 
//////////////1key//////////////////////  
  resistor = ((float)Rup)/(Rbase + Rup);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rdown)/(Rbase + Rdown);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft)/(Rbase + Rleft);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rright)/(Rbase + Rright);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rselect)/(Rbase + Rselect);
  *array++ = resistor*vcc;
 
//////////////2 key/////////////////////////
  resistor = ((float)Rup)*Rdown/(Rup+Rdown);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup)*Rright/(Rup+Rright);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup)*Rleft/(Rup+Rleft);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup)*Rselect/(Rup+Rselect);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rdown)*Rleft/(Rdown+Rleft);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rdown)*Rright/(Rdown+Rright);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rdown)*Rselect/(Rdown+Rselect);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rright)*Rleft/(Rright+Rleft);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rright)*Rselect/(Rright+Rselect);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft)*Rselect/(Rleft+Rselect);
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  ///////////////3 key//////////////////////
  resistor = ((float)Rup*Rdown*Rright/(Rup*Rright + Rdown*Rright + Rup*Rdown));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup*Rdown*Rleft/(Rup*Rleft + Rdown*Rleft + Rup*Rdown));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup*Rdown*Rselect/(Rup*Rselect + Rdown*Rselect + Rup*Rdown));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft*Rdown*Rright/(Rleft*Rright + Rdown*Rright + Rleft*Rdown));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft*Rdown*Rselect/(Rleft*Rselect + Rdown*Rselect + Rleft*Rdown));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft*Rup*Rright/(Rleft*Rright + Rup*Rright + Rleft*Rup));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rleft*Rup*Rselect/(Rleft*Rselect + Rup*Rselect + Rleft*Rup));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup*Rright*Rselect/(Rup*Rright + Rright*Rselect + Rup*Rselect));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rdown*Rright*Rselect/(Rdown*Rright + Rright*Rselect + Rdown*Rselect));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
 resistor = ((float)Rleft*Rright*Rselect/(Rleft*Rright + Rright*Rselect + Rleft*Rselect));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  ////////////////4 key///////////////////////////
  resistor = ((float)Rup*Rdown*Rleft*Rright/(Rdown*Rleft*Rright + Rup*Rleft*Rright + Rup*Rdown*Rright + Rup*Rdown*Rleft));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup*Rdown*Rleft*Rselect/(Rdown*Rleft*Rselect + Rup*Rleft*Rselect + Rup*Rdown*Rselect + Rup*Rdown*Rleft));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rup*Rselect*Rleft*Rright/(Rselect*Rleft*Rright + Rup*Rleft*Rright + Rup*Rselect*Rright + Rup*Rselect*Rleft));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rselect*Rdown*Rleft*Rright/(Rdown*Rleft*Rright + Rselect*Rleft*Rright + Rselect*Rdown*Rright + Rselect*Rdown*Rleft));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  resistor = ((float)Rselect*Rdown*Rup*Rright/(Rdown*Rup*Rright + Rselect*Rup*Rright + Rselect*Rdown*Rright + Rselect*Rdown*Rup));
  resistor = resistor/(resistor+Rbase);
  *array++ = resistor*vcc;
 
  /////////////////5 key//////////////////////////
  resistor = ((float)Rup*Rdown*Rleft*Rright*Rselect/(Rdown*Rleft*Rright*Rselect + Rup*Rleft*Rright*Rselect + Rup*Rdown*Rright*Rselect + Rup*Rdown*Rleft*Rselect + Rup*Rdown*Rleft*Rright));
  resistor = resistor/(resistor+Rbase);
  *array = resistor*vcc;
}
 
unsigned char GetKey(int value)
{
  char tmpChar;
  unsigned int Rst;
 
  tmpChar = 0;
  do{
      if(value > KeyTable[tmpChar]) Rst = value - KeyTable[tmpChar];
      else  Rst = KeyTable[tmpChar] - value;
     tmpChar ++;
  }while(Rst > 1);
 
  return tmpChar--;
 
}
 
void setup() 
{
  int tmpInt;
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  sensorValue  = 1023;
   Serial.begin(9600); 
 
   GenerateKeyTable(analogRead(A0),KeyTable);
   for(tmpInt = 0;tmpInt <31;tmpInt++)
   {
     Serial.println(KeyTable[tmpInt]);
   }
}
 
void loop() 
{
  unsigned char key;
 
  if(sensorValue != analogRead(A0))
  {
     sensorValue = analogRead(A0);
     lcd.setCursor(0, 1);
     lcd.print(sensorValue);   
      key = GetKey(sensorValue);
      if(key < 31)
      {
        lcd.print("---");
        lcd.print(key);
        lcd.print(' ');
      }
      else  lcd.print("        ");
 
  }
}

Cautions

The warnings and wrong operations possible cause dangerous.

Schematic

  • Schematic in PDF
    • By using a R10 of smaller value, the brightness of backlight can be increased.

How to buy

See Also

Other related products and resources.

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are licensed under GPL/LGPL, see source code files for details.

Navigation menu

Personal tools

Namespaces

Variants

More

  • This page was last modified on 14 April 2017, at 09:55.
  • This page has been accessed 28,809 times.
  • Powered by MediaWiki