Search code examples
cmatrixarduinokeypad

Matrix keyboard 4*4 arduino


I have a problem with keyboard connected into 4*4 matrix. I use only 14 push buttons. The problem is that all push buttons work on Arduino Mega. On Uno works only 3,4 - 5,6 - B,C. I don't understand why it doesn't work. Could someone help me? Thank you in advance.

Here is my code

    #include <Keypad.h>

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

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


byte rowPins[ROWS] = {13,12,11,10};
byte colPins[COLS] = {0,1,2,3};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  char key = keypad.getKey();
  if(key != NO_KEY){
    Serial.println(key);
  }
}

Solution

  • On an Arduino UNO pins 0 & 1 are configured for serial communication, if you use the Serial library. Try changing those pins to some of the other digital pins.

    As pure speculation, trying to read from the pins with digitalRead() or such in this state will yield a LOW and so the Keypad library will never consider the column active and so buttons that reside on those columns will never work.