matrix keypad/Why the adapter/01. Sixteen keys, eight wires
Why the adapter · 01 of 11

Sixteen keys, eight wires

A 4×4 keypad is sixteen switches wired as a grid of four row wires and four column wires. Pressing a key joins one row to one column, and that pair is all a board needs to know which key it was.

A key is a switch

Each key is two contacts that touch while you press it. On the soft keypad they are printed on two layers of plastic film; on the heavy-duty keypad they sit under separate raised keys. Either way, pressed means connected and released means not.

Sixteen switches could have a wire each, plus a shared ground. That is seventeen wires, and nobody builds a keypad that way.

Rows and columns

A matrix keypad puts every switch where a row wire crosses a column wire. Four rows and four columns cross in sixteen places, which is one crossing per key. Pressing a key connects its row wire to its column wire and nothing else.

Sixteen keys, two ways to wire them
8 wires
Press a key
Wiring
Wires to the board
8
Keys
16
Key pressed
6 · R2 C3
A key is a crossing, not a wire. Pressing 6 connects row 2 to column 3 and nothing else, so a board that can tell which row and which column are joined knows the key. Four rows and four columns name all sixteen.

Press 6 and row 2 is joined to column 3. No other key joins that pair, so the pair names the key. Eight wires carry all sixteen keys.

The eight come out of the keypad in a row: along the soft keypad's ribbon tail, and as eight pins on the heavy-duty keypad's bottom edge.

What a board has to do

The keypad cannot say which key is down. The board has to find out, by pulling one set of wires to 0 V and watching which wire on the other side follows it down through the pressed key.

Chapter three shows how the adapter does that in two reads. First, the problem the adapter exists to solve: eight wires is still a lot of pins.

When it does not work

A whole row or column of keys does nothing

Four dead keys in a line are one dead wire, not four dead keys. On the soft keypad the socket is usually off by one pin or not pushed fully home; on the heavy-duty keypad, check that all eight pins are in the adapter's socket.

Which of the eight wires is row 1?

You do not need to know. The adapter and the library find the key by which two wires are joined, and the keymap turns that into the printed character. If a keypad arrives with no documentation, the keymap finder at the end of this book works it out.

How do I test a single key with a multimeter?

Set the meter to continuity, touch the probes to the key's row pin and column pin, and press the key: it should beep. Find the pair by trial — there are only sixteen combinations of one row pin and one column pin.

Is the soft keypad worse than the heavy-duty one?

Electrically they are the same grid. The difference is the feel and the fitting: the soft keypad is a thin film with an adhesive back for a box lid, the heavy-duty keypad has a rigid frame and separate raised keys.

Where this goes next

A grid still needs eight wires. The adapter turns them into the two an I²C bus already uses.

Eight pins down to two

Edit this page — content/books/matrix-keypad/sixteen-keys-eight-wires.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum