Learn how to interface a 4×3 membrane matrix keypad with Arduino using this comprehensive tutorial. By following the steps outlined below, you can easily connect the keypad to your Arduino and start using its 12 buttons with only 7 pins on the microcontroller.
Features of the 4x3 Matrix Keypad
Keypads are one of the most popular components that are widely used in electronics. Everybody can communicate with the system by switches. Normally, every key occupies one digital pin of the microcontroller. But by using a 3×4 keypad you can reduce the occupied pins. With this module, you can use all 12 switches by occupying only 7 pins of the microcontroller.
How it works
The Keypad 4×3 features a total of 12 buttons in Matrix form. Consider 4 rows as input and 3 columns as output. Each switch is connected from one side to a row and from the other side to a column. For example, if we press switch number 1, the input of this row is saved at the output of its column. The image below shows the internal circuit of this keyboard.
4x3 Matrix Keypad Pinout
This module has 9 pins:
- ROW1: Input pin – Row 1
- ROW2: Input pin – Row 2
- ROW3: Input pin – Row 3
- ROW4: Input pin – Row 4
- COL1: Output pin – Column 1
- COL2: Output pin – Column 2
- COL3: Output pin – Column 3
- NC: Not used
You can see the pinout of this module here.
Interfacing 4x3 Matrix Keypad with Arduino
Step 1: Circuit
The following circuit shows how you should connect Arduino to this module. Connect wires accordingly.
Step 2: Installing Library
Search for Keypad in the Arduino Library section and install it, as shown.
Step 3: Code
Upload the following code to Arduino.
/* 4x3-Membrance-Matrix-Keypad modified on 15 Nov 2020 by Amir Mohammad Shojaee @ Electropeak
First, the Keypad library is included. Then you have to enter the number of columns and rows of keypads. A two-dimensional array of columns and rows is defined to display the character of each switch. Note that only characters are displayed in this code. In the next step 5 parameters are defined in the Keypad command. Then the “getkey()” command checks to see which switches are pressed. Finally, the compressed switch character appears in the Serial Monitor.
The output is as follows. As you can see, switches (first to the end) are pressed one after another and a special character for each is displayed on the Serial Monitor.