Door lock final

dear all i am using arduino wemos in door lock project with lcd 16*2 i upload code and its ok but it doesnt work
can any one help me

#include <Keypad.h>
#include <LiquidCrystal.h>
 
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {D0, D1, D2, D3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {D4, D5, D6}; //connect to the column pinouts of the keypad
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 
// 16x2 LCD 
#define rs D7
#define en D8
#define d4 A0
#define d5 D15
#define d6 D11
#define d7 D12
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
String password = "5656";
String mypassword;
 
int redled = D14;
int lock = D13;
 
int counter = 0; 
int attempts = 0; 
int max_attempts = 3; 
 
void setup(){
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  
  pinMode(redled, OUTPUT);
  pinMode(lock, OUTPUT);
  
  digitalWrite(redled, LOW);
  digitalWrite(lock, LOW);
  
  Serial.println("enter password");
    lcd.print("Enter Password:");
}
  
void loop()
{
  
 keypadfunction();
 
}
 
void keypadfunction()
{
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print("*");
  }
  if (key == '1')
  {
 
    mypassword = mypassword + 1;   
  }
  
    if (key == '2')
  {
 
    mypassword = mypassword + 2;  
  }
  
  if (key == '3')
  {
 
    mypassword = mypassword + 3; 
  }
  
   if (key == '4')
  {
  
    mypassword = mypassword + 4;  
  }
  
  if (key == '5')
  {
  
    mypassword = mypassword + 5;
  }
  
   if (key == '6')
  {
   
    mypassword = mypassword + 6; 
  }
  
   if (key == '7')
  {
 
    mypassword = mypassword + 7; 
  }
 
   if (key == '8')
  {
 
    mypassword = mypassword + 8; 
  }
  
  if (key == '9')
  {
 
    mypassword = mypassword + 9;
  }
             
                 if (key == '0')
  {
 
    mypassword = mypassword + 0; 
  }
  
  
        if (key == '*')
  {
    Serial.println(mypassword); 
    
if ( password == mypassword )
{
lcd.clear(); 
lcd.println("Welcome To");
lcd.setCursor(0,1);
lcd.println("Chestfreezer");
digitalWrite(lock, HIGH);
delay(5000); 
digitalWrite(lock,LOW);
mypassword = ""; 
counter = 0; 
lcd.clear();
lcd.setCursor(0,0); 
lcd.println("Enter password");
}
else
{
Serial.println("wrong");
digitalWrite(lock, LOW);
attempts = attempts + 1; 
if (attempts >= max_attempts )
{
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("Locked Out");
  
digitalWrite(redled, HIGH);
delay(5000); 
digitalWrite(redled, LOW); 
attempts = 0; 
 
}
mypassword = ""; 
counter = 0; 
lcd.clear(); 
lcd.setCursor(0,0); 
lcd.print("Wrong Password");
delay(1000);
 
lcd.setCursor(0,1); 
lcd.print("max attempts 3");
delay(1000);
 
lcd.clear(); 
lcd.println("Enter password");
lcd.setCursor(0,1); 
}
      
  }  
  
  
}

attached connection

You forgot to add code tags and say what doesn't work in this code.

1 Like

Help us help you.

Put some Serial.println(variable) in your sketch to confirm variables are what you think they are.

Look for this example can be useful for you.

Nice schematic pictorial. From what you show in the schematic you will probably destroy the lock port or even the whole micro. The lock probably has a coil of some type and when you turn off the port pin the flyback from that coil will in time destroy the Arduino, you need some sort of buffer or driver. A simple N-Channel MOSFET would do the job nicely.

Hi,
For what date did the teacher ask for these projects?

Your mistake is in using the D9 and D10, (GPIO1 e GPIO3), on the LCD.
These GPIOS are from the ESP8266 serial and will conflict with its LCD.

i changed D9 and D10 with A0 and D15 but the same problem happens

What are the lock's voltage and current requirements?

my problem that lcd not working

Does this help?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.