#include <Keypad.h>
const uint8_t ROWS = 4; // Number of rows
const uint8_t COLS = 4; // Number of columns
// Define the keymap for the keypad
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// Define the row and column pin connections
uint8_t rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pins of the keypad
uint8_t colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pins of the keypad
// Create the Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600); // Start the serial communication
}
void loop() {
char key = keypad.getKey(); // Read a key from the keypad
if (key != NO_KEY) { // Check if a key is pressed
Serial.println(key); // Print the key to the Serial Monitor
}
}