Built-in project · Arduino Uno R3

Membrane keypad on pins 9 to 2, on an Arduino Uno

A 4x4 membrane keypad with its rows on pins 9, 8, 7 and 6 and its columns on 5, 4, 3 and 2: the Keypad library prints every key that is pressed. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

Membrane keypad on pins 9 to 2 · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// A 4x4 membrane keypad: every key you press, printed.
//
//   keypad rows R1 to R4    -> pins 9, 8, 7, 6
//   keypad columns C1 to C4 -> pins 5, 4, 3, 2
//
// Sixteen keys on eight wires. Each key joins one row wire to one column wire
// when it is pressed. The Keypad library drives the columns low one at a time
// and reads the rows, so it can tell exactly which crossing closed.
//
// Click a key on the canvas.

#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);
  Serial.println("Mokxi Uno: keypad, rows on 9 to 6, columns on 5 to 2. Press a key.");
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    Serial.print("key: ");
    Serial.println(key);
  }
}

Parts list

2 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

8 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 9; Keypad, 4x4 pin R1
  • Arduino Uno R3 pin 8; Keypad, 4x4 pin R2
  • Arduino Uno R3 pin 7; Keypad, 4x4 pin R3
  • Arduino Uno R3 pin 6; Keypad, 4x4 pin R4
  • Arduino Uno R3 pin 5; Keypad, 4x4 pin C1
  • Arduino Uno R3 pin 4; Keypad, 4x4 pin C2
  • Arduino Uno R3 pin 3; Keypad, 4x4 pin C3
  • Arduino Uno R3 pin 2; Keypad, 4x4 pin C4

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.