This tutorial is part of: Keypad
All keypad videos are listed here.
How to use 4x4 Soft Keypad with Arduino
In this tutorial, we will explore how to connect and use a 4x4 soft keypad with an Arduino. This keypad features sixteen keys but only requires eight pins for connection, making it a compact and efficient input device for various projects. By the end of this guide, you'll be able to read inputs from the keypad and trigger actions based on those inputs.

We will be utilizing the Keypad library to interface with the keypad, allowing us to easily detect which key is pressed. The program we will implement will display the pressed key on the serial monitor and take action when a specific key is pressed, such as key '4'. For more visual guidance, be sure to check the video at (in video at 00:00).
Hardware Explained
The main component of this project is the 4x4 soft keypad, which consists of 16 buttons arranged in a grid. Each button connects to a specific pin on the Arduino, allowing it to detect when a button is pressed. The keypad operates using a matrix scanning method, where the rows and columns are activated in sequence to determine which key is pressed.
To connect the keypad, you'll need to use eight digital pins on the Arduino. The rows are typically connected to pins 2 through 5, while the columns connect to pins 6 through 9. This arrangement allows the Arduino to read the state of each key effectively.
Datasheet Details
| width | 69mm |
|---|---|
| Length | 76mm |
| Cable length | 84mm |
| Connector width | 20mm |
| Connector hole spacing | 2.56mm |
- Ensure proper wiring of row and column pins to avoid misreads.
- Use pull-up resistors if necessary to stabilize input readings.
- Debounce keys in software to avoid multiple readings for a single press.
- Test each key individually to ensure functionality.
- Keep the keypad dry and clean to maintain performance.
Wiring Instructions

To wire the 4x4 keypad to the Arduino, connect the row pins of the keypad to the digital pins on the Arduino as follows: connect the first row to pin 2, the second row to pin 3, the third row to pin 4, and the fourth row to pin 5. For the column pins, connect the first column to pin 6, the second column to pin 7, the third column to pin 8, and the fourth column to pin 9.
This setup allows the Arduino to scan through the rows and columns efficiently. Make sure to double-check the connections to ensure each pin corresponds correctly to its designated row or column. In the video, alternative wiring configurations are briefly discussed (in video at 01:15). If you choose to wire differently, simply update the pin numbers in the code accordingly.
Code Examples & Walkthrough
In the code, we start by including the Keypad library and defining the layout of the keypad. The rows and columns are set up using arrays, where rowPins maps to the digital pins connected to the rows and colPins maps to the columns.
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
In this excerpt, we define the number of rows and columns, as well as the character layout of the keys. This setup is crucial for identifying which key is pressed based on the row and column activated.
void setup(){
Serial.begin(9600);
}
The setup function initializes the serial communication at 9600 baud rate. This is important for sending keypress data to the serial monitor for debugging and verification.
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
if (key =='4'){
Serial.println("Key 4 is pressed");
}
}
In the loop function, we continuously check for a pressed key using keypad.getKey(). If a key is pressed, it prints the key value to the serial monitor. Additionally, if key '4' is pressed, it prints a specific message indicating that key '4' has been activated. This section of the code allows for real-time interaction based on user input.
Demonstration / What to Expect
Once everything is set up and the code is uploaded to your Arduino, you should see the pressed keys displayed in the Serial Monitor. If you press key '4', the message "Key 4 is pressed" will appear, confirming that the input was successfully detected. Be cautious of common pitfalls, such as floating inputs or incorrect wiring, which can lead to erroneous readings (in video at 02:30).
Video Timestamps
- 00:00 - Introduction to the keypad
- 01:15 - Wiring instructions
- 02:30 - Code explanation and demonstration
This tutorial is part of: Keypad
- Using 4x3 Keypad with Arduino
- Arduino Code and Video for a Four-Key Keypad
- Arduino Code and Video: 4x4 Matrix Black Keypad
- Build a Simple Electronic Lock with Keypad and LCD Using Arduino
- Controlling an 8-channel relay with a 4x3 keypad
- How to Use a 5x4 20-Key Keypad with Arduino to Detect Strings
- Lesson 67: Controlling an 8-Channel Relay with a Keypad Using Arduino
- 1602 LCD Keypad Shield: Basic Code
Things you might need
-
AmazonPurchase 4x4 keypad from Amazonamzn.to
-
AliExpressPurchase soft keypad from Aliexpresss.click.aliexpress.com
Resources & references
No resources yet.