> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 4x4 Membrane Keypad

> A standard 4x4 keypad - great for numeric input

A standard 4x4 keypad. Great for numeric input, e.g. security pin code.

## Pin names

<ParamField path="R1" type="Row">
  Row 1 (top row)
</ParamField>

<ParamField path="R2" type="Row">
  Row 2
</ParamField>

<ParamField path="R3" type="Row">
  Row 3
</ParamField>

<ParamField path="R4" type="Row">
  Row 4 (bottom row)
</ParamField>

<ParamField path="C1" type="Column">
  Column 1 (left)
</ParamField>

<ParamField path="C2" type="Column">
  Column 2
</ParamField>

<ParamField path="C3" type="Column">
  Column 3
</ParamField>

<ParamField path="C4" type="Column">
  Column 4 (right)
</ParamField>

## Attributes

<ParamField path="columns" type="string" default="4">
  Number of columns: "3" or "4"
</ParamField>

<ParamField path="keys" type="array" default="[&#x22;1&#x22;, &#x22;2&#x22;, &#x22;3&#x22;, &#x22;A&#x22;, &#x22;4&#x22;, &#x22;5&#x22;, &#x22;6&#x22;, &#x22;B&#x22;, &#x22;7&#x22;, &#x22;8&#x22;, &#x22;9&#x22;, &#x22;C&#x22;, &#x22;*&#x22;, &#x22;0&#x22;, &#x22;#&#x22;, &#x22;D&#x22;]">
  Labels for the keys
</ParamField>

You can change the key labels as you like. The first four items in the array set the labels for the first row of keys, the next
four items set the labels for the second row of keys, etc. Unicode characters are supported, so you can use special characters,
accented letters, superscript/subscript (e.g. Xⁿ or A₁), and even emojis.

## Arduino code example

The example below uses the Keypad library for Arduino. The key names set in the `keys` array
define the values that `keypad.getKey()` returns. They don't have to match the actual key labels
(but it can be confusing if they don't), and they must contain exactly one ASCII character.

```cpp theme={null}
#include <Keypad.h>

const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    Serial.println(key);
  }
}
```

You can also [try this example on Wokwi](https://wokwi.com/projects/294980637632233994).

<Tip>
  You can use keyboard shortcuts to activate the buttons on the keypad. Click on the keypad once (now the keypad is in focus), and you can press 0...9/A/B/C/D/#/\* in the keyboard to activate the corresponding key.
</Tip>

## Simulator examples

* [Basic Keypad example](https://wokwi.com/projects/294980637632233994)
* [Arduino Calculator](https://wokwi.com/projects/276825819240727048)
* [Electronic Safe](https://wokwi.com/projects/344891391763022419)
