Guide to 4×4 Matrix Keypad for Arduino

4×4 Matrix Keypad
16-Button Input Interface for Arduino and Microcontroller Projects
Introduction
The 4×4 matrix keypad is a compact input device with 16 buttons arranged in a grid. Using only 8 pins, it provides an efficient way to add multiple button inputs to Arduino, Raspberry Pi, and other microcontroller projects.

Key Features
16 Buttons
4 rows × 4 columns matrix configuration
Standard Layout
0-9 digits plus A,B,C,D,*,# symbols
Low Power
Only draws current during scanning
Simple Interface
8-pin connection (4 rows + 4 columns)
Technical Specifications
Operating Voltage | 1.5V – 24V DC |
---|---|
Contact Resistance | <100mΩ |
Insulation Resistance | >100MΩ |
Life Expectancy | 1,000,000 presses |
Dimensions | 80mm × 80mm × 10mm (typical) |
Button Spacing | 19mm × 19mm (standard) |
Pin Configuration

Pin | Function | Arduino Connection |
---|---|---|
1 | Row 1 | D9 |
2 | Row 2 | D8 |
3 | Row 3 | D7 |
4 | Row 4 | D6 |
5 | Column 1 | D5 |
6 | Column 2 | D4 |
7 | Column 3 | D3 |
8 | Column 4 | D2 |
Note: Pin connections can be customized to any digital pins
Wiring with Arduino

// Basic Connections:
// Row 1 → D9
// Row 2 → D8
// Row 3 → D7
// Row 4 → D6
// Column 1 → D5
// Column 2 → D4
// Column 3 → D3
// Column 4 → D2
Important: Always use INPUT_PULLUP mode for columns to avoid floating inputs
Library Setup
- Install the Keypad library by Mark Stanley and Alexander Brevig
- Include the library in your sketch:
#include <Keypad.h>
- Configure the keypad layout:
const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} };
Basic Keypad Example
#include <Keypad.h> const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {9, 8, 7, 6}; byte colPins[COLS] = {5, 4, 3, 2}; Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); void setup() { Serial.begin(9600); } void loop() { char key = keypad.getKey(); if (key) { Serial.print("Pressed: "); Serial.println(key); } }
Advanced Features
Password Entry
// Simple password check
char password[4] = {'1','2','3','4'};
char entered[4];
int pos = 0;
void checkPassword(char key) {
entered[pos++] = key;
if(pos == 4) {
if(strncmp(entered, password, 4) == 0) {
Serial.println("Access granted!");
}
pos = 0;
}
}
Keypad Events
// Detect key presses and releases
void loop() {
if(keypad.getState() == PRESSED) {
Serial.print("Pressed: ");
Serial.println(keypad.getKey());
}
if(keypad.getState() == RELEASED) {
Serial.print("Released: ");
Serial.println(keypad.getKey());
}
}
Multi-key Press
// Detect multiple simultaneous presses
void loop() {
if(keypad.isPressed('A') && keypad.isPressed('B')) {
Serial.println("A+B combo pressed!");
}
}
Custom Keymaps
// Special function keys
char keys[ROWS][COLS] = {
{'F','F','F','F'},
{'F','F','F','F'},
{'F','F','F','F'},
{'R','F','E','F'}
}; // F=Forward, R=Reverse, E=Emergency Stop
Troubleshooting
No Key Detection
- Verify all connections are secure
- Check row/column pin assignments
- Ensure proper keymap configuration
Ghost Presses
- Use INPUT_PULLUP for columns
- Add 0.1μF capacitors between rows/cols and GND
- Implement software debouncing
Multiple Keys Not Working
- Check for short circuits between pins
- Verify sufficient power supply
- Test with different digital pins
Related Posts
MG90S Mini Digital 180° Servo
MG90S Mini Digital 180° Servo
Metal Gear, 2.2kg·cm Torque for RC and Robotics
Introduction
The MG90S is a compact di...
XKC-Y25-V Non-Contact Water Liquid Level Sensor
XKC-Y25-V Non-Contact Water Liquid Level Sensor
Capacitive Detection Without Physical Contact
Introduction
The XKC-Y...
Waterproof Ultrasonic Obstacle Sensor, Sensor with Separate Probe
+
Waterproof Ultrasonic Obstacle Sensor
Distance Measurement with Separate Waterproof Probe
Introduction
The Wa...
Water Level Depth Detection Sensor
Water Level Depth Detection Sensor
Liquid Measurement for Arduino and IoT Projects
Introduction
The Water Level Dept...
VL53L0X Purple Laser Distance Sensor Module
VL53L0X Laser Distance Sensor Module
High-Speed, High-Precision Time-of-Flight Distance Measurement
Introduction
The...
TCS34725 RGB Color Sensor Module
TCS34725 RGB Color Sensor Module
High-Accuracy Digital Color Detection with IR Filter
Introduction
The TCS34725 is a...
TCS3200 Color Sensor Module
TCS3200 Color Sensor Module
Precise RGB Color Detection for Arduino and Embedded Projects
Introduction
The TCS3200 C...
PN532 NFC RFID Read/Write Module V3 Kit
PN532 NFC RFID Read/Write Module V3 Kit
Advanced Near Field Communication for Arduino and Embedded Systems
Introducti...
HC-SR501 PIR Motion Sensor Module
HC-SR501 PIR Motion Sensor Module
Passive Infrared Detection for Security and Automation Projects
Introduction
The H...
Flex Sensor 5.6 cm (Detect Bending Motion)
Flex Sensor 5.6cm
Bend Detection Sensor for Arduino and Wearable Electronics Projects
Introduction
The 5.6cm...
ACS712 Current Sensor Module
ACS712 5A Current Sensor Module
Hall-Effect Based AC/DC Current Measurement for Arduino Projects
Introduction
The AC...
AS608 Optical Fingerprint Sensor Module
AS608 Optical Fingerprint Sensor Module
High-Precision Biometric Recognition for Arduino and Microcontroller Projects
...
Recent Comments