Introduction
We have a 4×4 membrane keypad to interface today. These are the soft touch ones and work based on the matrix keypad configuration generally seen.
Project
The idea is to interface this with Arduino and whenver a key is pressed, we print the same on the serial console. We will use the Keypad library and provide the same characters that we see on the keypad as a two dimensional character array (matrix) to the library. Also note that we require 8 lines (4 rows and 4 cols) to interface this keypad. Since the idea is to check if there is a short between the lines we don’t need any supply of power or ground too.
In the keypad sensor, the first four pins from left to right are row-pins and the next four pins are column-pins.
Pin Configuration
Arduino | Sensor |
2 | col3 |
3 | col2 |
4 | col1 |
5 | col0 |
6 | row0 |
7 | row1 |
8 | row2 |
9 | row3 |
Circuit connections
Interfacing keypad with Arduino
Code
Requires Keypad Library : Download Link
#include <Keypad.h> const byte ROWS = 4; //four rows const byte COLS = 4; //three columns char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad byte colPins[COLS] = {5,4, 3, 2}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void setup(){ Serial.begin(9600); } void loop(){ char key = keypad.getKey(); if (key){ Serial.println(key); } }