problem whit 4x4 matrix keypad and uno r3

Hello I am working on a small beginner’s project. has got everything to work as I want except the 4x4 matrix keypad. I have the password “1” but when I press “4” then it opens … this is the whole problem, I do not get the rows and columns to match the keypad and Arduino … so wrong number (key) at the wrong place. is pretty new to this area so I have not clue what to do to make it work.

I use

Arduino r3
4x4matrix keypad

Here you can see which cable goes from the keypad to which pin on the Arduino counting from the right side of the keypad
yellow = pin 2
blue =pin 3
purple =pin 4
green =pin 5
gray =pin 6
white =pin 7
black =pin 8
brown =pin 9

This is the code I use

#include <Keypad.h>

char* secretCode = “1”;
int position = 0;

const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’*’,‘0’,’#’,‘D’}
};

byte rowPins[rows] = { 8, 7, 6, 9 };
byte colPins[cols] = { 5, 4, 3, 2 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

int redPin = 10; // which output + red LED locked
int greenPin = 11; // which output + green LED unlocked
int greenstyrpin = 12; // when the green light is on this output is open and goes to a relay

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(greenstyrpin, OUTPUT);
setLocked(true);
}

void loop()
{
char key = keypad.getKey();
if (key == ‘*’ || key == ‘#’) {
position = 0;
setLocked(true);
}

if (key == secretCode[position]) {
position++;
}

if (position == 6) {
setLocked(false);
}
delay(100);
}

void setLocked(int locked)
{
if (locked) {
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(greenstyrpin, HIGH);
}
else {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(greenstyrpin, LOW);
}
}

is there anyone out there who can help me :slight_smile: Sincerely jimmy

First of all, please read the rules before posting again. Especially about code tags and appropriate board choice ;)

Okay, off to the problem. A quick google for that keyboard (so please give use a link to it next time ;) ) reveals that the first halve of the connector are the rows in order and the second the columns in order. So why did you shuffle the order of the rows in the sketch?

byte rowPins[rows] = { 8, 7, 6, 9 };

You also connected them in order, so try:

byte rowPins[rows] = { 9, 8, 7, 6 };