Arduino Keyless Door Lock System | Arduino Project

by | May 11, 2022 | Arduino, Basic Coding, Coding

Home » Coding » Arduino Keyless Door Lock System | Arduino Project

Introduction

In this Arduino project tutorial, we will create an Arduino Keyless Door Lock System With Keypad And LCD. For this, we will use a micro servo which will act as a lock, an LCD will be used for display purposes and a keypad to enter the password.

In order to build physical projects, the components can be purchased online or from any electronics centre.

For the online projects, the TinkerCad website can be used.

 

Supplies

In order to make Arduino Keyless Door Lock System With Keypad And LCD, we will require the following components:

Components

  • Arduino Uno R3
  • 1 KeyPad 4×4
  • LCD 16×2
  • 1 micro servo
  • 1 small BreadBoard
  • 2 LEDs
  • 3 Resistors
  • Connecting wires

Circuit Diagram

Arduino Keyless Door Lock System With Keypad And LCD

Steps To Make Arduino Keyless Door Lock System

Step 1: Gather all the components on the Digital Board or Physical Table.

Step 2: Plug LEDs on the BreadBoard.

Micro Servo:

Step 3: Connect the Ground Terminal of it to the Ground(GND) pin of the Arduino using a black coloured wire.

Step 4: Connect the signal terminal of it to the 7 number pin of the Arduino Uno.

Step 5: Connect the Power terminal of it to the 5V power supply pin of the Arduino Uno.

LEDs:

Step 6: Connect the Cathode Terminal of each to the Ground(GND) pin of the Arduino using a black coloured wire thru a resistor, as shown in the figure.

Step 7: Connect the Anode terminal of each to the A0 & A1 pin number of the Arduino, respectively, as shown in the figure.

Keypad:

Step 8: Connect the Row 1 to 4 and Column 1 to 3 of it to the 0 to 6 number pins of the Arduino, respectively, as shown in the figure.

LCD:

Step 9: Connect the Power & the LED anode terminal of it to the 5V pin of the Arduino.

Step 10: Connect the Ground, Contrast, Read/Write & LED cathode terminals of it to the GND pin of the Arduino, as shown in the circuit.

Step 11: Connect the Register Select, Enable, & DB4 to DB7 pins of it to the 8 to 13 number pins of the Arduino, respectively, as shown in the figure.

Source Code

#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
int servoState;
int open = 0;
int close = 90;
int a = 0, b = 0, c = 0, d = 0;
int var = 0;
int C1 = 1, C2 = 2, C3 = 3, C4 = 4;
char f='*';
const byte rows = 4;
const byte columns = 3;
char keyPad[rows][columns] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte pinRows[rows] = {0, 6, 5, 4};
byte pinColumns[columns] = {3, 2, 1};
Servo lock;
Keypad keypad = Keypad(makeKeymap(keyPad), pinRows, pinColumns, rows, columns );
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup()
{
lcd.begin(16,2);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
lock.attach(7);
lock.write(close);
servoState = 1;
}


void loop()
{
char key = keypad.getKey();
if(key)
{
lcd.setCursor(6+var, 1), lcd.print(key);
lcd.setCursor(6+var, 1), lcd.print(f);
key = key - 48;
var++;


switch(var)
{
case 1: a = key;
break;
case 2: b = key;
break;
case 3: c = key;
break;
case 4: d = key;


delay(50);


if(a == C1 && b == C2 && c == C3 && d == C4)
{
lcd.clear();
lcd.setCursor(4,0);
lcd.print(" Welcome ");
lcd.setCursor(5,1);
lcd.print(" Human !");
lock.write(open);


digitalWrite(A0, HIGH);
delay(1000);
lcd.clear();
digitalWrite(A0, LOW);
}
else
{
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Incorrect");
lcd.setCursor(4,1);
lcd.print("Password");
digitalWrite(A1, HIGH);
delay(1000);
lcd.clear();
digitalWrite(A1, LOW);
}
var = 0;
lcd.clear();
break;
}
}
if(!key)
{
lcd.setCursor(0, 0), lcd.print("Enter Password :");
}
delay(2);
}

Explanation of the Code

In the beginning, we have included three header files for LCD, Keypad and servo, respectively.

1. Firstly, we have initialised class arrays and variables that will be required in the function.

2. In the setup function, we have configured the LED pins for output purposes and defined the servo state to close at the beginning.

3. In the loop function, we take the key and print it in an asterisk for privacy and confidentiality. Simultaneously taking the keys using a switch case and matching the key entered to the password that we have set in the keypad using the if statement and proceeding further using the if-else statement. In case the entered key does not match the predefined key array, we are printing the incorrect password in the LCD using its cursor.

4. The servo will be at 90 degrees initially, and when the password matches, it will rotate to 0 degrees.

5. In case of success, we are glowing green LED by giving it High power; else, Red LED will glow for a second.

Output

Arduino Keyless Door Lock System With Keypad And LCD

We will get the following output on the successful completion of the project.

On starting, the Servo will be at a 90-degree angle from its regular position and on entering the correct password(1234), it will turn to 0 degrees, and the lock will open in this way.

Entering the incorrect password will not change its axis, and the LCD will display “Incorrect password”.

 

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *