- Published: Tuesday, 21 May 2013
- Written by Jon Chandler
Aruna Rubasinghe - May 8, 2013
This is a repost from EDN Magazine's Design Ideas
Matrix keyboards are common as an input device in microcontroller-based projects. A conventional way of connecting a matrix keyboard to a microcontroller is to use multiple I/O pins of the MCU. The MCU then uses a scanning algorithm to identify which keys are pressed. A drawback of this method is that it requires a large number of the MCU’s I/O pins to connect the keyboard. For example, to connect a 4×3 keyboard requires seven digital I/O pins. This becomes a problem when the project is based on a low-pin-count MCU or when the MCU being used does not have enough free I/O pins.
Two solutions for this issue are available: Use readily available I/O expanders, or assign a unique voltage to each key using a resistor network and then use an analog pin to read the voltage and determine which key is pressed. Each solution has its own disadvantages.
Since most of the time I/O expanders require a special communication protocol (I2C or SPI, for example) to read and write data, the MCU should have built-in communication modules, or the user has to implement the relevant communication-protocol software wisely, which adds significantly to the overhead of the MCU. On the other hand, assigning a unique voltage to each key using a resistor network becomes troublesome as the number of keys becomes high, which will lead to tight voltage margins. Then, as resistor values tend to change with temperature, the use of tight voltage margins can cause incorrect readings. Even switch bouncing can play a major role in producing incorrect voltages with this method. Another major drawback of this method is that it requires the presence in the MCU of an analog input pin.Discuss this article in the forums (0 replies).