The Keypad

Keypads, numeric or otherwise, are typically manufactured as push-button switch matrices, switches being located at the cross-points of the column and row lines which then are accessible through the keypad's interface connector. Similar key matrices can be constructed also from discrete push-button switches and the externally visible layout does not need to be square. In all cases, in order to minimize the complexity it is advantageous to arrange the wiring such that the sum of the rows and columns is minimized.

A keypad so constructed is intended to be interfaced digitally. The states of the buttons are decoded by scanning the switch matrix rows one-by-one and reading the columns (or vice versa) in parallel. This can be done from a microcontroller's GPIO or from a dedicated keyboard interface driver chip, or one can use shift registers or serial-to-parallel and parallel-to-serial converter logic chips (TTL, CMOS, LVC etc.).

If one wants to connect such a switch matrix with less pins, a common approach has been to connect the switches into a resistive voltage divider, each button press creating a different resistor combination topology and thus a different output voltage. For custom made keypad reasonably distinct voltage levels can be achieved by using many resistors of finely selected values. An example of such is available for purchase and more examples can be found in designs of consumer electronics devices like push-button interfaces of some microwave ovens an TV-sets.

If one wants to connect a readily available matrix keypad the same way, either heavy internal modifications are needed, or, when using only the externally accessible connections to the rows an columns, even with careful selection of the resistors, it is difficult to get the spacing of the output voltage levels uniform, which requires more complex decoder program and in some cases unit-by-unit calibration and even then the performance with large number of keys is not very good.

What is needed is a way to generate uniform distribution of voltages with a simple circuit.

The Modification

Both a custom key matrix and an off-the-self matrix keypad can be easily modified to produce a uniform distribution of resistances by connecting resistors between consecutive rows and columns. Only two different values are needed, one for rows and one for columns. The resistance of a resistor between rows must be number of columns times the resistance of a resistor between columns (or vice versa).

Such exact resistor value ratios are available in standard resistor values from series E24 and up. Required tolerance depends on the total number of keys. Tolerance of 5% is sufficient for 3x4 matrix while for 4x4 it would be safer to use 2% for manufacturing, even though usually 5% is also OK, at least for private projects.

One of the photos shows the circuit board of a rubber dome keypad which was used in the demonstration. That board contains an internal modification made using five 0402 resistors (12 kΩ and 36 kΩ) connected between the rows and the columns using slug tape. external modification can be made to the pins easily if the connector uses the pattern where row and column lines are not interleaved. This keypad has them interleaved so the modification was made internally. In commercial productions the resistors would be part of the board and the connector would have only two pins. An alternative would be to use an adapter board attached to the keypad's connector and providing the two-wire connection onward.

The Interface

At the logic board, between the keypad connector and the analog input pin of the microcontroller a simple current mirror circuit is needed. That requires just one resistor and a current mirror, like BCV61 or a pair of transistors, co-packaged, like BC847S or discrete. Pretty much any pair of similar transistors is sufficient for private projects, but for manufacturing a dedicated current mirror is a better choice.

The resistor in this circuit sets the reference current at which the resistance of the keypad is converted to a voltage. For best performance the current has to be st so that the distribution of the output voltage levels is as uniform as possible.  In practice that means that the desired resistance is slightly lower (by about 3%) of the maximum resistance the keypad produces. This reduction depends on the type of the current mirror and the maximum resistance of the keypad and for optimal performance needs to be determined by simulations or on board experiment. To obtain accurate resistor value one may need to use 1% or 0.5% resistors, but for private projects 5% resistors work fine up to 4x4 keypad.

The Program

Decoding the key value in SW is simple as the voltage levels are evenly distributed. When no key is pressed the voltage and the ADC output is zero (except for possible noise). The highest value will correspond to the short-circuiting key and is the reference voltage or ADC full scale. Other values can be obtained simply by linear interpolation. All values of the interpolation formula can be fixed by design when the component tolerances are good. For a private project using less accurate components the lowest value above zero may need to be measured and included into the formula.


In an EEVblog forum discussion the user PCB.wiz kindly pointed out the issue of Vbe temperature dependence of the current mirror and its possible effect to the generated voltage levels. Furthermore the user capt bullshot suggested using emitter resistors for that. By adding the compensating resistor to the emitter circuit of the output leg the spread of the voltages at the low end can be reduced drastically as shown in picture below.

For a discussion about using a high side current mirror and measuring the base voltage, please see a discussion in GitHub.