2*4 matrix keyboard/8 keys independent key module

SKU: FA2137-2
Key Layout

2 × 4 Matrix (8 Keys)

Total I/O Pins Required

6 (2 Rows + 4 Columns)

Connector Type

2.54mm pitch male pin header

Board Dimensions (L × W)

34mm × 32mm (approx.)

Board Height

Approx. 4mm

Mounting Hole Diameter

3mm (M3 screws)

Switch Type

Momentary Tactile Micro-Switch

Material

FR-4 PCB with tin-plated pads

Compatibility

Arduino, ESP32, STM32, Raspberry Pi, 8051, AVR, PIC

Operating Voltage

3.3V – 5V DC

Operating Temperature

-25°C to +70°C

Product Overview

The 2×4 Matrix Keyboard Module is a compact and efficient input device featuring 8 independent tactile micro-switches arranged in a 2-row by 4-column matrix configuration . This module is specifically designed as an external keyboard expansion for single-chip microcomputers, providing a convenient alternative to using eight separate tact switches .

The matrix design is key to its efficiency. By arranging the 8 keys in rows and columns, the module requires only 6 I/O pins (2 rows + 4 columns) to read all 8 buttons, rather than 8 individual pins. This matrix scanning approach significantly conserves your microcontroller’s valuable GPIO resources, making it an excellent choice for projects where I/O pins are limited .

Pre-soldered pin headers on the module allow for immediate breadboard or jumper wire connection, eliminating the need for soldering . The PCB includes four 3mm mounting holes, enabling secure attachment to enclosures, robot chassis, or prototyping platforms.

Whether you are building a custom control panel for a robot, designing a numeric keypad for a DIY calculator, creating a menu selection interface for an automation project, or teaching students the fundamentals of keyboard scanning, this 2×4 matrix keyboard module provides a simple, reliable, and space-saving solution for direct user input to your Arduino, ESP32, STM32, or other microcontroller projects.

Key Features

  • 1×2 Matrix Layout: 8 individual tactile micro-switches arranged in 2 rows and 4 columns for intuitive numeric and functional input

  • I/O Efficient Matrix Design: Requires only 6 GPIO pins (2 rows + 4 columns) to read 8 buttons, significantly reducing pin usage from 8 individual pins

  • Tactile Micro-Switches: Quality pushbuttons provide positive tactile feedback with each press

  • Pre-Soldered Male Header Pins: Ready to insert into breadboards or connect with female-to-female jumper wires – no soldering required

  • Compact & Portable: Small footprint (approx. 34mm × 32mm) fits easily into tight project enclosures and is very easy to carry

  • Standard 2.54mm (0.1″) Pin Spacing: Compatible with standard breadboards, perfboards, and Dupont jumper wires

  • Mounting Holes: Four 3mm (M3) holes for secure attachment to cases, robot chassis, or panels

  • Clear Function Markings: Silkscreen labels on the PCB indicate each key’s position and connection points, simplifying wiring

Technical Specifications

Parameter Operating Value
Key Layout 2 × 4 Matrix (8 Keys)
Total I/O Pins Required 6 (2 Rows + 4 Columns)
Connector Type 2.54mm pitch male pin header
Board Dimensions (L × W) 34mm × 32mm (approx.)
Board Height Approx. 4mm
Mounting Hole Diameter 3mm (M3 screws)
Switch Type Momentary Tactile Micro-Switch
Material FR-4 PCB with tin-plated pads
Compatibility Arduino, ESP32, STM32, Raspberry Pi, 8051, AVR, PIC
Operating Voltage 3.3V – 5V DC
Operating Temperature -25°C to +70°C

Pinout & Connection Guide

Pin Definitions

The module uses a 6-pin interface. The exact order of row and column pins may vary between manufacturers; always verify the silkscreen on your specific board.

Pin Label Function Description
R1 / Row 1 Row Line 1 Connects to first row of buttons (Keys 1-4)
R2 / Row 2 Row Line 2 Connects to second row of buttons (Keys 5-8)
C1 / Col 1 Column Line 1 Connects to first column of buttons
C2 / Col 2 Column Line 2 Connects to second column of buttons
C3 / Col 3 Column Line 3 Connects to third column of buttons
C4 / Col 4 Column Line 4 Connects to fourth column of buttons

Wiring to Arduino Uno

Module Pin Arduino Uno Pin
Row 1 Digital Pin 9
Row 2 Digital Pin 8
Col 1 Digital Pin 7
Col 2 Digital Pin 6
Col 3 Digital Pin 5
Col 4 Digital Pin 4

How the Matrix Works

In a matrix keyboard, each key connects a specific row and column . When no key is pressed, all row and column lines are electrically isolated. When a key is pressed, it connects its row and column lines together, creating a closed circuit that the microcontroller can detect by scanning the matrix.

The microcontroller activates one row at a time (sets it HIGH) and reads the states of all column pins. If a key in that row is pressed, the corresponding column pin will read HIGH. By quickly cycling through all rows and checking all columns, the microcontroller can determine exactly which key (if any) is pressed – all using just rows + columns I/O pins .

Usage Guide

Software Setup (Arduino IDE)

Step 1: Install the Keypad Library

The Keypad library by Mark Stanley and Alexander Brevig handles all matrix scanning and debouncing automatically.

  1. Open Arduino IDE → Sketch → Include Library → Manage Libraries

  2. Search for “Keypad”

  3. Find the library by Mark Stanley, Alexander Brevig and click Install

Step 2: Basic Test Sketch

cpp
#include <Keypad.h>

// Define the number of rows and columns
const byte ROWS = 2;  // Two rows
const byte COLS = 4;  // Four columns

