A 4×4 keypad is an input device consisting of 16 buttons arranged in a 4x4 matrix. It is widely used in electronic projects and commercial products for entering numeric, alphabetic, and other symbol data. Common applications include security systems, telephone dial pads, and electronic door locks.
Pin Number | Description |
---|---|
1 | Row 1 |
2 | Row 2 |
3 | Row 3 |
4 | Row 4 |
5 | Column 1 |
6 | Column 2 |
7 | Column 3 |
8 | Column 4 |
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {9, 8, 7, 6};
// Connect keypad COL0, COL1, COL2 and COL3 to these Arduino pins.
byte colPins[COLS] = {5, 4, 3, 2};
// Create 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);
}
}
Q: Can I use the keypad with a 3.3V system? A: Yes, but ensure the keypad is rated for 3.3V operation.
Q: How can I clean the keypad? A: Use a soft, damp cloth. Avoid harsh chemicals and do not submerge the keypad.
Q: What is the maximum length of wire I can use to connect the keypad? A: It depends on the wire gauge and the environment, but keep it as short as possible to avoid signal degradation.
Remember to always power off your system before making any changes to the connections to prevent damage to the keypad or the microcontroller.