Ordinato entro le 14:00 nei giorni lavorativi = spedito in giornata 30 giorni per il recesso Garanzia di 1 anno
← Torna alla panoramica

Schema di collegamento ed esempio di codice

Ecco come collegare il Tastierino a matrice 4x4 nero a un Arduino UNO o ESP32, con uno sketch di esempio che puoi caricare subito.

Lettore di input per tastierino a matrice 4x4

Questo progetto mostra come leggere gli input da un tastierino a matrice 4x4 usando un Arduino Uno. Quando viene premuto un pulsante del tastierino, il carattere corrispondente viene stampato direttamente nel Serial Monitor a 115200 baud.

Schema di collegamento: Tastierino a matrice 4x4 nero su un Arduino UNO
Schema di collegamento · Clicca per ingrandire
Tabella di collegamento: Tastierino a matrice 4x4 nero su un Arduino UNO
Tabella di collegamento · Clicca per ingrandire
4x4_Matrix_Keypad_Input_Reader.ino · compilato e testato
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 4x4 Matrix Keypad Input Reader
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Keypad 4x4
 *  Libraries : Keypad 3.1.1
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

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

void setup() {
  Serial.begin(115200);
  Serial.println(F("4x4 Keypad Demo"));
  Serial.println(F("Press any key on the keypad..."));
}

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

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

Librerie necessarie: Keypad 3.1.1

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Lettore di tastierino a matrice 4x4 per ESP32

Questo circuito collega direttamente un tastierino a matrice 4x4 ai GPIO dell’ESP32. La Keypad library scansiona le righe e le colonne della matrice usando resistori di pull-up interni. Premendo un tasto, il suo carattere viene stampato in tempo reale nel Serial Monitor.

Schema di collegamento: Tastierino a matrice 4x4 nero su un ESP32 DevKit V1
Schema di collegamento · Clicca per ingrandire
Tabella di collegamento: Tastierino a matrice 4x4 nero su un ESP32 DevKit V1
Tabella di collegamento · Clicca per ingrandire
ESP32_4x4_Matrix_Keypad_Reader.ino · compilato e testato
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : ESP32 4x4 Matrix Keypad Reader
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Keypad 4x4
 *  Libraries : Keypad 3.1.1
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#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] = {19, 18, 5, 4};
byte colPins[COLS] = {13, 12, 14, 27};

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

void setup() {
  Serial.begin(115200);
  Serial.println("4x4 Keypad Test Ready. Press any key...");
}

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

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

Librerie necessarie: Keypad 3.1.1

Wiring diagram and example code generated by Codey.online — https://www.codey.online