PASSCODE LOCK SYSTEM USING EEPROM MEMORY

HI brothers and sis..... here iam a newbie to arduino probably i come with an existing idea passcodelock
system but when iam googled so many people who didi the project but not used a eeprom .you can think that a the importance of eeprom memory in a passcode lock system .so i started doing this project .mostly iam done 75% now i need help from my maker brothers please help me to make this project.

my code of pass code lock is given below(iam a newbie i dont know much about programming iam googled and compained so many codes i got u can make better)
when any one finish please post this on here.


///////////////////////////////////////////////////////////////////////////////

#include <Keypad.h>
#include<LiquidCrystal.h>
#include<EEPROM.h>

//////////////////////////////////////////////////////////////////////////////

LiquidCrystal lcd(13,12,11,10,9,8);
char password[4];
char pass[4],pass1[4];
int i=0;
char customKey=0;

//////////////////////////////////////////////////////////////////////////////

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

///////////////////////////////////////////////////////////////////////////////

byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 1,A5}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

////////////////////////////////////////////////////////////////////////////////////

void(* resetFunc) (void) = 0;
void setup()
{

lcd.begin(16,2);

lcd.print(" XPARXZ-techs ");
lcd.setCursor(0,1);
lcd.print(" Keypad Lock ");
delay(2000);
lcd.clear();
lcd.print("Enter Ur Passkey:");
lcd.setCursor(0,1);
for(int j=0;j<4;j++)
pass[j]=EEPROM.read(j);
}

void loop()

{

customKey = customKeypad.getKey();
if(customKey=='#')
change();

if (customKey)

{
password[i++]=customKey;
lcd.print(customKey);

}

if(i==4)
{
delay(200);
for(int j=0;j<4;j++)
pass[j]=EEPROM.read(j);
if(!(strncmp(password, pass,4)))
{

lcd.clear();
relayon();
//lcd.clear();
// lcd.print("Passkey Accepted");
// lcd.setCursor(8,1);
// lcd.print("A->LOCK");

}

else
{

lcd.clear();
lcd.print("Access Denied...");

delay(2000);
lcd.clear();
lcd.print("restarting...");
delay(5000);
resetFunc();

// i=0;
}
}
}

void change()
{
int j=0;
lcd.clear();
lcd.print("UR Current Passk");
lcd.setCursor(0,1);
while(j<4)
{
char key=customKeypad.getKey();
if(key)
{
pass1[j++]=key;
lcd.print(key);

}
key=0;
}
delay(500);

if((strncmp(pass1, pass, 4)))
{
lcd.clear();
lcd.print("Wrong Passkey...");
lcd.setCursor(0,1);
lcd.print("Better Luck Again");
delay(1000);
customKey=0;
setup();
}
else
{
j=0;

lcd.clear();
lcd.print("Enter New Passk:");
lcd.setCursor(0,1);
while(j<4)
{
char key=customKeypad.getKey();
if(key)
{
pass[j]=key;
lcd.print(key);
EEPROM.write(j,key);
j++;

}
}
lcd.print(" Done......");
delay(1000);
}
// lcd.clear();
// lcd.print("Enter Ur Psk:");
// lcd.setCursor(0,1);
// customKey=0;
}
void relayon()
{
if(!(strncmp(password, pass,4)))
{
digitalWrite(0,HIGH);

}
}
void relayoff()
{
digitalWrite(A1,LOW);
}

.mostly iam done 75%

That's great progress - 30% better than yesterday.

Can you please get into the habit of posting code inside code tags?

What do you expect the code to do? What doesn't work?

Why do you need a reset function?

I mentioned in your other thread to tell us where your stuck. I forgot to tell you to please provide information about what you expect your code to do and what it does do and does not do.

PS
When posting code, please use code tags (as mentioned above)

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

Your code will look like

///////////////////////////////////////////////////////////////////////////////


#include <Keypad.h>
#include<LiquidCrystal.h>
#include<EEPROM.h>


//////////////////////////////////////////////////////////////////////////////


LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
char password[4];
char pass[4], pass1[4];
int i = 0;
char customKey = 0;


//////////////////////////////////////////////////////////////////////////////


const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


///////////////////////////////////////////////////////////////////////////////



byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 1, A5}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);



////////////////////////////////////////////////////////////////////////////////////

void(* resetFunc) (void) = 0;


void setup()
{


  lcd.begin(16, 2);

  lcd.print("  XPARXZ-techs ");
  lcd.setCursor(0, 1);
  lcd.print("  Keypad Lock ");
  delay(2000);
  lcd.clear();
  lcd.print("Enter Ur Passkey:");
  lcd.setCursor(0, 1);
  for (int j = 0; j < 4; j++)
    pass[j] = EEPROM.read(j);
}


void loop()

{


  customKey = customKeypad.getKey();
  if (customKey == '#')
    change();


  if (customKey)
  {
    password[i++] = customKey;
    lcd.print(customKey);
  }

  if (i == 4)
  {
    delay(200);
    for (int j = 0; j < 4; j++)
      pass[j] = EEPROM.read(j);
    if (!(strncmp(password, pass, 4)))
    {

      lcd.clear();
      relayon();
      //lcd.clear();
      // lcd.print("Passkey Accepted");
      // lcd.setCursor(8,1);
      // lcd.print("A->LOCK");
    }

    else
    {

      lcd.clear();
      lcd.print("Access Denied...");

      delay(2000);
      lcd.clear();
      lcd.print("restarting...");
      delay(5000);
      resetFunc();

      // i=0;
    }
  }
}



void change()
{
  int j = 0;
  lcd.clear();
  lcd.print("UR Current Passk");
  lcd.setCursor(0, 1);
  while (j < 4)
  {
    char key = customKeypad.getKey();
    if (key)
    {
      pass1[j++] = key;
      lcd.print(key);

    }
    key = 0;
  }
  delay(500);

  if ((strncmp(pass1, pass, 4)))
  {
    lcd.clear();
    lcd.print("Wrong Passkey...");
    lcd.setCursor(0, 1);
    lcd.print("Better Luck Again");
    delay(1000);
    customKey = 0;
    setup();
  }
  else
  {
    j = 0;

    lcd.clear();
    lcd.print("Enter New Passk:");
    lcd.setCursor(0, 1);
    while (j < 4)
    {
      char key = customKeypad.getKey();
      if (key)
      {
        pass[j] = key;
        lcd.print(key);
        EEPROM.write(j, key);
        j++;

      }
    }
    lcd.print("  Done......");
    delay(1000);
  }
  // lcd.clear();
  // lcd.print("Enter Ur Psk:");
  // lcd.setCursor(0,1);
  // customKey=0;
}
void relayon()
{
  if (!(strncmp(password, pass, 4)))
  {
    digitalWrite(0, HIGH);

  }
}
void relayoff()
{
  digitalWrite(A1, LOW);
}

Note:
strncmp works basically on nul-terminated character arrays and neither password nor pass seems to be that.

ok guys i will explain how my stuff need to be work:

firstly there will be a default 1234 passcode in eeprom(there is another two line of code to write to eeprom)

when it initialise it will ask PLEASE ENTER UR PASSCODE:

1)enter the password

+-----------------------------------------------------+
| |
| enter your passcode: |
| 1234 |
| |
| #)change passcode A)Lock |
| |
+-----------------------------------------------------+
we can change passowrd when click the # button or reset the code by pressing on A button

2)after enter the code

-> if it is true

+-----------------------------------------------------+
| |
| ACCESS GRANDED |
| |
| |
| #)change A)lock |
| |
+-----------------------------------------------------+

when access granded the relay is on status

while we press 'A' button it will reset the code if press it goes to change password.

-> if the access denied:

+-----------------------------------------------------+
| |
| ACCESS DENIED |
| |
| |
| reseting in 5 second |
| |
+-----------------------------------------------------+

