In this tutorial, we are learning how to set up a keypad matrix with an Arduino. We use both type keypads i.e 4×3 keypad and 4×4 keypad. The output is shown in the serial monitor.
Keypads are used to giving outputs like passwords, menu navigation, gaming control, etc.
A 4×4 keypad has 4 rows and 4 columns whereas 4×3 keypad has 4 rows and 3 columns.
- Keypad Matrix
- Jumper Wires
Working of Keypad Matrix
When we pressed a key it closes the switch and allows the current flow between column and row pin.
- Normally when no button is pressed all the row pins are held LOW and all the column pins are held HIGH.
- When the button is pressed the column is held at LOW.
- Now Arduino knew the column button, its time to find the row from the button is. Now the row pins switched to HIGH
- When the column pin rises again HIGH, Arduino finds the row pin that is connected to the button.
Pin Connection of Keypad with Arduino
Connect the Keypad pins with Arduino as follow. Skip the last one for the 4×3 keypad matrix.
|Keypad Pins||Arduino Pins|
Circuit Diagram of Keypad Matrix with Arduino
Code for 4×4 Keypad
Upload the below code and open the serial monitor. Now press keys and you can see the output key in the serial monitor.
Code for 4×3 Keypad Matrix
If you are using a 4×3 Keypad matrix than upload the below code.