The membrane keypad 4×4 is one of the most popular input devices for Arduino and microcontroller projects. With 16 buttons in a compact, flat package, it is perfect for PIN entry systems, calculators, menu navigation, and access control — all for under ₹60 in India.
What Is a Membrane Keypad?
A membrane keypad is a thin, flexible input device made of multiple layers of polyester film. The top layer has printed key labels, and beneath it are two conductive layers separated by a spacer. Pressing a key pushes the top conductive layer through a hole in the spacer to make contact with the bottom layer.
The 4×4 variant has 16 keys arranged in 4 rows and 4 columns, typically labelled 0-9, A-D, *, and #. It uses only 8 pins (4 row + 4 column), which is a major advantage over wiring 16 individual buttons.
How the Matrix Scanning Works
The keypad uses a matrix wiring scheme to minimise pin usage. Each key sits at the intersection of a row and a column. To detect which key is pressed:
- Set all column pins as INPUT_PULLUP and all row pins as OUTPUT HIGH.
- Drive one row LOW at a time while keeping others HIGH.
- Read all column pins. If a column reads LOW, a key at that row-column intersection is pressed.
- Repeat for each row.
This scanning happens fast enough (microseconds per scan) that it feels instantaneous to the user.
Wiring to Arduino
The 4×4 membrane keypad has an 8-pin ribbon connector. The pinout (left to right when the keypad faces you) is typically:
| Keypad Pin | Function | Arduino Pin |
|---|---|---|
| 1 | Row 1 | D9 |
| 2 | Row 2 | D8 |
| 3 | Row 3 | D7 |
| 4 | Row 4 | D6 |
| 5 | Col 1 | D5 |
| 6 | Col 2 | D4 |
| 7 | Col 3 | D3 |
| 8 | Col 4 | D2 |
Arduino Code with Keypad Library
Install the Keypad library by Mark Stanley and Alexander Brevig from the Arduino Library Manager, then use this code:
#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.println(key);
}
}
Project Ideas
- Door lock with PIN code — Combine the 4×4 keypad with a servo or solenoid lock. Store the PIN in EEPROM so it survives power cycles.
- Calculator — Display results on a 16×2 LCD. The A-D keys can map to +, -, *, /.
- Menu system for OLED — Use the number keys for selection and * / # for enter/back navigation.
- DTMF tone generator — Play the corresponding DTMF tone for each key press through a speaker.
- Home automation controller — Assign rooms or appliances to each key, with relay modules for switching.
Recommended Products from Zbotic
4×4 Matrix Keypad Membrane Switch
4×4 Matrix 16 Button Keypad Keyboard Module
1×4 Matrix – Membrane Type Keypad – 4 Keys
4×3 12-key Keyboard / Keypad Telephone Style – Black
4×5 Matrix Array 20 Key Membrane Switch Keypad
Frequently Asked Questions
What is the difference between a 4×3 and 4×4 keypad?
A 4×3 keypad has 12 keys (0-9, *, #) and uses 7 pins. A 4×4 keypad adds a column with A, B, C, D keys, totalling 16 keys on 8 pins. Choose based on how many inputs your project needs.
Can I use a membrane keypad in an outdoor project?
Standard membrane keypads are not waterproof, but their sealed construction offers some splash resistance. For outdoor use, mount the keypad behind a sealed enclosure or use an IP-rated industrial keypad.
How long does a membrane keypad last?
Most membrane keypads are rated for 1 to 5 million presses per key. For infrequent use (access control), they can last years. For heavy use, consider a PCB-mount tactile button matrix instead.
Can I use fewer Arduino pins for the keypad?
Yes. Use a PCF8574 I2C expander to read the keypad using just 2 pins (SDA and SCL). The Keypad_I2C library supports this configuration.
Start Your Keypad Project
Grab a keypad module and Arduino from Zbotic.in — delivered pan-India!
Add comment