4×4 Keypad
A 16-button matrix keypad wired as 4 rows by 4 columns, read over 8 digital pins with no power supply of its own.
- Keys16 in a 4 × 4 matrix (1-9, 0, A-D, *, #)
- Interface8 pins: 4 rows and 4 columns
- Contact rating24 VDC, 30 mA max
- Operating temperature0 °C to 50 °C

A 4x4 matrix membrane keypad is 16 passive switches on four row and four column wires: pressing a key joins one row to one column (Parallax #27899 datasheet, p. 2), so it needs no power, just eight digital pins. Wire the eight header pins to eight GPIOs and read it with the Arduino Keypad library, which pulls the rows up and drives each column low in turn. The contacts are rated 24 VDC and 30 mA at most (datasheet, p. 1), so it works the same on 3.3 V and 5 V boards.
The 4x4 keypad is a grid of 16 momentary switches arranged as four rows and four columns. Each button simply connects one row line to one column line when pressed (Parallax 4x4 Matrix Membrane Keypad #27899 datasheet, p. 2), so the whole keypad is passive: it needs no power, just eight digital pins on the microcontroller. Its contacts are rated for 24 VDC and 30 mA at most (p. 1), far above what a GPIO scan puts through them.
To read it, the microcontroller scans the matrix. It drives one line of one side at a time and reads the four lines of the other side, which tells it exactly which of the 16 keys is down. The Arduino Keypad library does this by pulling the rows up with INPUT_PULLUP and driving each column LOW in turn, then maps each intersection to a character like 0-9, A-D, star, or hash.
Reading 16 keys with only 8 pins is the whole point of the matrix layout. The trade-off is that reliable multi-key detection needs extra diodes, so a plain keypad is best for one keypress at a time.
4×4 Keypad pinout
| Pin | Function | Type |
|---|---|---|
| R1 | Digital | bidirectional |
| R2 | Digital | bidirectional |
| R3 | Digital | bidirectional |
| R4 | Digital | bidirectional |
| C1 | Digital | bidirectional |
| C2 | Digital | bidirectional |
| C3 | Digital | bidirectional |
| C4 | Digital | bidirectional |
How to wire the 4×4 Keypad
Pin by pin, for the board you have.
| 4×4 Keypad | Arduino Uno | Note |
|---|---|---|
| R1 | D2 | |
| R2 | D3 | |
| R3 | D4 | |
| R4 | D5 | |
| C1 | D6 | |
| C2 | D7 | |
| C3 | D8 | |
| C4 | D9 |
| 4×4 Keypad | ESP32 DevKit V1 | Note |
|---|---|---|
| R1 | GPIO13 (D13) | |
| R2 | GPIO14 (D14) | |
| R3 | GPIO27 (D27) | |
| R4 | GPIO26 (D26) | |
| C1 | GPIO25 (D25) | |
| C2 | GPIO33 (D33) | |
| C3 | GPIO32 (D32) | |
| C4 | GPIO4 (D4) |
| 4×4 Keypad | Raspberry Pi Pico | Note |
|---|---|---|
| R1 | GP0 | |
| R2 | GP1 | |
| R3 | GP2 | |
| R4 | GP3 | |
| C1 | GP4 | |
| C2 | GP5 | |
| C3 | GP6 | |
| C4 | GP7 |
4×4 Keypad code
Every example here compiles for its board.
// 4×4 Keypad on Arduino Uno: wiring and a free simulation at https://www.tinkered.ai/components/keypad-4x4
#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] = {2, 3, 4, 5}; // R1, R2, R3, R4
byte colPins[COLS] = {6, 7, 8, 9}; // C1, C2, C3, C4
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Returns the next pressed key character, or NO_KEY (== 0) if none.
// Combines the Keypad library (matrix scan on real hardware) with
char readKey() {
char k = kpd.getKey();
if (k) return k;
if (Serial.available()) {
char c = Serial.read();
if (c >= ' ') return c; // skip newlines / control chars
}
return NO_KEY;
}
void setup() {
Serial.begin(115200);
}
void loop() {
char key = readKey();
if (key) {
Serial.println(key);
}
}
Compiled for arduino:avr:uno on 2026-10-29Before you wire it
- Never plug its pins into breadboard holes. "kpd_1") and terminals: [{ name: "t1", connection: "<pinId>" }] where <pinId> is one of R1..R4 / C1..C4.
- Pin order on the header is R1, R2, R3, R4, C1, C2, C3, C4: wire them in this order to the Arduino pins listed in rowPins[] / colPins[].
- Use 8 digital GPIO pins on the Arduino. Any free digital pin works (D2–D13). Avoid D0/D1 if Serial is used.
- The keys[][] 2D array in code must match the physical layout of the keypad (see diagram above): otherwise the wrong character is returned.
- No external pull-up or pull-down resistors on any of the 8 pins (redundant with INPUT_PULLUP and can cause double-loading).
- No connecting any keypad pin to VCC (5V) or GND directly: all 8 pins must go to Arduino GPIO.
- No using analog-only pins for rows/cols on boards without digital fallback (Arduino Uno A0–A5 CAN be used as D14–D19, but prefer D2–D9).
- No swapping row/column roles in software: rowPins[] must be wired to R1–R4 pins, colPins[] to C1–C4, in order.
- No sharing any of these 8 pins with another component: all 8 pins are exclusive to the keypad during scanning.
- No VCC or GND is required for the keypad itself. Connect the four row pins and four column pins to eight digital GPIO pins.
- Enable the internal pull-up resistors on the pins the scan reads, so an unpressed key reads a defined level instead of floating. The Keypad library does this itself (rows as INPUT_PULLUP), so no external resistors are needed.
- Get the row and column pin order right. If the wiring order does not match the map in code, the wrong characters are reported even though the hardware is fine.
- For reliable simultaneous multi-key presses, add a diode in series with each switch to prevent ghosting. Without diodes, some three-key combinations read as phantom presses.
- The Keypad library pulls up the rows and drives the columns low one at a time.
Specifications
- Keys
- 16 in a 4 × 4 matrix (1-9, 0, A-D, *, #)Parallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, p. 1
- Interface
- 8 pins: 4 rows and 4 columnsParallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, pp. 1 to 2
- Contact rating
- 24 VDC, 30 mA maxParallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, p. 1
- Operating temperature
- 0 °C to 50 °CParallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, p. 1
- Size
- Keypad 6.9 × 7.6 cm, cable 2.0 × 8.8 cmParallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, p. 1
- Power
- None: passive switches onlyParallax 4x4 Matrix Membrane Keypad #27899 datasheet v1.2, p. 2
- Weight
- 10 g
Common mistakes
Mismatched row and column order
The eight pins must be listed in code in the same order as they are wired. A swapped row or column makes the keypad report the wrong characters even though every key works.
Leaving scan pins floating
Without pull-up or pull-down resistors the input pins float and report random presses. Use the internal pull-ups the keypad library expects.
Expecting reliable multi-key input
A plain matrix keypad without diodes suffers from ghosting, so pressing several keys at once can register phantom keys. Design for one key at a time or add per-switch diodes.
Assuming it needs power
The keypad is just switches. Wiring a VCC to it does nothing useful and, if bridged to a scan line, can confuse the reading. Only the eight signal pins are needed.
4×4 Keypad questions
How do I connect a 4x4 keypad to an Arduino?
Plug the eight header pins into eight digital pins, for example rows on D2 to D5 and columns on D6 to D9, with no power or ground wire. List the same pins in rowPins and colPins for the Keypad library and call getKey() in loop().
Can I use a 4x4 keypad with an ESP32 or other 3.3 V board?
Yes. The keypad is passive switches rated up to 24 VDC and 30 mA (Parallax #27899 datasheet, p. 1), so it works at any logic voltage. Avoid the ESP32's input-only pins (GPIO34 to 39) for the columns, since the library drives those as outputs, and avoid pins without internal pull-ups for the rows.
Why does my keypad print the wrong characters?
The pins in code do not match the wiring, or rows and columns are swapped. Check which header pins are rows and which are columns on your keypad, then list them in the same order in rowPins and colPins, and make sure the keys[][] map matches the printed layout.
Do I need resistors with a 4x4 keypad?
No. The Keypad library turns on the microcontroller's internal pull-ups on the rows, so every unpressed key reads a defined level. External resistors are only needed on a board without internal pull-ups.
Why do I get phantom key presses when I press several keys?
That is ghosting: with three keys down on the corners of a rectangle, current finds a path through them and the scan sees a fourth key. A plain membrane keypad has no diodes to block it, so design for one key at a time or build a matrix with a diode per switch.
How many pins does a 4x4 keypad need?
Eight: four rows and four columns (Parallax #27899 datasheet, p. 1). If pins are short, an I2C I/O expander such as a PCF8574 can scan it over two wires.
Build something with the 4×4 Keypad
- Build this
Passcode door lock
Enter a PIN to release a servo or relay-driven latch, a classic access-control build.
- Build this
Calculator or number entry
Feed digits into a display or logger for a simple calculator or data-entry pad.
- Build this
Menu and mode selector
Use the letter keys to move through menus or switch modes on a project.
- Build this
Combination-lock games
Build safe-cracking or memory games around entering the right key sequence.
This page as plain Markdown, for ChatGPT, Claude or your own agent. /components/keypad-4x4.md