Arduino Keypad 4×4 Tutorial

Arduino and 4X4 Matrix Keypad


In this tutorial we will learn how to connect a keypad with arduino and get started.


After connecting as shown here we need to upload a code on our arduino.

Connecting keypad with aruduino digital pins:

Keypad Pin Connects to Arduino Pin

1                                          D9

2                                          D8

3                                          D7

4                                          D6

5                                          D5

6                                          D4

7                                          D3

8                                          D2


Adding the library :  

To add the library go to Skeetches –>>Include library–> Type the libray name “keypad” then press install. Heres how:

Here’s the  Code :

#include <Keypad.h>

const byte numRows= 4; //number of rows on the keypad

const byte numCols= 4; //number of columns on the keypad

char keymap[numRows][numCols]=


{‘1’, ‘2’, ‘3’, ‘A’},

{‘4’, ‘5’, ‘6’, ‘B’},

{‘7’, ‘8’, ‘9’, ‘C’},

{‘*’, ‘0’, ‘#’, ‘D’}


byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3

byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()




void loop()


char keypressed = myKeypad.getKey();

if (keypressed != NO_KEY)







FB Page

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s