Recently I’ve got an Arduino LCD keypad shield. Haven’t decided yet where will it be used. But why not to plug it to Arduino board and see it working. The shield was initially introduced by DFRobot who has some cool open-source stuff including robotics related.
This LCD keypad shield is a cheap and convenient solution for adding 2×16 LCD and five push buttons (+1 reset) to Arduino design. LCD here is interfaced using 4-bit mode and occupies 4 (D4), 5 (D5), 6(D6), 7(D7), 8(RS), 9(E) and ten digital pins. Pin 10 is used to control LCD backlight through transistor key. All five buttons are connected to single Analog pin 0 using a resistor-based voltage divider. This lets us keep other pins for general use. The shield is designed to work with 5V based boards.
Since Arduino already has an LCD library implemented in the core, it is easy to start using it right away by initializing LCD with a simple command:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
But since there is a dedicated library for this shield things become even simpler. All you need is to download one of the libraries. I suggest using LCDKeypad.zip which simplifies usage of LCD a bit and also implements key reading.
If we look at keys connected to analog pin 0 we will see that when any of the keys is pressed we get a simple voltage divider. With all known resistor values and supply voltage we can calculate the voltage drop, and so ADC reading for each key. In the library, there are ADC ranges used to minimize error due to the variation of resistor values. Actually, you even don’t need a library for that since there is only one loop used to test the button. Let’s build a simple program where we would be able to adjust LCD backlight brightness:
As you can see backlight of LCD is changed by simply sending PWM signal to pin 10 of Arduino. The minimum value is 0 which means the backlight of OFF and the maximum is 255 when LEDs are driven with a constant voltage. Here is the result of PWM set to 10 and 255 respectively:
The last thing I would like to mention that this shield has an awkward Reset button position. It is placed next to five user buttons that can be used as menu navigation keys and other purposes. The reset button is aligned dangerously close to user keys and can be accidentally pressed during operation.
Probably it would be better to place it anywhere else on PCB. Overall this is a great and robust shield which works fluently. It is up to you whether to use a library or achieve the same result with standard Arduino libraries. It shouldn’t be a problem to put this stacked assembly into a compact enclosure.