Arduino Library for DF Robot 16×2 LCD Keypad Shield


A few years ago, I purchased one of these 16×2 LCD and Keypad Arduino shields. There are quite a few of them around (including some clones?), but they are similar to this one from DF Robot:


I think I bought this one from eBay a few years ago, but nonetheless, the different ones around  are all based on the same circuit. I wrote my own Arduino Library for the keypad operation, and just wanted to share it with those who might find it useful.

There are some jumper wires soldered onto it. This isn’t how it came from the shop, but something I had to modify on the board due to compatibility issues with another shield. I don’t remember exactly what this was for, it was many years ago!

The buttons on the keypad, except for the reset switch, are all connected via a resistor divider to a single analog input pin. You can read what the key state is by reading the analog value at the pin, and comparing it to a set of known expected values.

Download Arduino Library

You can download the library over here:

To install, it simply copy the DFR_LCD_Keypad directory into the libraries/ directory in your Arduino installation. There is an example sketch to help you get started.

A note about the Pin 10 bug

Just one thing to mention, they all happen to have a flaw in the design, so don’t use pin 10 when using this shield. The library has functions to enable and disable the backlight. But in the design, a flaw exists, that when pin 10 is set to output, and set high, it could cause the IO pin of the MCU (the main Atmel chip) to deliver too much current (over the datasheet’s maximum rating) to the backlight LED. This may cause the over stressing of the MCU and may reduce its life, or maybe even blow it up.

  • To set the backlight on, set pin 10 as input.
  • To set the backlight off, set pin 10 as output, and immediately set output low (never high!)

For more information, there is discussion on the Arduino forums about this.