-1

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 Wiring that I used to connect the pins Close up of the pins wire diagram

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.

asked Dec 12, 2022 at 23:16
3
  • Your pictures are useless to me, post a real schematic as to how you have it wired. I know first hand the keyboards will work if connected correctly to a good UNO. Be sure to show the keyboard in the schematic and properly label rows and columns. Commented Dec 13, 2022 at 0:51
  • Are those pins soldered onto the keypad? The connection looks a bit dodgy from the photo. Commented Dec 13, 2022 at 5:45
  • Hi Gil, I have included a schematic, however, I could only find a 4x4 keypad so just ignore the connection to pin 2. Hi Nick, yes they are soldered onto the keypad. Commented Dec 13, 2022 at 7:26

1 Answer 1

2

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.

Diagram showing what connections are for rows and which ones are for columns

answered Dec 13, 2022 at 8:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.