4×4 Membrane Keypad Interfacing with Arduino

This tutorial is about interfacing of 4×4 keypad interfacing with Arduino UNO. A 4×4 keypad can be constructed using 16 push button. The keypad is used in different applications like password protected security system, microwave oven, fax machines and in different digital and embedded system applications. For this, we should know how to arrange the push button in a matrix of rows and columns and it will need some soldering skills for designing it. We are using readymade 4×4 membrane keypad.

Arduino Keypad.h Library

For making this tutorial easy we are using arduino keypad.h(keypad h) library. Download the keypad.zip and add to arduino library. We are using CustomKeypad.pde code given in keypad.h library and modified according to our circuit. As we are already using the keypad library we are not developing any complex algorithm to scan the keypad keys. Here Arduino continuously monitors the rows and its columns. In this code when a key is pressed Arduino scan the key pressed and send the key value to the serial port and displayed to serial monitor.

Hardware Required

  • Arduino Uno
  • 4×4 Membrane Keypad

Keypad Arduino Connection

Connect the arduino and 4×4 keypad as given in the above wiring diagram. Make sure keypad pin is connected in correct order. This keypad has a pin no. written on its connector.

Arduino Keypad Circuit

While making circuit we prefer to use membrane keypad because it has a ready-made module so chances of running the project are good. Once you are comfortable with the code and internal circuit of the keypad you can design your own.

4×4 Keypad Arduino Code

In this keypad interfacing with Arduino, connect keypad to the arduino with a proper pin number. Define the keymap properly as mention in this programming code. Make all connection as give in this tutorial, if this work correctly then you can change according to your project.

/* Source || @file CustomKeypad.pde|| @version 1.0|| @author Alexander Brevig|| @contact alexanderbrevig@gmail.coms*/
/* #####  4x4 Membrane Keypad Arduino Interfacing  #####Arduino and Keypad ConnectionKeypad Pin    Arduino Pin   1      =>  Digital Pin 2   2      =>  Digital Pin 3   3      =>  Digital Pin 4   4      =>  Digital Pin 5   5      =>  Digital Pin 6   6      =>  Digital Pin 7   7      =>  Digital Pin 8   8      =>  Digital Pin 9*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
// Define the Keymap
char hexaKeys[ROWS][COLS] = {
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the Rows of the keypad pin 8, 7, 6, 5 respectively
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the Columns of the keypad pin 4, 3, 2, 1 respectively

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
void loop(){
  char customKey = customKeypad.getKey();
  if (customKey){
    Serial.println(customKey); // Send the pressed key value to the arduino serial monitor