How to use simple keypad with Arduino

Submitted by CAAadmin on Sun, 07/24/2016 - 07:12

In this example, we will use Simple Keypad to send the data to arduino when someone presses the keys

Connect keypad leads to 9,8,7,6 ,5,4,3,2 of arduino Digital IO pins (Right Most pin to Arduino D I/O 2 and so on)

In this case, the variable key1 returns the value equivalent to the key pressed. this variable can be used to sent the values to VB interface (which will be explained in next article)

These codes are tried and tested - without any errors, if any error occurs please report it under comments section.

Arduino Code

#include <Keypad.h>
const byte numRows= 4;
const byte numCols= 4;
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};
byte colPins[numCols]= {5,4,3,2};
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup()

void loop()
char key1 = myKeypad.getKey();
if ( key1 != NO_KEY)
Serial.print( key1);

Arduino keypad library files can be downloaded at


arduino keypad