Arduino password protected door access

Hello world! Today i made a simple code to control a electric strike lock with a Password / Access Code using a 1 channel relay to build a Arduino password protected door access control. I don’t have such a lock but i demonstrated it with a lamp attached to the relay.
(I know! I wrote access wrong in the video..don’t mind the typo..lol.)

Schematic:
Arduino password protected door access

You need these following libraries
password.h
LiquidCrystal_I2C.h
Keypad.h

Wire it up like the schematic and it should work after uploading,
if you are not seeing anything, try change your I2C Address i will include a Code to scan your address.
You can change this at the line shown below which you can find on line 14 of the code of the Arduino password protected door access.

#define I2C_ADDR 0x27
Most common I2C addresses.

PCF8574 = 0x20,
PCF8574A = 0x38,
PCF8574AT = 0x3F
PCF8574T = 0x27

Parts list:
Arduino uno, I used the RobotDyn Uno.
1 Channel Relay KY-019
Keypad 4×4
LCD 1602 with I2C
Electrical Strike Lock (Not needed to test the code, you will see if relay go’s on or off.)

Code:

/*
Author: Danny van den Brande. Arduinosensors.nl. BlueCore Tech.
This code is a example on how to build a keypad access control. You can add more options such as setting a new password.
This code is basic and you need to set the password in the code itself.
The relay should be attached to a electrical strike lock. The relay is set to HIGH because that is what the doorlock needs. 
When the relay is LOW the door lock opens. 
 */
#include <Password.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//Most common adresses PCF8574 = 0x20, PCF8574A = 0x38,PCF8574AT = 0x3F 
//PCF8574T = 0x27   
#define I2C_ADDR          0x27   
#define BACKLIGHT_PIN      3
#define En_pin             2
#define Rw_pin             1
#define Rs_pin             0
#define D4_pin             4
#define D5_pin             5
#define D6_pin             6
#define D7_pin             7

int buzzer = 3;
int relay = 9;
const int buttonPin = 5;
int buttonState = 0;
LiquidCrystal_I2C      lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
Password password = Password( "1654" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
   {'1','2','3','A',},
   {'4','5','6','B',},
   {'7','8','9','C',},
   {'*','0','#','D',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
  12, 13, A5, A4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  A3, A2, A1, A0};

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


void setup(){
    pinMode(buttonPin, INPUT);
    pinMode(relay, OUTPUT);
    pinMode(buzzer, OUTPUT);
    lcd.begin (16,2);
    digitalWrite(relay, HIGH); 
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);
    lcd.print(" BlueCore Tech  "); 
    lcd.setCursor(0,1); 
    lcd.print("Access Control  "); 
 
    delay(5000);
    
    lcd.clear();
    lcd.print("Access Code: "); 
    Serial.begin(9600);
    keypad.addEventListener(keypadEvent); 
    keypad.setDebounceTime(100); 
}

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

void keypadEvent(KeypadEvent eKey){
    switch (keypad.getState()){
    case PRESSED:
    lcd.print("*");
    digitalWrite(buzzer, HIGH);
    delay(100);
    digitalWrite(buzzer, LOW);
    switch (eKey){
    case 'A': guessPassword(); break;

    default:
    password.append(eKey);
    }
  }
}

void guessPassword(){
    if (password.evaluate()){
    digitalWrite(relay, LOW); 
    lcd.setCursor(0,0); 
    lcd.print("##CORRECT CODE##"); 
    lcd.setCursor(4,1); 
    lcd.print("WELCOME!");
    delay(10000);
    digitalWrite(relay, HIGH);
    password.reset(); 
    lcd.clear();
    lcd.print("Access Code: "); 
    
}


else{
    digitalWrite(relay, HIGH);
    lcd.setCursor(0,0); 
    lcd.print("###WRONG CODE###");
    password.reset(); 
    lcd.setCursor(2,1); 
    lcd.print("ACCESS DENIED");
    delay(3000);
    lcd.clear();
    lcd.print("Access Code: "); 
    }
}

Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

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