03 / Templates · intermediate
MEMBRANE KEYPAD
Open in Playground4×4 membrane keypad (16 keys: 0–9, A–D, *, #) wired to 8 Arduino pins via row/column scanning. Requires the Keypad library. Press a key and its character prints to the Serial Monitor.
intermediatekeypadinputserialmatrixKeypad library
sketch.inoArduino C++
26 lines
// Membrane Keypad — print key to Serial Monitor
#include <Keypad.h>
const byte ROWS = 4, 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("Key: ");
Serial.println(key);
}
}- Arduino Uno01
- Membrane Keypad (wokwi-membrane-keypad)02
| Component Pin | Arduino Pin |
|---|---|
| R1 (Row 1) | Pin 9 |
| R2 (Row 2) | Pin 8 |
| R3 (Row 3) | Pin 7 |
| R4 (Row 4) | Pin 6 |
| C1 (Col 1) | Pin 5 |
| C2 (Col 2) | Pin 4 |
| C3 (Col 3) | Pin 3 |
| C4 (Col 4) | Pin 2 |