A keypad is an input device consisting of a set of buttons arranged in a block or 'pad' which bear digits, symbols, or alphabetical letters. It is used to input data into a system, often for security or user interface purposes. Keypads are commonly found in devices such as telephones, calculators, ATMs, and access control systems.
Parameter | Value |
---|---|
Operating Voltage | 3.3V - 5V |
Operating Current | 10mA - 20mA |
Number of Keys | 12 (3x4) or 16 (4x4) |
Keypad Type | Matrix |
Contact Resistance | < 100Ω |
Insulation Resistance | > 100MΩ |
Operating Temperature | -20°C to +50°C |
Pin Number | Pin Name | Description |
---|---|---|
1 | R1 | Row 1 |
2 | R2 | Row 2 |
3 | R3 | Row 3 |
4 | R4 | Row 4 (if applicable) |
5 | C1 | Column 1 |
6 | C2 | Column 2 |
7 | C3 | Column 3 |
8 | C4 | Column 4 (if applicable) |
Pin Number | Pin Name | Description |
---|---|---|
1 | R1 | Row 1 |
2 | R2 | Row 2 |
3 | R3 | Row 3 |
4 | R4 | Row 4 |
5 | C1 | Column 1 |
6 | C2 | Column 2 |
7 | C3 | Column 3 |
8 | C4 | Column 4 |
Connect the Keypad to the Microcontroller:
Initialize the Keypad Library:
Read Key Presses:
#include <Keypad.h>
// Define the size of the keypad
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, ROW3 to these Arduino pins
byte rowPins[ROWS] = {9, 8, 7, 6};
// Connect keypad COL0, COL1, COL2, COL3 to these Arduino pins
byte colPins[COLS] = {5, 4, 3, 2};
// Create the Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
char key = keypad.getKey(); // Get the key pressed
if (key) { // If a key is pressed
Serial.println(key); // Print the key to the serial monitor
}
}
No Key Press Detected:
Multiple Key Presses Detected:
Incorrect Key Detected:
By following this documentation, users should be able to effectively integrate and utilize a keypad in their electronic projects, whether for simple input tasks or more complex user interfaces.