12 digit Keypad-controlled lock not working

Hi, I just bought a 12 key numeric keypad and tried to make a lock code with it. I opened the serial monitor and typed the passcode but nothing was printed into the serial monitor! :fearful:
THE CODE

#include "Keypad.h"
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] =
{{'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char PIN[6]={'1','2','3','4','5','6'};
char attempt[6]={0,0,0,0,0,0};
int z=0;

void setup()
{
  Serial.begin(9600);
}

void correctPIN()
{
  Serial.println("CORRECT PIN ENTERED...");
}

void incorrectPIN()
{
  Serial.println("INCORRECT PIN ENTERED!");
}

void checkPIN()
{
  int correct=0;
  int i;
  for ( i = 0; i < 6 ; i++ )
  {
    if (attempt[i]==PIN[i])
    {
      correct++;
    }
  }
  if (correct==6)
  {
    correctPIN();
  } else
  {
    incorrectPIN();
  }
  for (int zz=0; zz<6; zz++)
  {
    attempt[zz]=0;
  }
}

void readKeypad()
{
  char key = keypad.getKey();
  if (key != NO_KEY)
  {
    switch(key)
    {
      case '*':
        z=0;
        break;
      case '#':
        delay(100);
        checkPIN();
        break;
      default:
        attempt[z]=key;
        z++;
    }
  }
}

void loop()
{
  readKeypad();
}

Could anyone please post a solution?

Maybe sprinkle some Serial.println() statements in your code to see where its hanging up? I usually like to put a Serial.println(key) in my "if (key != NO_KEY)" statements. That way I know if the keypad is working, if its hooked up correctly, and what keys it thinks are being pressed.

There is nothing wrong with your code, so it could be your wiring to your keypad that may be the problem. If everything is wired correctly and the baud rate on the serial monitor (located in the bottom right corner) matches the BR in your code, enter this *123456#.

wizdum:
Maybe sprinkle some Serial.println() statements in your code to see where its hanging up? I usually like to put a Serial.println(key) in my "if (key != NO_KEY)" statements. That way I know if the keypad is working, if its hooked up correctly, and what keys it thinks are being pressed.

Ohhhhhhhh ok I'll try that thanks!
:smiley:

It turns out that my keypad was working... I just don't know how to connect it :sweat_smile: could you please tell me? It also needs to be relative to my program.

What keypad do you have, can you provide any links or pictures?

HazardsMind:
There is nothing wrong with your code, so it could be your wiring to your keypad that may be the problem. If everything is wired correctly and the baud rate on the serial monitor (located in the bottom right corner) matches the BR in your code, enter this *123456#.

I entered that but it doesn't recognise the keys... :frowning: :frowning: Could someone tell me the pins locations PLEASE?

:smiley:

We don't know what keypad you have, so we cant tell what pins to use.

HazardsMind:
We don't know what keypad you have, so we cant tell what pins to use.

Oh yeah sorry...
My keypad is from jaycar so go on their webpage
The catalogue number is
CAT. NO. SP0770
Search the number in jaycar search bar and it should be black w/ white keys!

Please don't take this the wrong way, but, the scrolling icons etc make it very difficult to concentrate on your actual posts.

Maybe I am just getting old and my concentration levels aren't what they used to be :roll_eyes:

Take a look at the Procedure section. Here is the link HERE.
The picture that came up with the link you gave us, only showed 7 pad, so it should be the first 3 pads are for the COL, and the rest are your ROW pins

scruffyruff:

HazardsMind:
We don't know what keypad you have, so we cant tell what pins to use.

Oh yeah sorry...
My keypad is from jaycar so go on their webpage
The catalogue number is
CAT. NO. SP0770
Search the number in jaycar search bar and it should be black w/ white keys!

Also problems occur i.e., 3 isn't 4 in computer is it????? or # isn't 0?
I don't understand because I'm just starting the hardware side of electronics. (I'm more of a software person)

:smiley:

HazardsMind:
Take a look at the Procedure section. Here is the link HERE.
The picture that came up with the link you gave us, only showed 7 pad, so it should be the first 3 pads are for the COL, and the rest are your ROW pins

THANKS!

Also problems occur i.e., 3 isn't 4 in computer is it????? or # isn't 0?

What?

Magicj:
Please don't take this the wrong way, but, the scrolling icons etc make it very difficult to concentrate on your actual posts.

Maybe I am just getting old and my concentration levels aren't what they used to be :roll_eyes:

Oh that's ok I can just switch to normal text. Thanks for your opinion!

HazardsMind:

Also problems occur i.e., 3 isn't 4 in computer is it????? or # isn't 0?

What?

When I press 3 serial monitor says i pressed 4
when I press # serial says i pushed 0

That means your wires are wrong.

HazardsMind:
Take a look at the Procedure section. Here is the link HERE.
The picture that came up with the link you gave us, only showed 7 pad, so it should be the first 3 pads are for the COL, and the rest are your ROW pins

Which is first and which is last?

It shows it in the link I gave you.

HazardsMind:
That means your wires are wrong.

Thanks!

HazardsMind:
It shows it in the link I gave you.

Whoops accidentally went passed it.