Password Program to light up two LEDs

Hi all,
I am building a project where I am using a keypad and LCD with a password. I want a red LED to be on to signify a door being closed and for a green LED to turn on and the red LED to turn off when the correct password is entered to signify the door open. Thr red LED is connected to 12 and the green LED is coonected to 11 of the arduino. Here is the code I am using so far. The LCD, keypad and password part of the code is working. I just cant figure out how to get the LEDs sorted. Any help would be much appreciated. Thank you.

PasswordTest1.ino (1.56 KB)

Here is the program

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
Password password = Password( "147*" );
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] = {7,6,5,4}; 
byte colPins[COLS] = {10,9,8}; 
const int buttonPin = 52;
int buttonState = 0;


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup(){
   pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
digitalWrite(12, LOW); 
Serial.begin(9600);
keypad.addEventListener(keypadEvent); 
keypad.setDebounceTime(250);
}

void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}

void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(12,HIGH); 
delay(1000);
digitalWrite(11,LOW); 
lcd.print("Hi "); 
password.reset(); 
delay(1000);
lcd.print("Enter");
delay(2000);
lcd.clear();
}


else{
digitalWrite(12,LOW);
lcd.print("GET OUT ");
password.reset(); 
delay(1000);
lcd.clear();
}
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I can't see any pinMode() commands for pins 11 and 12

Thanks for your reply. I have this but Im not sure where to put it.

pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);

They go in setup() { ... }

Put the pinMode() commands in setup() where the other one is and remove the existing one unless you are planning on using the LED connected to pin 13. The digitalWrite() command look like they are in the right place but I have not looked in detail.

Do yourself a favour and give the red and green LEDs names like the ledpin one just before setup, then you can use pinMode like this
pinMode(redLedPin, OUTPUT); and digitalWrite like thisdigitalWrite(redLedPin, HIGH);this makes it more obvious what is going on.

It looks like you have copied some/all of the code from an example. Make sure you understand how it works or you will find it difficult to make changes to it.

Thanks all for your help.

Hello Gents,
I want to make a project using LCD 16x2 , 4x4 keypad with 2 outputs. I need 4 or 5 digit password with 2 options. if after password press A on keypad, output A go high, if press B output B go high. To make them low again enter password and press D key.
Can you please advise me the code. As I tried many here but not achieving success. my little knowledge!!! THANKS IN ADVANCE.

asimzafar:
Hello Gents,
I want to make a project using LCD 16x2 , 4x4 keypad with 2 outputs. I need 4 or 5 digit password with 2 options. if after password press A on keypad, output A go high, if press B output B go high. To make them low again enter password and press D key.
Can you please advise me the code. As I tried many here but not achieving success. my little knowledge!!! THANKS IN ADVANCE.

You probably be would have been better of starting your own thread instead of kicking a 4-year old one. There is a risk that people reply to the opening post and not your,

But anyway, show the code of your failed attempt and we can try to assist.

PS
And although the description changed a bit, why did you not stick to your other thread. You can get the basics from there and later expand.

I am new to this forum will understand the rule gradually. thx

// KEYPAD 5 DIGIT PSWD LOCK UNLOCK CODE

