Keypad, 4x4
Sixteen keys on eight pins. Scan a row at a time, and mind the ghosting.
- 8 pins
Every one of its 8 pins
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 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.
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.
See the Keypad, 4x4 in a project
Shown here on: Arduino Uno R3
Where it turns up in a lesson
In a learn article
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Keypad, 4x4
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.