Project showcase
Door Lock System with Arduino

Door Lock System with Arduino © GPL3+

This is a door lock security system made with Arduino.

  • 28,886 views
  • 4 comments
  • 20 respects

Components and supplies

About this project

Just thought of making a password based door lock system in which you can enter the password via the keypad. It was an interesting project which required beginner's level skill in programming and very easy to connect circuit.

WORKING OF THE PROJECT

Code

DOOR LOCK SECURITY SYSTEM WITH ARDUINOC/C++
#include<Keypad.h> // KEYPAD LIBRARY FOR KEYPAD INTERFACING 
#include<LiquidCrystal.h> // LIBRARY FOR LCD INTERFACING
#include<Servo.h>// LIBRARY FOR SERVO MOTOR
//#include<String.h>
#define buzzer 20 // DEFINING PIN FOR BUZZER.

LiquidCrystal lcd(14,15,16,17,18,19); // PINS FOR LCD

char keys[4][4]={ // LAYOUT OF KEYPAD
 {'1','2','3','A'},
 {'4','5','6', 'B'},
 {'7','8','9', 'C'},
 {'*','0','#', 'D'}};
 
byte rowPin[4]={4,5,6,7}; // ROW PINS OF KEYPAD
byte colPin[4]={8,9,10,11}; // COLUMN PINS OF KEYPAD

Servo servo_Motor; 
String password = "159";  // SETTING DEFAULT PASSWORD.
int position = 0; // VARIABLE FOR DETERMINING THE POSITION.

int wrong = 0; // VARIABLE FOR CALCULATING THE WRONG INPUT.

int redPin = 9; // DEFINING PIN FOR RED LED
int greenPin = 8; // DEFINING PIN FOR GREEN LED
 
Keypad keypad=Keypad(makeKeymap(keys),rowPin,colPin,4,4);
// MAPPING THE KEYPAD.


int total = 0; // VARIABLE TO DETERMINE THE NUMBER OF WRONG ATTEMPTS.

void setup()
{
 pinMode(redPin,OUTPUT);
 pinMode(greenPin,OUTPUT);
 
lcd.begin(16,2);
lcd.print("DOOR LOCK SYSTEM");
lcd.setCursor(0,2);
lcd.print("       BY:");
delay(2000);
lcd.clear();
lcd.print("Creative");
lcd.setCursor(0,2);
lcd.print("    Engineer");
delay(2000);
lcd.clear();
servo_Motor.attach(3);
setLocked(true);
delay(1000);

pinMode(buzzer, OUTPUT);
}

void loop()
{
  
  lcd.clear();
  lcd.print("Enter Password:");
  delay(100);
  
 char pressed=keypad.getKey();// TAKING THE INPUT FROM KEYPAD
 String key[3];
  
 if(pressed) // IF THE KEY IS PRESSED
 {
  lcd.clear();
  lcd.print("Enter Password:");
  lcd.setCursor(position,2);
  lcd.print(pressed);
  delay(500);
    if(pressed == '*' || pressed == '#')
      {
          position = 0;
          setLocked(true);
          lcd.clear();
      }

    else if(pressed == password[position])
      {
          key[position]=pressed;
          position++;
      }
 
    else if (pressed != password[position] )
      {// IN CASE OF WRONG INPUT INCREMENT BOTH WRONG AND POSITION.
          wrong++;
          position ++;
      }

    if(position == 3)
      {// WHEN POSITION == 3 THEN CHECK THE FOLLOWING
          if( wrong >0) // IF ANY WRONG INPUT IF GIVEN THEN INCREMENT TOTAL AND
          // SET WRONG AND POSITION TO ZERO.
            {
                total++;
                wrong = 0;
                position = 0;
                lcd.clear();
                lcd.print("WRONG");
                lcd.setCursor(5,2);
                lcd.print("PASSWORD");
                delay(1000);
                setLocked(true);
            }

          else if(position == 3 && wrong == 0)
            {// IF NO WRONG VALUE IS GIVEN THEN DISPLAY THE ACCEPTED PASSWORD AND
              // MOVE THE SERVO MOTOR.
                position = 0;
                wrong = 0;
                lcd.clear();
                lcd.print("PASSWORD");
                lcd.setCursor(6,2);
                lcd.print("ACCEPTED");
                delay(2000);
                lcd.clear();
                lcd.print("Door Open");
                delay(2000);
                setLocked(false);
            }

          if(total ==3)// IF TOTAL OF 3 ATTEMPTS ARE DONE BY ENTERING WRONG PASS
          //WORD THEN SOUND A BUZZER AND SET TOTAL TO 0.
            {
                total=0;
                buzzer_beep();
                delay(500);
            }

        }

   }

   
}

void setLocked(int locked)// FUNCTION TO CHANGE STATUS OF SERVO MOTOR.
  {
    if (locked)
      {
          digitalWrite(redPin, HIGH);
          digitalWrite(greenPin, LOW);
          delay(1000);
          servo_Motor.attach(3);
          servo_Motor.write(10);
          delay(1000);
          servo_Motor.detach();
      }
    else
      {
          digitalWrite(redPin, LOW);
          digitalWrite(greenPin, HIGH);
          delay(1000);
          servo_Motor.attach(3);
          servo_Motor.write(90);
          delay(1000);
          servo_Motor.detach();
      }
  }
void buzzer_beep()// FUNCTION TO BEEP THE BUZZER.
{
   digitalWrite(buzzer,HIGH);
   delay(1000);
   digitalWrite(buzzer,LOW);
   delay(1000);
   lcd.clear();
   lcd.setCursor(16,0);
   lcd.print("Subscribe Channel");
   lcd.setCursor(16,1);
   lcd.print("For More Videos");
   delay(2000);
   while(1)
   {
   lcd.scrollDisplayLeft();
   delay(200);
   }
}

//IF VIDEO WAS HELPFUL THE DO LIKE COMMENT AND SUBSCRIBE THE CHANNEL. ALSO SHARE THE 
//VIDEO SO THAT OTHERS CAN ALSO LEARN NEW THINGS.

Schematics

CIRCUIT DIAGRAMS
Led interfacing with arduino qhqkflfvcj
lcd_with_arduino_ZHuuxD17fT.JPG
Lcd with arduino zhuuxd17ft
interfacing_keypad_with_arduino_8xDFWS5uS3.JPG
Interfacing keypad with arduino 8xdfws5us3

Comments

Author

Jayesh nawani
jayesh_nawani
  • 6 projects
  • 19 followers

Additional contributors

  • Design and coding by Jayesh Nawani

Published on

July 22, 2017

Members who respect this project

Default cy6ziyq7xmEu3DefaultPhotoDefault

and 14 others

See similar projects
you might like

Similar projects you might like

Arduino Keyless Door Lock System with Keypad and LCD

Project tutorial by DIY Hacking

  • 15,305 views
  • 9 comments
  • 44 respects

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 35,778 views
  • 20 comments
  • 97 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,836 views
  • 17 comments
  • 75 respects

Bluetooth Door Lock (Arduino)

Project tutorial by Dante Roumega

  • 23,118 views
  • 12 comments
  • 33 respects

Automatic Door and Counter Prototype

Project tutorial by Francisc Camillo

  • 11,462 views
  • 1 comment
  • 21 respects
Add projectSign up / Login