TK85I2Cbeginner

Matrix Keypad with I2C Adapter (4x4, PCF8574)

A 4×4 keypad on two I²C wires instead of eight GPIO pins. The TK85 adapter, the soft and heavy-duty keypads, the two keymaps they need, and how to put two on one bus.

Comes in this kit — not sold separately
I2C 4x4 Matrix Membrane Keypad, 5 Sets
4x4 Matrix Keypad with I2C Adapter, Heavy Duty, 2-Pack

Specifications

Soft keypad 5-pack5 flexible membrane keypads, 69 × 76 mm with an adhesive back, and 5 adapters with pins, in a storage box
Heavy-duty 2-pack2 rigid keypads with raised keys and 8 pins soldered on, and 2 adapters with a socket
TinkerBlock TK85The adapter on a TinkerBlock board with mounting holes, in the 46-piece kit
Adapter chipPCF8574 I²C I/O expander: 8 port pins, P0–P7, one per keypad wire
Wires to your board4 — GND, VCC, and the 2 signal wires SDA and SCL
Supply voltage2.5–6 V for the chip. Use your board's own 3.3 V or 5 V: the I²C pull-ups go to VCC
I2C address0x20 as shipped; 0x20–0x27 with the three pads on the back
I2C clock100 kHz at most, per the PCF8574 datasheet
Pull-ups10 kΩ on SDA and on SCL, removable by cutting the I2C PULL UP pad
Keys16 in a 4 × 4 grid, read one at a time

What it does

A 4×4 matrix keypad is sixteen switches wired as four row wires and four column wires: pressing a key joins one row to one column. That is eight wires, and wired straight to a board it is eight GPIO pins — nearly half an Arduino Uno.

The adapter moves those eight wires onto a PCF8574, a chip with eight pins of its own that is controlled over I²C. What is left on your board is the I²C bus: SDA and SCL, plus power and ground. Screens, sensors and clocks share the same two wires, each at its own address. The adapter ships at 0x20.

The I2CKeyPad library by Rob Tillaart reads a key with two writes and two reads, and returns a number from 0 to 15. A keymap string turns that into the character printed on the key.

The boxes

Three products carry the same adapter circuit. What differs is the keypad.

The soft keypad 5-pack: one large flexible membrane keypad with blue number keys and red A to D, star and hash keys, four smaller ones below it, five small black adapter boards with eight right-angle pins, and a teal box printed I2C MATRIX KEYPAD KIT.
The soft keypad 5-pack: five membrane keypads with ribbon tails, five adapters with pins, and the box.
The heavy-duty 2-pack: a large keypad in a black rigid frame with raised keys 1 to 9, 0, A to D, star and hash, plugged into an adapter below it, a second keypad and adapter to the right, and the teal I2C MATRIX KEYPAD KIT box.
The heavy-duty 2-pack: two rigid keypads with pins soldered on, and two adapters with a socket.
TinkerBlock TK85 — front
Front
TinkerBlock TK85 — back
Back
TinkerBlock TK85 — side
Side

The TinkerBlock TK85, above, is the adapter on a TinkerBlock board with mounting holes for the base plate, and comes in the 46-piece kit.

Which keymap

KeypadComes inKeymap
Soft membranethe 5-pack, and the TK85 as photographedDCBA#9630852*741NF
Heavy-dutythe 2-packD#0*C987B654A321NF

The soft keypad brings its rows out first and the heavy-duty keypad its columns, so the same key lands on a different number. A keypad from anywhere else: run the keymap finder.

Wiring, in four lines

  1. GND to the board's GND.
  2. VCC to the board's own logic voltage: 5V on an Uno, 3V3 on an ESP32.
  3. SDA to the board's SDA: A4 on an Uno, GPIO 21 on an ESP32, GPIO 8 on an ESP32-S3.
  4. SCL to the board's SCL: A5, GPIO 22, GPIO 9.

VCC matters because the adapter's own 10 kΩ pull-ups tie SDA and SCL to it. Fed from 5 V next to an ESP32, the bus idles at 5 V against 3.3 V pins.

