Notes About Working with Various Arduino & Netduino Microcontroller Boards

Friday, October 26, 2012

Using the 4x4 Universal 16 Key Keypad for Arduino

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. Here are my notes on how to connect and test this keypad.

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 up, the wires connect in sequence from left to right to Arduino digital pins 2 - 9. Don't use digital pins 0 and 1 on the Arduino Uno, since they are used for serial communication.

The Arduino Keypad library is available from the Arduino Playground.

Note: I also have an I2C version of this example (01/24/13).

Note: I have posted a C/Linux example of using this keypad with an Arduino Galileo (running at the Galileo's command line rather than as an Arduino sketch). (06/04/2015)

 The following code will allow you to test the keypad. As each key is pressed, the corresponding character should appear on a separate line in the Arduino IDE's serial console.

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {2,3,4,5}; //connect to row pinouts 
byte colPins[COLS] = {6,7,8,9}; //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. Thanks this has helped me a lot

    1. Hi Bibsy -

      I'm glad you found this post useful. I have noticed that it is one of the most frequently read posts.

  2. Very useful post. Found the membrane keypad on ebay, and seems like an order of magnitude less expensive than conventional EM keypad, and was wondering how to use it, when I found your post.

    Something on the specifications section on the ebay ad, caught my attention, where it says:

    Circuit Rating: 35V (DC), 100mA, 1W

    I am guessing the 35VDC is the max terminal voltage that can be applied to the scan lines, and 100mA is the max current draw during scan, but it'd happily scan with 5VDC typical from Android, right ?

    1. Hi Banibrata -

      I believe that you are correct. I've got 2 that I purchased from Amazon ( and I have used them with 3.3V and 5V (Arduino Due at 3.3V & Arduino Uno R3 at 5V).

  3. Brad, awesome posting. I bought the Keypad and of course forgot about implementation/libraries. I wonder if the keypad can be used with a shift register and reduce the the pin requirements from 8 to just 2?

    1. Hi Jeff -

      I also have a post that shows how to use this keypad with the PCF8574P I/O expander. This chip then connects to the Arduino using I2C, and thus takes fewer pins. You can find the post at at the "i2C Version" link above or at

  4. Hi Brad, thanks so much for this post and some of your others (SainSmart 12864 Graphic LCD specifically). I appreciate the code snippets, they have been a big help. I'm hoping to get the screen and the keypad working together.

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

  6. to input password and display in the serial display???

  7. Hey Brad
    Do you know how to function a 'backspace' and 'enter' on a 4x4 matrix keypad?

  8. How can you enter to where multiple characters will appear, creating a number like "640" or "72"?