#include<LiquidCrystal.h> //Adding LCD
LiquidCrystal lcd(13,12,11,10,9,8); //LCD pins connected to Adruino
int row[]={7,6,5,4}; // Defining row pins
int col[]={3,2,1,0}; // Defining column pins
int i,j,lcd_count,count=1,key_id=0,flag,entry=0; // See About the Program
int col_scan; // Variable to identify a key press
char temp_press; // Variable to hold value of key press
char check[6],pass[6]; // See About the Program
int Relay1Pin=A0; // Output port to control
int Relay2Pin=A1; // Output port to control
int Relay3Pin=A2; // Output port to control
int Relay4Pin=A3; // Output port to control
void setup()
{
lcd.begin(16,2);
for(i=0;i<=3;i++)
{
pinMode(row*,OUTPUT);*
pinMode(col*,INPUT);*
digitalWrite(col*,HIGH);*
pinMode(Relay1Pin, OUTPUT);//Key Enter Relay
pinMode(Relay2Pin, OUTPUT);//Switch on Relay
pinMode(Relay3Pin, OUTPUT);//Ignition Switch Relay
pinMode(Relay4Pin, OUTPUT);//Ignition Self Relay
}
lcd.setCursor(0,0);
lcd.print("ENTER CHEVY PSWD");
delay(600);
} // Main Program Starts here
void loop()
{
while(entry<=4) // Password Setting Loop begins
{
SetPassword();
} // Password Setting Loop Ends
key_id=0;
keyscan(); // Scan for a Key Press
/* Actions on Key Press begins */
if(key_id==1) // Condition to Check Key is Pressed
{
check[count]=temp_press;
count++;
/* Condition to Unlock Begins*/
if(temp_press=='B')
{
* checkPassword();*
if(flag==0)
{
lcd.setCursor(0,0);
lcd.print("Check B");
digitalWrite(Relay1Pin, HIGH); //Key Enter Relay pulse ON
delay(400);
digitalWrite(Relay1Pin, LOW); //Key Enter Relay pulse OFF
delay(300);
digitalWrite(Relay2Pin, HIGH); // Switch on Relay ON
}
count=1; // Resetting the counter variable
}
if(temp_press=='A')
{
* checkPassword();*
if(flag==0)
{
lcd.setCursor(0,0);
lcd.print("SWITCH ON");
digitalWrite(Relay1Pin, HIGH); //Key Enter Relay pulse ON
delay(400);
digitalWrite(Relay1Pin, LOW); //Key Enter Relay pulse OFF
delay(300);
digitalWrite(Relay2Pin, HIGH); // Switch on Relay ON
}
else
{
lcd.setCursor(0,0);
lcd.print("SORRY WRONG CODE");
//delay(400);
lcd.setCursor(0,2);
delay(400);
lcd.print(" CHEVY LOCKED");
delay(1000);
lcd.clear();
delay(500);
lcd.print("PLEASE TRY AGAIN");
delay(500);
lcd.clear();
delay(500);
lcd.print("PLEASE TRY AGAIN");
//digitalWrite(Relay1Pin, LOW);
//digitalWrite(Relay2Pin, LOW);
//digitalWrite(Relay3Pin, LOW);
//digitalWrite(Relay4Pin, LOW);
}
count=1; // Resetting the counter variable
} //Condition to Unlock Ends
* // Condition to Change Password Begins*
else if(temp_press=='C')
{
checkPassword();
if(flag==0)
{
lcd.setCursor(0,0);
lcd.print("ENTER NEW PASS");
key_id=0;
entry=0;
}else{
lcd.setCursor(0,0);
lcd.print("WRONG PASSWORD");
}
count=1; // Resetting the counter variable
}
/* Condition to Change Password Ends */
/* Condition to LOCK Begins*/
/* Actions on Key Press Ends*/
}
/* Main Program Ends */
void SetPassword() // Subroutine to SET User Defined Password
{
keyscan();
if(key_id==1)
{
if(temp_press=='A'||temp_press=='C'||temp_press=='B') // Condition to Check for an Invalid Keypress
{
lcd.setCursor(0,0);
lcd.print("INVALID KEYS");
entry=0;
}
else
{
* pass[entry]=temp_press;
_}
}
key_id=0;
if(entry==5)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PASSWORD ENABLED");
}} // Subroutine to SET Password ENDS*
char keyscan()// Subroutine to Scan Keypad for a Keypress
{
for(i=0; i<=3; i++)
{
digitalWrite(row[0],HIGH);
digitalWrite(row[1],HIGH);
digitalWrite(row[2],HIGH);
digitalWrite(row[3],HIGH);
digitalWrite(row*,LOW);*
for(j=0; j<=3; j++)
{
col_scan=digitalRead(col[j]);
if(col_scan==LOW)
{
* key_id=1;*
* entry++;_
temp_press=keypress(i,j);
lcd.setCursor(lcd_count++,1);
lcd.print("");//put temp_press to see the code while entering

if(temp_press=='A'||temp_press=='C'||temp_press=='B')
{
lcd_count=0;
lcd.clear();
}
delay(300);
break;
}}
}}// Subroutine to Scan Keypress Ends
char keypress(int i, int j) // Subroutine to Identify the value of Key pressed
{
if(i==0&&j==0)
{
return('1');
}
if(i==0&&j==1)
{
return('2');
}
if(i==0&&j==2)
{
return('3');
}
if(i==0&&j==3)
{
return('A');
}
if(i==1&&j==0)
{
return('4');
}
if(i==1&&j==1)
{
return('5');
}
if(i==1&&j==2)
{
return('6');
}
if(i==1&&j==3)
{
return('B');
}
if(i==2&&j==0)
{
return('7');
}
if(i==2&&j==1)
{
return('8');
}
if(i==2&&j==2)
{
return('9');
}
if(i==2&&j==3)
{
return('C');
}
if(i==3&&j==0)
{
return('*');
}
if(i==3&&j==1)
{
return('0');
}
if(i==3&&j==2)
{
return('#');
}
if(i==3&&j==3)
{
return('D');
}
} // Subroutine to identify Keypress Ends
void checkPassword() // Subroutine to Check User Input Data with SET Password
{
flag=0;
for(i=1;i<=5&&flag==0;i++)
{
if(check_==pass*)
{
flag=0;
}
else
{flag=1;
}}} // Subroutine to check password ends*

I copy this code from somewhere and modified as per my knowledge._

I copy this code from somewhere and modified as per my knowledge.

Apparently, your knowledge does not encompass the first three threads in this part of the forum.

Correct that issue, and fix the way you posted your code. I am absolutely certain that your code does NOT look like that.

Dear I did not understand what you want me to correct.

Are your comparing my subject request with this code. I can add or remove the output , but weak in applying conditional loops.

Or if I am in wrong forum subject??

looking forward for your assistance.

Dear I did not understand what you want me to correct.

Read this before posting a programming question ...

Specifically, read item #6.