In this blog, we will be discussing interfacing 4x4 Matrix Keypad with Arduino Uno.
Matrix keypad basically consists of push buttons.
At a particular instant, if we know which push button is pressed, we can say which character was given by the user.
# Module Data Sheet:
Working Current: 30mA
Working Voltage: 5-24V
# Pin-Out:
X1, X2, X3, X4 are rows.
Y1, Y2, Y3, Y4 are columns.
# Arduino Connection:
# Working:
The working is simple.
We know that at a time only one key will be pressed.
So we have to check which key is pressed at that given time.
There are 4 rows and 4 columns.
We will first make Row R1 high.
Then check whether C1, C2, C3 or C4 is high or not.
If not we will proceed to the next row.
For example...
Let's say we found C2 to be high when R3 was high.
=> The key (3,2) was pressed i.e. Key '8' was pressed.
This process will keep on repeating very fast.
# Arduino Code:
#include <Keypad.h>
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
// define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {10, 11, 12, 13}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // connect to the column pinouts of the keypad
// initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop()
{
char customKey = customKeypad.getKey();
if (customKey)
{
Serial.println(customKey);
}
}
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
// define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {10, 11, 12, 13}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // connect to the column pinouts of the keypad
// initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop()
{
char customKey = customKeypad.getKey();
if (customKey)
{
Serial.println(customKey);
}
}
# Applications:
1. To get the data from the user.
To download the code click here
Accha he pr 8 vala logic samaj nahiya aaya
ReplyDelete4x4 keypad...
Delete1 2 3 A
4 5 6 B
7 8 9 C
* 0 # D
Look at the 4x4 Keypad.
Its (3,2) element is '8'.
Good.
ReplyDelete