// Define the symbols printed on the keypad buttons
char keys[ROWS][COLS] = {
  {'1','2','3','4'},
  {'5','6','7','8'}
};

// Define the Arduino pins connected to the module's rows and columns
byte rowPins[ROWS] = {9, 8};    // R1, R2
byte colPins[COLS] = {7, 6, 5, 4};  // C1, C2, C3, C4

// Create the Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  Serial.println("2x4 Matrix Keyboard Ready. Press any key...");
}

void loop() {
  char key = keypad.getKey();  // Check for a key press
  
  if (key) {  // If a key was pressed
    Serial.print("Key Pressed: ");
    Serial.println(key);
    
    // Add your action code here based on which key was pressed
    switch(key) {
      case '1':
        // Action for key 1
        break;
      case '2':
        // Action for key 2
        break;
      // Add more cases for keys 3-8 as needed
    }
  }
}

Step 3: Connecting Without the Library

If you prefer not to use the library, you can implement matrix scanning yourself:

cpp
// Define row and column pins
int rowPins[] = {9, 8};
int colPins[] = {7, 6, 5, 4};

void setup() {
  Serial.begin(9600);
  
  // Set row pins as outputs, initially LOW
  for (int i = 0; i < 2; i++) {
    pinMode(rowPins[i], OUTPUT);
    digitalWrite(rowPins[i], LOW);
  }
  
  // Set column pins as inputs with pull-ups
  for (int i = 0; i < 4; i++) {
    pinMode(colPins[i], INPUT_PULLUP);
  }
}

void loop() {
  for (int row = 0; row < 2; row++) {
    // Set the current row HIGH
    digitalWrite(rowPins[row], HIGH);
    
    // Check each column
    for (int col = 0; col < 4; col++) {
      if (digitalRead(colPins[col]) == LOW) {
        // Key pressed: calculate key number and break
        int keyNumber = row * 4 + col + 1;
        Serial.print("Key ");
        Serial.println(keyNumber);
        delay(200);  // Simple debounce
      }
    }
    
    // Reset the row to LOW before moving to the next row
    digitalWrite(rowPins[row], LOW);
  }
  
  delay(50);  // Small delay between scans
}

Raspberry Pi (Python) Setup

For Raspberry Pi, you can use the pad4pi library:

python
from pad4pi import rpi_gpio
import time

# Define key mapping
KEY_MAP = [
    ["1", "2", "3", "4"],
    ["5", "6", "7", "8"]
]

# Define GPIO pins connected to rows and columns
ROW_PINS = [9, 8]      # GPIO pins for rows
COL_PINS = [7, 6, 5, 4]  # GPIO pins for columns

factory = rpi_gpio.KeypadFactory()
keypad = factory.create_keypad(keypad=KEY_MAP, row_pins=ROW_PINS, col_pins=COL_PINS)

def print_key(key):
    print(f"Key Pressed: {key}")

keypad.registerKeyPressHandler(print_key)

try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    keypad.cleanup()
Q: How many I/O pins does this module require on my microcontroller?

The matrix design requires 6 I/O pins: 2 row pins and 4 column pins . This is significantly more efficient than connecting 8 independent switches, which would require 8 individual pins.

Q: Can I use this module with a 3.3V microcontroller like ESP32 or Raspberry Pi?

Yes, the module works with both 3.3V and 5V logic systems. The micro-switches are passive components, so voltage compatibility depends on your pull-up configuration. For 3.3V systems, enable internal pull-ups (INPUT_PULLUP) or use external 4.7kΩ – 10kΩ resistors to VCC (3.3V).

Q: How do I know which pin is for which row or column?

The PCB typically has silkscreen labels indicating R1, R2, C1, C2, C3, C4. If the labels are not present, use a multimeter in continuity mode to trace which pins connect to which keys and determine the matrix layout.

Q: What is the "matrix" design and why is it used?

The matrix design arranges switches in a grid of rows and columns . Instead of each key having its own dedicated input pin, the microcontroller scans the grid by activating one row at a time and reading the columns. This allows 8 keys to be read using only 6 pins instead of 8.

Q: Can I connect more than one of these modules to a single microcontroller?

Yes, but each module requires its own set of row and column pins. If you need many keys, consider an 8×8 matrix or use an I/O expander (like PCF8574 or MCP23017) to communicate via I2C, which uses only 2 pins regardless of how many keys you add.

Q: Why does my keypad register random or multiple presses?

This is usually contact bounce. Mechanical switches “bounce” when pressed, creating multiple rapid signal changes. The solution is debouncing – ignoring signals for a short period (typically 10-50ms) after the first detection. The Keypad library includes built-in debouncing, or you can implement delay-based debouncing in your code.

Q: Can I change what each key does without changing the wiring?

Absolutely! The key mapping is defined entirely in software. In the keys[][] array, you can assign any characters or values to each button position – letters, numbers, commands, or function calls. The physical wiring only determines which button is connected to which row/column intersection.

Q: What is the purpose of the mounting holes?

The four 3mm holes allow you to securely screw the module into enclosures, project boxes, robot chassis, or control panels . This prevents the module from moving around during use and ensures reliable operation.

Q: Does this module have pull-up resistors included?

Most basic matrix keyboard modules do not include onboard pull-up resistors. You should enable the microcontroller’s internal pull-ups using pinMode(pin, INPUT_PULLUP) in Arduino, or add external 4.7kΩ – 10kΩ resistors for more reliable operation, especially with longer wires.

Q: What's the difference between a matrix keypad and independent switches?

Matrix Keypad: Shares rows and columns, requires scanning logic, uses fewer pins, best for many buttons (8-64+). Independent Switches: Each switch has its own pin, no scanning required, simple code but uses many pins. This module uses the matrix design for pin efficiency while being compact and easy to use .