Part

Keypad, 4x4

Sixteen keys on eight pins. Scan a row at a time, and mind the ghosting.

or see every part
  • 8 pins
Drawn live by the editor's own code, at the size you see it.
Reference

Every one of its 8 pins

Pin
What it does
R1
R2
R3
R4
C1
C2
C3
C4
This part

What it does

The 4x4 membrane keypad has sixteen keys, eight pins and no chip inside. Under each key a carbon pad shorts one row trace to one column trace, and that is all it does, which is why a sketch has to scan it: drive one row low, read the four columns with their pull-ups on, and a column that reads low is a key held in that row. Mokxi models the keys as real contacts that pass current both ways, so it keeps the faults of the real part too. Three keys held in a rectangle make the fourth corner read as pressed, the ghosting that membrane keypads without diodes have, and driving a row high while another key shorts it low puts two outputs against each other as it would on a desk. It does not model contact bounce; that lesson belongs to the pushbutton. Click a key in the editor to hold it down.

How to use it

How to use a 4x4 keypad with an Arduino

Eight wires: the four rows and the four columns to eight digital pins. Scan it: set the columns as inputs with pull-ups, drive one row LOW at a time, and read the columns; a column that reads LOW is a key held in that row. Do it every few milliseconds and report a key once, when it first goes down.

Drive rows low, never high, while scanning. With two keys held in one column, a high row would be shorted straight to a low one.

Part pin
Board pin
R1, R2, R3, R4
Pins 9, 8, 7, 6
C1, C2, C3, C4
Pins 5, 4, 3, 2
Arduino Uno: keypad locklive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
How it is modeled

What is true about the Keypad, 4x4, here

What is modeled

A closed key is a real low-resistance contact passing whatever is on either side in either direction. The model does nothing to stop a row driven high while another key shorts it to a driven low, because a real keypad does nothing to stop that either. Ghosting is modeled too: three keys held in a rectangle make the fourth corner read as pressed, because current has a way around through the three that are closed, exactly what a real matrix keypad with no diodes does, and the reason a keypad sketch normally reads one key at a time.

Not modeled

No diodes on the keys. Some keypads add one per key to prevent ghosting, but the cheap membrane kind does not, and neither does this part.

No contact bounce. A real membrane key's carbon pad chatters for a millisecond or two and a scanning sketch has to settle for it; here a key closes exactly once. That is a deliberate omission, not an oversight (the bounce lesson belongs to the pushbutton), but it means a keypad sketch that would need debouncing on the bench runs clean here. There is no contact resistance drift, no row or column capacitance and no settle time after a row is driven, so a scan can be as fast as the firmware likes.

From 4x4 membrane keypad, in full.

Projects

See the Keypad, 4x4 in a project

Shown here on: Arduino Uno R3

Learn

Where it turns up in a lesson

In a learn article

Wire up the Keypad, 4x4

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.