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.
-
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.Gil– Gil2022年12月13日 00:51:13 +00:00Commented Dec 13, 2022 at 0:51
-
Are those pins soldered onto the keypad? The connection looks a bit dodgy from the photo.Nick Gammon– Nick Gammon ♦2022年12月13日 05:45:08 +00:00Commented 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.Campbell White– Campbell White2022年12月13日 07:26:12 +00:00Commented Dec 13, 2022 at 7:26
1 Answer 1
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
Explore related questions
See similar questions with these tags.