Why is my Keypad not working with 5x5?

Hello,
I have a custom made 5x5 Button Matrix. If I code 4 rows it is working fine, but as soon as I add the fith row nothing is working at all. Here is my code:

#include <Keypad.h>

const byte COLS = 5;
const byte ROWS = 5;


char hexaKeys[ROWS][COLS]={
{'O','N','M','L','K'},
{'J','I','H','G','F'},
{'E','D','C','B','A'},
{'9','8','7','6','5'},
{'4','3','2','1','0'},
};

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

Keypad pad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() 
{
  Serial.begin(9600);              
  Serial.println("Connected");
  pad.setHoldTime(100);              
  pad.setDebounceTime(50);
}

void loop() 
{
  char key = pad.getKey();
  pad.getState();
    if (key) {
    Serial.println(key);  
  }

}


Whilst I only have a 4x4 keypad it works fine if I use your code for a 5x5 keypad and I can see nothing obvious wrong with your code

Check your wiring very carefully

1 Like

I will take a SWAG since I have no knowledge of that library, have you declared the additional pins in the setup portion of your code? I assume the library does not do that for you.

The fact that the OP didn’t worry about pin modes in setup and had success with a 4x4 keypad is a clue.

The source code for the library provides another; the pin modes are set variously at this low level during scanning.

So probably not the problem.

a7

What board are you using?
You could try the code in post #16 here to help isolate the problem:

I am using the original nano.

I did multiple times, but for me it must have somerhing to do with the code, because If I remove the first row, then the keypad works fine with 4x5. As soon as I add the row not a single key is working

As an experiment comment out the calls to

  pad.setHoldTime(100);              
  pad.setDebounceTime(50);
and
 pad.getState();

Does the sketch behave any differently ?

Who made? Can you share a picture and a diagram? It awfully sounds like it's a problem with your matrix wiring.

What kind of switches are you using?

a7

The Keypad library supports up to 10 rows and 16 columns (source).

Wokwi uses the same Keypad library, but the Wokwi element for a membrane keypad can not do 5x5 (source).
So I put 25 buttons in a matrix. It works as it is supposed to do :+1:
You can test it here:

I have to agree with the others: something is wrong with the wiring or with the keypad itself. If you checked the wiring, then there must be something wrong with the keypad. Can you show a photo of it or a x-ray of the keypad :stuck_out_tongue_winking_eye:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.