Till now we learn how to give input to arduino / MCU and how to take the output as well. Even we learn how to display pre-stored messages on the LCD screen. But that is not the end. Isn’t cool if we can show the message not defined in our program but after uploading the program as well, like in our computer we are able to type and see the messages in the form of text. In this section we will learn 4×3 keypad operating mechanism and then display numbers on screen (4×4 keypad operating mechanism is similar to 4×3), this is a similar concept we used in keypad phones like Nokia 1100.
Keypad/Keyboard is most widely used as an input device. Generally Used with microcontroller and microprocessor based devices. In this section, we will discuss the “4×3” matrix keypad, its basic understanding is important. Here basic refers to its construction and working mechanism of key detection.
Here R1, R2, R3 & R4 refers to row 1, row 2, row 3 & row 4 respectively and C1, C2 & C3 refers to column 1, column 2 & column 3 respectively.
OPERATING MECHANISM OF KEYPAD 4X3 [ BUTTON MATRIX CONCEPT]
We can see clearly there are 12 numbers and/or characters and 12 push-buttons (switch). Each push-button is associated with each number or character.
All the columns are set to HIGH i.e. + 5V and rows to LOW i.e. ground (we can interchange columns to LOW and rows to HIGH according to our convenience, but then we need to change the programming model accordingly).
So if no key has been pressed then all columns will remain HIGH and if the key has been pressed then its corresponding column will give a LOW signal (because it shorted to ground via row). Just suppose we press ‘2’, it is in column 2 and row 1 so as we pressed ‘2’ column 2 will become from HIGH to LOW (because signal directs to the ground without any resistance) but as we release the key 2 it will again becomes high because of pull-up resistor, we read about the concept of pull-up in the previous chapter, here we used pullup resistor of 4.7 K ohm.
LOGIC BEHIND KEY DETECTION OF KEYPAD 4×3
First let us understand the logic to detect the key and print numbers of the First row, as now we have three columns and one row. So there are three possibilities
- Column 1 key pressed
- Column 2 key pressed
- Column 3 key pressed
If column 1 key has been pressed, as row R1 is output type and C1 is input to Arduino, then Arduino will read the logic (state HIGH or LOW) of Row 1 passes through C1 line (same logic we used in reading input from a switch (interface of the switch as input)).
Row 1 should be LOW, so that the microcontroller can detect logic (as we know from both sides HIGH logic will not lead to a potential difference). But if we have multiple rows then we should give logic HIGH to them (R2, R3, R4) to distinguish between R1 and other rows. In short for Row 1 keys
- R1 → LOW
- R2 → HIGH
- R3 → HIGH
- R4 → HIGH
Arduino will continuously read input pin signals, if C1 is LOW means key 1 is pressed, if C2 is LOW means key 2 is pressed and if C3 is LOW means key 3 is pressed.
A. If R1 → LOW, R2 → HIGH, R3 → HIGH and R4 → HIGH
Column 1 key pressed leads to detect ‘1’
Column 2 key pressed leads to detect ‘2’
Column 3 key pressed leads to detect ‘3’
B. If R1 → HIGH, R2 → LOW, R3 → HIGH and R4 → HIGH
Column 1 key pressed leads to detect ‘4’
Column 2 key pressed leads to detect ‘5’
Column 3 key pressed leads to detect ‘6’
C. If R1 → HIGH, R2 → HIGH, R3 → LOW and R4 → HIGH
Column 1 key pressed leads to detect ‘7’
Column 2 key pressed leads to detect ‘8’
Column 3 key pressed leads to detect ‘9’
D. If R1 → HIGH and R2 → HIGH, R3 → HIGH and R4 → LOW
Column 1 key pressed leads to detect ‘*’
Column 2 key pressed leads to detect ‘0’
Column 3 key pressed leads to detect ‘#’