The circuit has a 4 x 4 = 16 button that connect any two lines at the intersection point @node once it is pressed. In order to detect which button is pressed, for example, you pressed button[1,1] ,you set pin A as output High, and set pin 1 as input, and you will readily detect the the high at pin 1 which indicate that button one is pressed.
Consequently, you can produce a scanning function, that changes any output pin high at a time, and detect one input pin at a time. This scanning function can be perform routinely to scan whether a button is pressed.
Multiple Pressed Detection
Lets imagine there is three button pressed. The three button is respectively button node (2,B), node (3,B), and node (4,B). So the scanning can be done by applying logic high at output B, and then input 2, 3 and 4 will detect a logic high, thus the button pressed is known.
Lets imagine again, three more button is pressed, but this time, node (2,B), node (2,C) and node (2,D). The scanning can be done by setting pin 2 as output, and applying logic high at pin 2, with pin B, C and D as input, you will readily detect the three button is pressed.
But there is a problem with this kind of scanning. This effect is also commonly known as ghosting.
This is because all the button that are pressed connect all the lines and row that are connected, thus as long as any one of the row is high, the row or column will also be high.
To overcome this problem, adding extra circuitry will solve the problem easily. By adding an diode in series with all the button side by side is said to solve the problem well enough.
Using voltage ladder to read button input : Keypad using ADC method
ADC for short stand for Analog-Digital-Converter. To detect button pressed, you can also utilize ADC peripheral which is commonly available in microcontroller. The advantages of using this kind of configuration is that it only use up 1 pin, with condition that pin from the particular microcontroller must support ADC peripheral. This configuration can also be used to detect multiple pressed, but with appropriate value for each resistor. The circuit is shown as below.
To make life easier, you can also form a 'REAL' resistor ladder.
The connection is as the figure on the left. By this way you can have same value for all resistor and also add as much segment as you like, but be sure not to add too much resistor and 'starve' your microcontroller. The only weakness with this kind of connection is you can only have one button pressed on a time.
So, what are you waiting for, if you want to try one of those method why not go prepare the hardware now after reading such a looooong article. Stay tuned for more updates.
For more information, please visit the link below.
Most of the picture above are also taken from the website below.
You might also find this site informative.
Inspiring Creative and Innovative Minds
Chai Jun Kong
Faculty of Electrical Engineering
Universiti Teknologi Malaysia