The TK85 wired to an Arduino Uno: 5V to VCC, GND to GND, A4 to SDA and A5 to SCL

Two on one bus

Every adapter ships at 0x20. Two on the same board need different addresses, set by bridging one of the three pads on the back with solder. The pads printed A0 and A2 are wired the other way round: bridging the one marked A0 gives 0x24, and the one marked A2 gives 0x21. Scan after soldering and use what it prints.

Each adapter also brings a pair of 10 kΩ pull-ups. With more than a handful on one bus, cut the I2C PULL UP pad on all but one. More than one keypad works through both.

Example

Install I2CKeyPad from the Arduino Library Manager. The MicroPython version does the same two reads by hand and needs no library.

#include <Wire.h>
#include "I2CKeyPad.h"

// 16 keys, then N (no key) and F (fail). Pick the one for your keypad.
char keymap[19] = "DCBA#9630852*741NF";      // soft keypad
// char keymap[19] = "D#0*C987B654A321NF";   // heavy-duty keypad

I2CKeyPad keyPad(0x20);
char last = 'N';

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(100000);   // the PCF8574 is rated for 100 kHz
  if (!keyPad.begin()) {
    Serial.println("No keypad at 0x20");
    while (true) delay(1000);
  }
  keyPad.loadKeyMap(keymap);
}

void loop() {
  char c = keyPad.getChar();
  if (c != last) {
    if (c != 'N' && c != 'F') Serial.println(c);
    last = c;
  }
  delay(20);
}

Where to start

The handbook below is eleven short articles with a working figure in each. If you only read one, read one adapter, two keymaps. If you want keys on the serial monitor now, the first keypress is the whole build.

When it doesn’t work

Nothing responds.
Scan the bus. The adapter answers at 0x20 as shipped, or 0x20–0x27 if a pad on the back is bridged; a PCF8574A chip would answer at 0x38–0x3F. If nothing answers anywhere, the fault is GND, VCC, SDA or SCL — on an Uno those last two are A4 and A5.
Every key prints a different key.
The sketch has the other keypad's keymap. The soft keypad needs "DCBA#9630852*741NF" and the heavy-duty keypad "D#0*C987B654A321NF". With the wrong one, 2 prints 4 and A prints *, while 1, 5, 9 and D look fine.
Two keys at once prints F.
That is the I2CKeyPad library refusing to guess. A second key pulls a second line low, and it returns FAIL rather than report a key that may not have been pressed. The keypad reads one key at a time.
I bridged the A0 pad and the adapter is at 0x24, not 0x21.
The design files wire the pad printed A0 to the chip's A2 pin, and the pad printed A2 to A0; only A1 is as labelled. The address is still different from 0x20, which is what matters. Always scan after soldering and use the address it prints.
Can I power the adapter from 5 V on an ESP32?
No. The adapter's pull-ups tie SDA and SCL to its VCC, so from 5 V both lines sit at 5 V against 3.3 V pins. The chip runs from 2.5 V, so feed it 3V3.
An old sketch sets the I²C clock to 400 kHz.
Set it to 100 kHz. That is the PCF8574's rated maximum, and a key still reads in well under a millisecond.

The matrix keypad handbook

11 articles · about 50 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

Why the adapter

2 articles

Sixteen keys need only eight wires if they are wired as a grid. The adapter turns those eight into the two an I²C bus already uses.

What is in your box

2 articles

Three boxes, one adapter circuit, two kinds of keypad. Which plugs into which, and what every pin and pad on the adapter is for.

How it reads a key

2 articles

Two I²C reads find any key, and the number they produce is not the character printed on it. The keymap is the translation, and there are two.

Limits and more keypads

2 articles

It reads one key at a time, by design. And it shares its bus: eight addresses, and pull-up resistors that add up.

Two builds and a check

3 articles

The first keypress on an Uno or an ESP32, a four-digit code lock, and the sketch that finds the right keymap for a keypad you have never seen.

Lessons using TK85

Each one is a working build, not a snippet.

Edit this page — content/modules/matrix-keypad.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