What can you do with a bunch of buttons and a few resistors? How about a keypad for your next microcontroller project.
Keypad Schematic and Explanation
The following is a 3×3 keypad that could easily be extended to more keys, when a button is pressed the resistors in that button’s column and row form a voltage divider with the 10k resistor below. The cool thing about this keypad is that it would only require one pin of a micronctroller.
The output (Vout) is taken at the 10k resistor. The output can then be fed to a microcontroller A/D or any other circuit that can read different voltages, because each button produces a unique combination of resistors the output will be different for every button.
In my original design I had a 6k and 2k resistors, these were replaced with 3.9K and 2.2k and 2.2k respectively because I did not have 6k nor 2k in my resistor box. A picture of the circuit in real life is shown below.
Keypad Output Table
Using a 10bit A/D converter the output of this keypad is the following.
|Key||Bit Value In Decimal||Analog (V)||Analog Expected(V)|
Note that because the resistors actual value vary so does the output but they still fall within a range that is different for each button. The bit value to analog conversion was done using the formula
In our circuit the formula,assuming a 10 bit A/D converter, translates to
The expected analog value was calculated using the voltage divider formula for each button where
Possible Microcontroller Implementation
If you want to implement this keypad in a microcontroller connect its output to an analog pin of the micro and use the following conditions in a function to differentiate the keys, note that I left more margin for possible errors from the readings above.
if(voltage>=550 && voltage<=570) return 1; else if(voltage>=645 && voltage<670) return 2; else if(voltage>=830 && voltage<=845) return 3; else if(voltage>=590 && voltage<=610) return 4; else if(voltage>=700 && voltage<=725) return 5; else if(voltage>=920 && voltage<=940) return 6; else if(voltage>=620 && voltage<=640) return 7; else if(voltage>=760 && voltage<=775) return 8; else if(voltage>=1000 && voltage<=1023) return 9;
How can we improve this circuit? leave your comments or questions below.