Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Project 23: 4×4 Keypad

Introduction

The 4×4 Membrane Keypad is a simple user interface device with 16 keys arranged in 4 rows and 4 columns. Each key press connects a unique row-column pair, which the Arduino can detect. It’s ideal for projects requiring password input, menu navigation, or number entry. In this tutorial, we’ll learn how to connect the 4×4 keypad to an Arduino and read key presses.

Required Components

  • Arduino UNO
  • 4×4 Keypad
  • Jumper wires
  • Breadboard (optional)

Pinout

Circuit Diagram / Wiring

  • Keypad  Column 4 → D2 (Arduino)
  • Keypad  Column 3 → D3 (Arduino)
  • Keypad  Column 2 → D4 (Arduino)
  • Keypad  Column 1 → D5 (Arduino)
  • Keypad  Row 4 → D6 (Arduino)
  • Keypad  Row 3 → D7 (Arduino)
  • Keypad  Row 2 → D8 (Arduino)
  • Keypad  Row 1 → D9 (Arduino)

Programming With Arduino

#include <Keypad.h>
const byte numRows = 4; // Number of rows
const byte numCols = 4; // Number of columns
char keys[numRows][numCols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[numRows] = {9, 8, 7, 6}; // Row pin numbers
byte colPins[numCols] = {5, 4, 3, 2}; // Column pin numbers
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);
void setup() {
  Serial.begin(9600);
}
void loop() {
  char key = keypad.getKey();
  if (key != NO_KEY) {
    Serial.println(key);
    delay(200); // Debounce delay
  }
}

Open the Serial Monitor

  1. Connect your Arduino to the computer and upload the code.
  2. Open the Serial Monitor in the Arduino IDE by going to Tools > Serial Monitor or pressing Ctrl+Shift+M.
  3. Set the baud rate to 9600 in the Serial Monitor.

Explanation

  • The Keypad library detects which key is pressed by scanning row and column combinations.
  • When a key is pressed, its corresponding character is printed to the Serial Monitor.
  • A small delay is added to avoid multiple detections of the same key press (debouncing).

Testing and Troubleshooting

  • Press any key and check if the correct character appears on the Serial Monitor.
  • If nothing shows, verify wiring and make sure rows/columns match your code.
  • If multiple or wrong keys are detected, check for loose connections or incorrect pin mapping.

    Leave a Reply

    Your email address will not be published.

    Need Help?