#include <Keypad.h>
#include <LiquidCrystal.h>
// Define LCD pins (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
// Keypad setup
const byte ROWS = 4; // Number of rows
const byte COLS = 4; // Number of columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27}; // Row pins connected to keypad
byte colPins[COLS] = {26, 25, 33, 32}; // Column pins connected to keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Initialize LCD
lcd.begin(16, 2); // 16 columns, 2 rows
lcd.print("Keypad Ready"); // Display initialization message
delay(2000); // Wait for 2 seconds
lcd.clear();
}
void loop() {
// Check for key press
char key = keypad.getKey();
if (key) { // If a key is pressed
// Print the key to the Serial Monitor
Serial.print("Key Pressed: ");
Serial.println(key);
// Display the key on the LCD
lcd.clear();
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print("Key: ");
lcd.print(key);
}
delay(200); // Short delay for key press debounce
}