Codey OnlineArduino & ESP32 component library › Keypad 4x4
Keypad 4x4
Sensors

Keypad 4x4

Keypad with 4x4 buttons 123A 456B 789C *0#D

Width: 64.5 mm

Pinout — Keypad 4x4

Pin Signal Description
C1 digital Colimn 1
C2 digital Column 2
C3 digital Column 3
C4 digital Column 4
R1 digital Row 1
R2 digital Row 2
R3 digital Row 3
R4 digital Row 4

Example wiring diagram — Keypad 4x4

From To Wire
board:D9 x1:C1 green
board:D8 x1:C2 blue
board:D7 x1:C3 yellow
board:D6 x1:C4 purple
board:D5 x1:R1 cyan
board:D4 x1:R2 magenta
board:D3 x1:R3 brown
board:D2 x1:R4 pink

Example Arduino code — Keypad 4x4

This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {9, 8, 7, 6};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.println("4x4 Keypad example");
  Serial.println("Press a key on the keypad to see it in the Serial Monitor.");
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    Serial.print("Key pressed: ");
    Serial.println(key);
  }
}

Related components

18650 Battery Shield with USB-C Charger and 5V Boost Converter

18650 Battery Shield with USB-C Charger and 5V Boost Converter

2.4 inch OLED Display I2C 3.3V

2.4 inch OLED Display I2C 3.3V

3.5 inch TFT LCD Shield

3.5 inch TFT LCD Shield

50kg Load Cell Weight Sensor

50kg Load Cell Weight Sensor

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free