Tuesday, March 5, 2013

Using the 4x4 Universal 16 Key Keypad for Arduino with a Maple Mini

The listings at Amazon and other online vendors show this inexpensive membrane keypad as "4x4 Universial 16 Key Switch Keypad Keyboard For Arduino." There was no documentation for the product, nor were there any links from Amazon. The post about this on my Arduino/Netduino blog has proven very popular, so I wanted to see if I could get it to work with my Maple Mini. I have found that it and the Arduino Keypad library work very well with the Maple Mini with just a couple small changes.

The arrangement of the keys is

1 2 3 A 
4 5 6 B 
7 8 9 C 
* 0 # D 


There is a ribbon with 8 wires running from the bottom of the keypad. With the keypad face upand the connector ribbon pointing downward, the wires connect in sequence from left to right to Maple Mini pins 0 - 7. 

Keypad Library

The Arduino Keypad library is available from the Arduino Playground. [Note: Ver. 3.0 of the Keypad library works, but 3.1 doesn't.]  The library requires only one small change in the Keypad.h file:

Change line 75 from 

virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); }


virtual void pin_mode(byte pinNum, WiringPinMode mode) { pinMode(pinNum, mode); }

With that change made, the following sample code prints the key pressed to the SerialUSB console.


#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {0,1,2,3}; //connect to row pinouts 
byte colPins[COLS] = {4,5,6,7}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){


  1. Hi Brad. I had to add a WiringPinMode cast to the scanKeys() on Keypad.cpp so it could compile. Still haven't got it to work properly though. Thanks for the post :)

    1. Hi Jose -

      I tried to find version 3.0 of the Arduino Keypad library (rather than 3.1), but I couldn't find a copy. The Arduino Playground link looks like it should get you ver. 3.0, but it downloads ver. 3.1. I have put a copy of Keypad 3.0 in my GitHub repository at https://github.com/bberkland/MapleMini_Keypad. It contains the very minor change mentioned in my posting above.

  2. Hi Jose -

    It looks like I had an older version of the Keypad library (3.0). I, too, find that the current version (3.1) doesn't compile in the Maple IDE.

  3. This doesn't appear to work if you are using timer 2 for some reason but timer 3 (the only one I tried) appears to be OK. Strange as the library doesn't look like it uses any of the timers.

    1. Hi Mike - Thanks for passing this along. I hadn't run into this in my application, but it is good to know.

  4. This comment has been removed by a blog administrator.