Theory of Operation

Matrix keypads consist of a grid of buttons with corresponding wires that may be read and interpreted by a microcontroller. As the figure below shows, the number of pins needed by the microcontroller is determined by the number of rows and columns in the button grid, where one wire is needed per row and per column. When a button is pressed, a connection between the corresponding row and column is created. This connection enables the keypad to be interpreted by the microcontroller.

Figure 1. Matrix Keypad Schematics

There are multiple ways of scanning a matrix keypad. The simple method used in the example applications is scanning one full axis (that is, the row or the column) at a time. This is done by setting up one of the axes to output a known voltage level and reading the voltage level of the wires of the other axis to find out which wire was pulled to that voltage. Figure 2 shows where the columns output 0V and the rows are connected to 3.3V through a pull-up resistor. ROW 0 is shown to be pulled down to 0V because of a connection to the columns, so the pressed button may therefore be assumed to be in ROW 0.

Figure 2. Row Scan

After the first axis has been scanned, the setup must be flipped to read the other axis. This is shown in Figure 2-3 where COLUMN 1 is shown to be pulled down to 0V because of a connection to the rows, so the pressed button may therefore be assumed to be in COLUMN 1.

Figure 3. Column Scan

When both axes have been scanned, the coordinates of the pressed button in the grid are known, and the button press may be recorded and acted upon. In this example, since ROW 0 and COLUMN 1 are known to include the pressed button, it is understood that button 2 is pressed.

Although this method is simple, the problem with it is that it can only handle one simultaneous button press at a time. Figure 2-4 shows which wires are pulled low when each of the axes are pulled low. As shown in the figure, ROW 1 and 2 and COLUMN 1 and 2 are pressed, leading to four buttons being recorded while only two buttons are really pressed. This effect is called ghosting.

Figure 4. Ghosting

Another method is to pull the axis low one wire at a time, reading all the pins on the other axis for each time to find the intersections. This is shown in the figure below, where ROW 0 is driven low, and COLUMN 1 and COLUMN 2 are pulled low by buttons 2 and 3 being pressed. The advantage of this method is the ability to read two button presses at a time, while the disadvantage is that it may add complexity to the application.

Figure 5. Single Axis Scan