Today I got the HC-548 keypad in the mail, so it’s time to play with it and find out how it works! Another day, another gadget!
These little keypads are practically a matrix of switches. No matter if they are the same as the HC-548 or with a different layout (usually without the A, B, C, D buttons on the 4th row), or even thicker, made of metal and so on, these keypads have a number of pins equal to the sum of their rows and columns.
So, for the HC-548 keypad in particular, we have 4 rows and 4 columns, which gives us a total of 8 pins. For other keypads without the letters on the 4th column, we have 4 rows and 3 columns, which is 7 pins.
Now usually, the layout of the pins is as shown in this last picture. From left to right, each pin stands for each row first, then for each column. On the HC-548 we have the following pins in this order: Row 1, row 2, row 3, row 4, column 1, column 2, column 3, column 4.
Connecting the HC-548 keypad to an Arduino UNO R3
Initially, if you haven’t done so yet, you will need to install the keypad.h library on the Arduino IDE. Go to Sketch → Include Library → Manage Libraries, and in the top right hand corner of the window which will appear, enter “keypad” in the search field. In the results choose Keypad and click on the Install button. Done.
To connect the HC-548 keypad, we need to use one digital pin for each row and each column, so for this experiment we will need 8 empty pins. In this example I use digital pins 2 to 9. Connecting it is really easy you don’t even need ground or a voltage.
Start at pin number 3 on the Arduino and connect the first pin of the keypad (row 1) to it. Continue with rows 2-4 in order and then connect the column pins one by one starting from column 1. That was it.
The following sketch will read the button you press and output it on the serial port (baud rate 9600):
And there you have it! How are you going to use your matrix keypad? Door password? Something cooler? Let us know in the comments!