Quick answer
Wire the 4x4 membrane keypad's 8-pin header to Arduino digital pins 2–9, then use a keypad library to scan rows and columns and read key presses.
Why a matrix keypad uses only 8 pins for 16 keys
A 4x4 matrix keypad arranges the 16 keys in four rows and four columns. Each key connects one row and one column. By scanning each row low and reading the columns, the Arduino detects which key is pressed. This method saves I/O pins compared to connecting each key individually.
Choosing between membrane and mechanical keypads
Membrane keypads like the 4x4 16 Key Matrix Membrane Keypad are thin, self-adhesive, and low-cost. They are ideal for prototypes and projects where durability is not critical. Mechanical keypads offer better tactile feedback and longer life but cost more and take up more space. For most Arduino experiments, a membrane keypad is a practical starting point.
How to wire and program a 4x4 matrix keypad
- Identify the keypad pinout: Hold the keypad with the connector facing you and the cable pointing down. The leftmost pin is usually row 1, then row 2, row 3, row 4, column 1, column 2, column 3, column 4. Confirm with a multimeter in continuity mode: press a key in the first row and touch each pin to find which one beeps. Common mistake: assuming the pin order is columns first. Always verify with a multimeter or datasheet.
- Connect the keypad to Arduino: Connect the 8-pin header to Arduino digital pins 2 through 9. Use male-to-female jumper wires: pin 2 to row 1, pin 3 to row 2, pin 4 to row 3, pin 5 to row 4, pin 6 to column 1, pin 7 to column 2, pin 8 to column 3, pin 9 to column 4. If your keypad has a different pin order, adjust accordingly. Checkpoint: ensure each wire is firmly seated. Loose connections cause intermittent key reads.
- Install the Keypad library: In the Arduino IDE, go to Sketch > Include Library > Manage Libraries. Search for 'Keypad' by Mark Stanley and Alexander Brevig. Install the latest version. This library handles row/column scanning and debouncing. Empty
- Write the keypad scanning code: Define the key mapping as a 4x4 char array (e.g., '1','2','3','A','4','5','6','B', etc.). Define rowPins and colPins arrays matching your wiring. Create a Keypad object with makeKeymap(). In loop(), call keypad.getKey() and print the result to Serial Monitor. Common mistake: mismatched row/column pin order in code vs wiring. Double-check that rowPins and colPins arrays match the physical connections.
- Upload and test: Upload the sketch to your Arduino, open Serial Monitor at 9600 baud, and press each key. You should see the corresponding character appear. If some keys don't respond or give wrong characters, verify your pin mapping and keymap array. If multiple keys trigger the same output, check for solder bridges or debris on the membrane contacts.
Product used in this guide
-
4x4 16 Key Matrix Membrane Keypad: This 4x4 matrix membrane keypad provides 16 tactile keys in a compact, self-adhesive design. It includes an 8-pin connector with 2.54mm pitch and an 8cm cable. The 2.54mm pitch matches standard breadboard and Arduino header spacing, so you can plug it directly into a breadboard or use jumper wires without adapters.
4x4 16 Key Matrix Membrane Keypad