it will reset the code relaay in off status

  1. when press CHANGE password(the # button)

+-----------------------------------------------------+
| |
| enter existing password: |
| |
| |
| |
| |
+-----------------------------------------------------+

->if the right existing passcode entered

+-----------------------------------------------------+
| |
| enter new passcode : |
| |
| |
| |
| |
+-----------------------------------------------------+

after enter new pass code :

+-----------------------------------------------+
| |
| |
| DONE...... |
| |
| restarting in 5 second... |
| |
+------------------------------------------------+

then restart the code.

this is my concept so idont know how much my cord accurate and stable .

but you can help me this is the first better project in my life .

sorry its a little bug in the drawing of my lcd in this post :expressionless:

And what your code does? It is hard to hunt a bug if we don't know where you have problem.

there is only one problem->

when the passcode granded

ineed to display access granded in lcd

and at same time the ralay must on stat until we press the 'A' button

check the code the bug is:
inside the 'if' is repeating idont need to repeat

if (!(strncmp(password, pass, 4)))
{

lcd.clear();
relayon();
lcd.clear();
lcd.print("Passkey Accepted");
lcd.setCursor(8,1);
lcd.print("A->LOCK");
}

You're using several string functions, but what you're passing to them are not strings.
You need to fix that.
Hint

 if (customKey)
 
  {
     password[i++]=customKey;
     password[i] = '\0';
     lcd.print(customKey);

(of course, "password" needs to be a 25% bigger)

Also code tags - you need to start using them, please.

You check if i == 4. So the first thing you can do is reset it to 0. The will prevent the if-block from being entered again

  if (i == 4)
  {
    i == 0;

    ...
    ...
  }

And as you have not given a reason in your reply for the reset function, please get rid of it; you don't need it.

:confused: i couldn't understand ue example would u please write in my orginal code posted here then i will probably understand. then the reset function is used to reset the code when there is wrong key entered . i know only this way now but ur are an pro in these please make a good code.
and please consider the relay i confused with the relay need to on when right pascode etered.

i will hope you do that for me brother.

As Delta_G says. That if (i == 4) is part of your original code. The suggestion is to add the line i = 0 at the beginning of the if block; the ... represents the remaining code in your if block (where you delay(200), read the eeprom and compare the entered password with the stored password).

And still no answer for the question why you need a reset function.

the reset function iam used for reset the code when anyone enter wrong passcode.

the main problem is ineed to controll relay when passcode is granded. idond know .any one give me the code or edit it in my code i need it when passcode is granded.

Have you fixed the problems that have already been pointed-out?

If so, post the revised code (in code tags) and tell us your observations.

xparkz:
the reset function iam used for reset the code when anyone enter wrong passcode.

That is not a reason to reset your Arduino. Sounds like rebooting the PC after somebody typed the wrong password or username.

ok then what i need to do when anyone entered wrong passcode i need go back to the password enter code when password entered incorrect.i can't find another way till iam posting this replay.
if you know please tell me

You don't need to do anything. your code will happily go for the next attempt (as far as I can see) if you implement the suggestion that you set i to zero once you have received the four characters.

You might want to add some more logic to your code; what needs to happen if the user punches in 123# or 12A? Do you want the user to be able to change the password while the lock is open?

The below is the beginning of your loop(); just append the rest of your code that you already had (please remove the call of resetfunc()). Also consider that your not working with strings so strncmp is basically the wrong function.

void loop()
{
  customKey = customKeypad.getKey();
  if (customKey == '#')
    change();

  if (customKey == 'A')
  {
    relayoff();
  }

  if (customKey)
  {
    password[i++] = customKey;
    //lcd.print(customKey);
  }

  if (i == 4)
  {
    i = 0;

// the remainder of your code here

Questions:
1)
you have a relayoff() function; why is it not used? And why does it use a different pin from relayon()? Why is / are the relay pin / pins not set as output
2)
you check the password and if it's OK you call relayon(); why does that function check the password again?

k i will check and replay u

Guys please help me the relay is not working in the program

xparkz:
Guys please help me the relay is not working in the program

What program?

almost ready everything working what i need . but small bugs.

Now i need to make custom arduino board for this

any one had the circiut daigram