Using a Matrix Keypad

There a several cheap 4x4 matrix keypads available that can be easily controlled with an Arduino MCU. Those keypads don’t have own controllers. They are connected by their rows and columns. When putting one row to high, you can read at the column lines which of the buttons are pressed in this row. We need to cycle through the rows and read the columns to get all buttons that are pressed.

Basic setup

The basic setup consists of only these parts:

  • a half-length breadboard
  • an Arduino Micro v3
  • a 4x4 membrane keypad
  • a few wires

The circuit is very easy. We can connect the keypad directly to the Arduino. No extra parts are required.

Keypad connection circuit

For the experiments, we put everything together on a breadboad.

Keypad connected to the Arduino

The power is delivered over the USB connection of the Arduino. The keypad does not need a dedicated power source.

Warning

The hardware keypad in our experiment has a different pin-out assignment as in some data sheets around the web. The Arduino program may not match the circuit.

PIN | Assignment
----+-----------
  1 | Column 4
  2 | Column 3
  3 | Column 2
  4 | Column 1
  5 | Row 4
  6 | Row 3
  7 | Row 2
  8 | Row 1

What’s next?

Before we start programming, we need a strategy to debounce the inputs. This could be done with software in the MCU or hardware. We evaluate both possibilities.