user82353: I'm trying to program a mechanical keyboard running on the Arduino Pro Micro (5V/16MHz). I'm using a matrix approach (4x12), and while I believe the code and the wiring (both of which I've checked multiple times) are correct, I can't get the first two rows to work no matter what. I've tried wiring it up to other pins, which works, but only for two rows at a time, when I hook up all the 4 rows, the two ones on top don't work. The code:
/*cols and rows*/
byte rows[] = {2,3,4,5};
const int row_Count = 4; 
byte cols[] = {6,7,8,9,10,14,15,16,18,19,20,21};
const int col_Count = 12;

byte keyboard[col_Count][row_Count];

void read_layout() {
    /*do the columns*/
    for (int col_Index=0; col_Index < col_Count; col_Index++) {
        /*setup for registering the column state*/
        byte cur_Col = cols[col_Index];
        pinMode(cur_Col, OUTPUT);
        digitalWrite(cur_Col, LOW);
 
        /*do the rows*/
        for (int row_Index=0; row_Index < row_Count; row_Index++) {
            byte row_Col = rows[row_Index];
            pinMode(row_Col, INPUT_PULLUP);
            keyboard[col_Index][row_Index] = digitalRead(row_Col);
            pinMode(row_Col, INPUT);
        }
        /*disable the column*/
        pinMode(cur_Col, INPUT);
    }
}
 
void print_layout() {
    for (int row_Index=0; row_Index < row_Count; row_Index++) {
        Serial.print(row_Index); 
        Serial.print(F(": "));
 
        for (int col_Index=0; col_Index < col_Count; col_Index++) {  
            Serial.print(keyboard[col_Index][row_Index]);
            if (col_Index < col_Count) Serial.print(F(", "));
        }   
        Serial.println("");
    }
    Serial.println("");
}

void setup() {
    Serial.begin(115200);
    delay(2000);
    /*init the rows*/
    for(int i=0; i<row_Count; i++) {
        pinMode(rows[i], INPUT);
    }
    /*init the cols*/
    for (int i=0; i<col_Count; i++) {
        pinMode(cols[i], INPUT_PULLUP);
    }     
}

void loop() {
    read_layout();
    print_layout();
            
}

This is the schematic, a "dirty sketch":


user60431: You are using the diodes in series, which leads to accumulating forward voltages in the lower rows of your schematic. Because of this accumulation the threshold for "low" will not be crossed, and the input pin cannot recognize a pressed key.
Instead, you should adopt this circuit (copied from "Keyboard Matrix Help" by Dave Dribin). Of course, you will put the cathods on your columns pins, and the anodes on the keys.

So the right circuit uses each diode-and-key combination in parallel, not in series.

82353: <p>I'm trying to program a mechanical keyboard running on the Arduino Pro Micro (5V/16MHz). I'm using a matrix approach (4x12), and while I believe the code and the wiring (both of which I've checked multiple times) are correct, I can't get the first two rows to work no matter what. I've tried wiring it up to other pins, which works, but only for two rows at a time, when I hook up all the 4 rows, the two ones on top don't work. The code:</p>
<pre class="lang-cpp prettyprint-override"><code>/*cols and rows*/
byte rows[] = {2,3,4,5};
const int row_Count = 4; 
byte cols[] = {6,7,8,9,10,14,15,16,18,19,20,21};
const int col_Count = 12;

byte keyboard[col_Count][row_Count];

void read_layout() {
    /*do the columns*/
    for (int col_Index=0; col_Index &lt; col_Count; col_Index++) {
        /*setup for registering the column state*/
        byte cur_Col = cols[col_Index];
        pinMode(cur_Col, OUTPUT);
        digitalWrite(cur_Col, LOW);
 
        /*do the rows*/
        for (int row_Index=0; row_Index &lt; row_Count; row_Index++) {
            byte row_Col = rows[row_Index];
            pinMode(row_Col, INPUT_PULLUP);
            keyboard[col_Index][row_Index] = digitalRead(row_Col);
            pinMode(row_Col, INPUT);
        }
        /*disable the column*/
        pinMode(cur_Col, INPUT);
    }
}
 
void print_layout() {
    for (int row_Index=0; row_Index &lt; row_Count; row_Index++) {
        Serial.print(row_Index); 
        Serial.print(F(&quot;: &quot;));
 
        for (int col_Index=0; col_Index &lt; col_Count; col_Index++) {  
            Serial.print(keyboard[col_Index][row_Index]);
            if (col_Index &lt; col_Count) Serial.print(F(&quot;, &quot;));
        }   
        Serial.println(&quot;&quot;);
    }
    Serial.println(&quot;&quot;);
}

void setup() {
    Serial.begin(115200);
    delay(2000);
    /*init the rows*/
    for(int i=0; i&lt;row_Count; i++) {
        pinMode(rows[i], INPUT);
    }
    /*init the cols*/
    for (int i=0; i&lt;col_Count; i++) {
        pinMode(cols[i], INPUT_PULLUP);
    }     
}

void loop() {
    read_layout();
    print_layout();
            
}
</code></pre>
<p>This is the schematic, a &quot;dirty sketch&quot;:
<a href="https://archive.is/aOstH/91e28281c0bde7117145dfd7ffe3f5778a0801dd.png" rel="nofollow noreferrer"><img src="https://archive.is/aOstH/91e28281c0bde7117145dfd7ffe3f5778a0801dd.png" alt="schematic" /></a></p>
 60431: <p>You are using the diodes in series, which leads to accumulating forward voltages in the lower rows of your schematic. Because of this accumulation the threshold for &quot;low&quot; will not be crossed, and the input pin cannot recognize a pressed key.</p>
<p>Instead, you should adopt this circuit (copied from <a href="https://www.dribin.org/dave/keyboard/one_html/" rel="nofollow noreferrer">&quot;Keyboard Matrix Help&quot;</a> by Dave Dribin). Of course, you will put the cathods on your columns pins, and the anodes on the keys.</p>
<p><a href="https://i.stack.imgur.com/ySxUr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySxUr.png" alt="schematic" /></a></p>
<p>So the right circuit uses each diode-and-key combination in parallel, not in series.</p>
