Arduino matrix buttons not working,

I made a 3*5 arduino matrix buttons, used A2-A5, but not works well, actually, not response at all.

byte rows[] = {9,10,11};
const int rowCount = sizeof(rows)/sizeof(rows[0]);
 
// JP2 and JP3 are outputs
////byte cols[] = {8,9,10};

////byte cols[] = {8,16,17,18,19};

byte cols[] = {8,A2,A3,A4,A5};
const int colCount = sizeof(cols)/sizeof(cols[0]);
 
byte keys[colCount][rowCount];
 
void setup() {
    Serial.begin(9600);
 
    for(int x=0; x<rowCount; x++) {
        Serial.print(rows[x]); Serial.println(" as input");
        pinMode(rows[x], INPUT);
    }
 
    for (int x=0; x<colCount; x++) {
        Serial.print(cols[x]); Serial.println(" as input-pullup");
        pinMode(cols[x], INPUT_PULLUP);
    }
         
}
 
void readMatrix() {
    // iterate the columns
    for (int colIndex=0; colIndex < colCount; colIndex++) {
        // col: set to output to low
        byte curCol = cols[colIndex];
        pinMode(curCol, OUTPUT);
        digitalWrite(curCol, LOW);
 
        // row: interate through the rows
        for (int rowIndex=0; rowIndex < rowCount; rowIndex++) {
            byte rowCol = rows[rowIndex];
            pinMode(rowCol, INPUT_PULLUP);
            keys[colIndex][rowIndex] = digitalRead(rowCol);
            pinMode(rowCol, INPUT);
        }
        // disable the column
        pinMode(curCol, INPUT);
    }
}
 
void printMatrix() {
    for (int rowIndex=0; rowIndex < rowCount; rowIndex++) {
        if (rowIndex < 10)
            Serial.print(F("0"));
        Serial.print(rowIndex); Serial.print(F(": "));
 
        for (int colIndex=0; colIndex < colCount; colIndex++) {  
            Serial.print(keys[colIndex][rowIndex]);
            if (colIndex < colCount)
                Serial.print(F(", "));
        }   
        Serial.println("");
    }
    Serial.println("");
}
 
void loop() {
    readMatrix();
    if (Serial.read()=='!')
        printMatrix();
}

The post102.1 is the Serial Monitor.

POST102.1.JPG

Hi, A complete schematic would help here. Showing connections to Arduino.

What model Arduino are you using?

Thanks.. Tom... :)


POST102.1.JPG
Please do not post screen shots of the serial monitor. Copy text from serial monitor and paste it into your post between code tags.

    if (Serial.read()=='!')
        printMatrix();

Because of the if-statement here, the output will only appear when you enter a "!" on the serial monitor.

Hi you are declaring every pins as INPUT you need OUTPUT pins (rows) too.

Danisupra: Hi you are declaring every pins as INPUT you need OUTPUT pins (rows) too.

Please read the code in the original post.

Hi, Have you googled

arduino keypad

try this; https://playground.arduino.cc/Code/Keypad/

Tom... :)