# Power-Saving Keypad Controls Multiple Keys Through One MCU Pin

Traditionally, interfacing a microcontroller with an n-by-m keypad required n + m of the microcontroller’s I/O pins for keypad scanning. Keypad designs that conserve microcontroller pins have been developed, but they require additional resources, such as external ICs or a built-in analog-to-digital converter (ADC). The design presented in this article uses only a single I/O pin and requires only resistors and a capacitor as the external components.

I/O is a bidirectional pin initially configured as an input (see the figure). When no key is pressed, the capacitor is discharged and the pull-up resistor, RH, keeps I/O High. The microcontroller is in sleep mode and will wake up only when a change in I/O’s state generates an interrupt. When a key is pressed, I/O changes to Low, since the pull-down network is stronger than the pull-up. The microcontroller then wakes up to execute the following steps:

1. Wait for contact debouncing.
2. Change I/O to an output and set it High. The capacitor then starts charging to the High-state voltage. The charging time, Ti, is determined by the key pressed and its associated R (1, 2,…i).
3. Wait until T1.
4. Make I/O an input. Charging of C pauses.
5. If I/O is High, key 1 was pressed. If I/O is Low, make I/O an output and set it High to continue charging.
6. Wait until T2.
7. Make I/O an input. Charging of C pauses.
8. If I/O is High, key 2 was pressed. If I/O is Low, make I/O an output and set it High to continue charging.
9. Continue for T3 through Ti.

Resistors should be chosen to make T1

Charging time can be determined as follows: When charging pauses, the voltage at I/O is (Equation 1) where VC is the capacitor voltage (Equation 2). Equation 3 solves the charging time by equating VI/O to the switching threshold voltage VTH. Here, VTH is the switching threshold voltage for I/O.

As Ri is increased, Ti initially increases as well. But, subsequently, it reaches a maximum and starts to decrease. This imposes an upper limit on Ri and, therefore, on the number of keys that can be connected to the circuit.

Ti may vary between Ti,min and Ti,max due to resistor tolerances and variations in VTH. Consequently, the values should be chosen so that Ti,max

This design saves power in three ways. First, energy of CV2 is dissipated each time a capacitor is charged to V and discharged. In this design, charging stops as soon as I/O goes High and the capacitor is charged to about VTH (less than 2 V), rather than VDD. Second, the capacitor is charged (and discharged) only once for each key press. Finally, after determining which key was pressed, the microcontroller enters sleep mode and remains asleep until the key is released and the state of I/O changes back to High. So even when some of the keys are stuck or held down, power consumption is minimized.