Keypad, 4x4
Sixteen keys on eight pins. Scan a row at a time, and mind the ghosting.
- 8 pins
- In 4 projects
- In 2 lessons
The Keypad, 4x4 in brief
What it is, and where it sits on the bench.
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.
- Family
- Inputs
- Pins
- 8
A circuit built around it, running and explained: the Keypad simulator.
8 pins
Named as the editor names them, so a wire lands where you expect it.
- R1
- R2
- R3
- R4
- C1
- C2
- C3
- C4
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
In its help article’s own words: what the simulation gets right, and where it stops.
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
4 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
2 lessons place it in their own circuits.
The boards it is shown on
This board has a built-in project with the Keypad, 4x4 in it.
The Keypad, 4x4 on each board
The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.
Arduino libraries for the Keypad, 4x4
Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.
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.