Till now we learn how to give input to arduino/MCU and how to take output as well. Even we learn how to display pre-stored messages on LCD screen. But that is not the end. Isn’t cool if are able to show message not we defined in our program but after uploaded of 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, this is similar concept we used in keypad phones like Nokia 1100.
Keypad/Keyboard is most widely used as input device. Generally Used with microcontroller and microprocessor based devices. In this section we will discuss about “4×3” matrix keypad and 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 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 key has been pressed then its corresponding column will give 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 previous chapter, here we used of 4.7 K ohm.
LOGIC BEHIND KEY DETECTION OF KEYPAD 4×3
First let understand logic to detect key and print numbers of first row, as we 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 of Row 1 passes through C1 line (same logic we used in reading input from a switch (interface of switch as input)).
Row 1 should be LOW, so that microcontroller can detect logic (as we know from both side high logic will not lead 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 R1 keys
- R1 → LOW
- R2 → HIGH
- R3 → HIGH
- R4 → HIGH
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 ‘#’