user87979: I am trying to figure out how to use a 4x3 keypad and just want to receive the key numbers I select on the serial monitor. The problem I am getting is that some of the keys I type don't give me any output and then the keys that do provide output do not match their corresponding number. For example key 1 does not provide any output, whereas keys 3 and 4 give an output of 4 and 9 respectively. I have attached pictures of how the keypad is connected   
The code that I am using is below:
#include <Keypad.h>
 
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 3;
 
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
 
// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3};
 
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
 
void setup() {
  // Setup serial monitor
  Serial.begin(9600);
}
 
void loop() {
  // Get key value if pressed
  char customKey = customKeypad.getKey();
 
  if (customKey) {
    // Print key value to serial monitor
    Serial.println(customKey);}
}

I just need help identifying where I am going wrong and how I can fix the problem I am having. Thanks.

user87979: I determined where I was going wrong. The keypad has a different wiring compared to the traditional way of doing it. I found this this article helpful. The changes made to the code are as follows:
byte rowPins[ROWS] = {8, 3, 4, 6};
byte colPins[COLS] = {7, 9, 5};

As can be seen, the rows and columns pins need to be changed.


87979: <p>I am trying to figure out how to use a 4x3 keypad and just want to receive the key numbers I select on the serial monitor. The problem I am getting is that some of the keys I type don't give me any output and then the keys that do provide output do not match their corresponding number. For example key 1 does not provide any output, whereas keys 3 and 4 give an output of 4 and 9 respectively. I have attached pictures of how the keypad is connected <a href="https://i.stack.imgur.com/y70Yl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y70Yl.jpg" alt="Wiring that I used to connect the pins" /></a> <a href="https://i.stack.imgur.com/6OTz0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6OTz0.jpg" alt="Close up of the pins" /></a> <a href="https://i.stack.imgur.com/awCP5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/awCP5.jpg" alt="wire diagram" /></a></p>
<p>The code that I am using is below:</p>
<pre><code>#include &lt;Keypad.h&gt;
 
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 3;
 
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
 
// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3};
 
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
 
void setup() {
  // Setup serial monitor
  Serial.begin(9600);
}
 
void loop() {
  // Get key value if pressed
  char customKey = customKeypad.getKey();
 
  if (customKey) {
    // Print key value to serial monitor
    Serial.println(customKey);}
}
</code></pre>
<p>I just need help identifying where I am going wrong and how I can fix the problem I am having. Thanks.</p>
 87979: <p>I determined where I was going wrong. The keypad has a different wiring compared to the traditional way of doing it. I found this <a href="https://electropeak.com/learn/interfacing-4x3-membrane-matrix-keypad-with-arduino/" rel="nofollow noreferrer">this</a> article helpful. The changes made to the code are as follows:</p>
<pre><code>byte rowPins[ROWS] = {8, 3, 4, 6};
byte colPins[COLS] = {7, 9, 5};
</code></pre>
<p>As can be seen, the rows and columns pins need to be changed.</p>
<p><a href="https://i.stack.imgur.com/GoWUr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GoWUr.jpg" alt="Diagram showing what connections are for rows and which ones are for columns" /></a></p>
