/*
MSJ Researchers World
Date - 28th OCT 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
#include <Keypad.h>
// Define the number of rows and columns in the keypad
const byte ROWS = 4;
const byte COLS = 4;
// Define the keymap (as per your keypad layout)
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connect keypad rows and columns to Arduino pins
byte rowPins[ROWS] = {4, 5, 6, 7}; // Rows: R1, R2, R3, R4
byte colPins[COLS] = {8, 9, 10, 11}; // Columns: C1, C2, C3, C4
// Create an instance of the Keypad library
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600); // Initialize serial communication
}
void loop()
{
char key = keypad.getKey(); // Check for key press
if (key)
{ // If a key is pressed
Serial.print("Key Pressed: ");
Serial.println(key);
}
}