3x4 Keypad matrix

I have the following keypad

I have tried testing it using the following

/*
|| Example sketch for the Addicore 4x3 matrix array 12-key membrane switch keypad,
|| found at: https://www.addicore.com/product-p/142.htm
|| After connecting your keypad to your Arduino (as detailed below) and uploading
|| this sketch to your Arduino, you can then open the Serial Monitor on your
|| computer and ensure that the baud is set to 9600. Then press any of the buttons
|| on the keypad to see the pressed button show up on the Serial Monitor.
||
|| Wire the keypad to your Arduino using information below:
|| Note: Pins one and seven on the keypad are labeled with little embossed plastic
||
|| Modified by Craig Thompson (craig@addicore.com), December 15, 2014
|| Based on CustomKeypad.pde by Alexander Brevig (alexanderbrevig@gmail.com)
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){ 
Serial.println(customKey);
}
}

However the only keys that respond are 3 which produces 8 and 8 which produces 3.

I am not sure how to proceed in working out how to wire this up.

How have you wired it up at the moment?

If I am looking down at the keypad i.e. the * is on my left and the # on my right, the left most pin is connected to 3 and the right most to 9 (Digital). I have also tried it the opposite way round.

That doesn't sound right.
I think this is the data sheet for the same keypad. The ROW and COL pins must be connected to the pins that you say in the software.

keypad.pdf (216 KB)

Thanks for that I see what I was doing wrong that said I have not been able to fix it. Possible a combination of poor soldering and reading the attached image incorrectly.

But at least I now understand how it should all work :slight_smile:

so that diagram means you should replace the code:-

byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad

with the code:-

byte rowPins[ROWS] = {1, 2, 3, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 6, 7}; //connect to the column pinouts of the keypad

Note using pins 0 & 1 is not recommended as this can interfere with code uploading and serial communications.

Ok so does this mean that A must be connected to Pin 6 on the Arduino, B to Pin 1, C to Pin 5 etc as per the diagram?

You can connect it how you like. The thing is that you must reflect how you have wired it up in the code. You can either change the wiring or change the code. Either way the two must match.

I give up. I ordered a different one that I hopefully labeled clearer. No matter how I wire it up I can only get different keys to work and then they produced different numbers.

The numbers that the keypad produces are governed by the hexaKeys array. You can swap those round to produce the numbers you want. Before you do this make sure that they keypad is wired up so you get a different number from each key, then you can make these numbers by swapping the values in the array.

Thanks so much for you patience. I now get it. Alas I think the keypad is faulty but at lease I know how to move forward :slight_smile: