4x4 Matrix Keypad Experiment

4x4 Matrix Keypad Input Experiment

Introduction

A 4x4 matrix keypad is an input device that consists of 16 buttons arranged in a 4-row by 4-column grid. This experiment demonstrates how to interface the keypad with an Arduino to read button presses and display them on the Serial Monitor.

Components Needed

Circuit Setup

Connect the 4x4 keypad to the Arduino as follows:

Code for 4x4 Matrix Keypad

Upload the following code to your Arduino to detect button presses:


// Include the Keypad library
#include 

// Define the number of rows and columns in 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 ROW pins to Arduino pins 2, 3, 4, 5
byte rowPins[ROWS] = {2, 3, 4, 5};

// Connect keypad COLUMN pins to Arduino pins 6, 7, 8, 9
byte colPins[COLS] = {6, 7, 8, 9};

// Create the Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
    Serial.begin(9600);
    Serial.println("4x4 Keypad Ready. Press a key:");
}

void loop() {
    char key = keypad.getKey(); // Read the key pressed

    if (key) { // If a key is pressed
        Serial.print("Key Pressed: ");
        Serial.println(key);
    }
}
            

Explanation

Troubleshooting

Applications of 4x4 Keypad

Matrix keypads are commonly used in: