Hackster is hosting Impact Spotlights: Smart Home. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Smart Home. Stream on Thursday!
SetNFix
Published © LGPL

Arduino Digital Door Lock

Arduino based Password protected door lock

IntermediateFull instructions provided5 hours343
Arduino Digital Door Lock

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
ATMEGA328P-PU
×1
MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
TaydaElectronics MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
×1
D313 Transistor
×1
2n2222 Transistor
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Arduino UNO
Arduino UNO
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
3.7V 9900mAh Rechargeable Lithium Ion Battery
18650 Storage
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Schematics

Arduino Door Lock

Circuit Diagram

Code

Arduino Door Lock

Java
Upload this code for the project
/* @file MultiKey.ino
|| @version 1.0
|| @author Mark Stanley
|| @contact mstanley@technologist.com
||
|| @description
|| | The latest version, 3.0, of the keypad library supports up to 10
|| | active keys all being pressed at the same time. This sketch is an
|| | example of how you can get multiple key presses from a keypad or
|| | keyboard.
|| #
*/

/*This code was modified to create a Digital Door Lock by
 * INDIKA for SETNFIX Youtube channel. visit http://youtube.com/setnfix for more details
 * contact via setnfix@gmail.com.
 */

 /*OPERATION
  * Default password is 1234. then you can unlock using 1234 and pressing # within 8 seconds.
  * the old passwod can be changed by entering default password and press *. if the passwod is correct
  * you can enter new password and save it by pressing *.
  * if the old password is wrong, puwer will be cut off.
  * unlock password is given 8 secinds and change the password is allowed 15 secinds.
  * There is a CUT OFF relay and a power supply relay. you have to press the power on switch to supply the power
  * to the arduino. then the relay will be activated to supply the power.
  * If you have entered a wrong password or at the end of given time perid, CUT OFF relay will be activated and will be
  * disconnnected the power supply.
  * USE 12V BATTER AND THIS CUT OFF RELAY METHOD WILL BE A CAUSED TO KEEP THE BATTERIED LONG TIME.
  * 
  * *************************************************************************
  * YOU NEED
  * *************************************************************************
  * 12V RELAY
  * 4*3 MATRIX KEY PAD
  * 3V/5V RELAY
  * 12V SOLENOID DOOR LOACK
  * PUSH BUTTON SWITCH
  * LEDS,
  * 120OHM, 1K RESISTORS
  * ATMEGA 328P
  * 16MHZ CRYSTAL
  * 22PF CAPACITOR
  * 104PF CAPACITOR
  * D313 TRANSISTOR
  * 2N2222 TRANSISTOR
  * 100UF CAPACITOR
  * ARDUINO UNO BOARD
  * WIRES
  * WIRE CONNECTORS
  * SOLDERINGIRON
  * VERO BOARD
  * BATTERY CASING
  * BATTERIES (12V)
  * 1N4007 DIODE
  * SCREW NAILS
  * NUTS AND BOLTS
  * SPACES
  * 
  * -----------------------------------------
  *YOU CAN GET MORE INFORMATIONS ON
  *------------------------------------------
  *http://www.youtube.com@setnfix
  *https://projecthub.arduino.cc/setnfix
  *http://www.setnfix.com
  *https://www.facebook.com/setnfixofficial
  */

 

#include <Keypad.h>
#include <EEPROM.h>
int ResetRelay = 10; // Connect relay to Reset the unit
int lock = 9; // Connect Door LOCK
const int buzzer = 11; //buzzer to arduino pin 11
long eeAddress = 13; //EEPROM address to start reading from
int Unlock = 12;
int resetDelay = 8000; // 8 seconds given to enter the password

long OldMillis = millis();;

String savedPW = "";
String oldkey="" ;
String PrsKey="";
String defaultPW = "1234#"; //Default password, you can change is the format is xxxx#
String currentPW = "";
int updatePW = 0;

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] = {8, 7, 6, 5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the kpd

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

unsigned long loopCount;
unsigned long startTime;
String msg;


void setup() {
    Serial.begin(9600);
    loopCount = 0;
    startTime = millis();
    msg = "";
    pinMode(lock, OUTPUT); // DOOR LOCK
    pinMode(ResetRelay,OUTPUT); //RESET RELAY
    pinMode(buzzer, OUTPUT); //BUZZER
    pinMode(Unlock, INPUT); //Unlock switch
      

    // Read the saved Password from EEPROM
    for (int i = 0; i < 5; ++i) {
        savedPW += char(EEPROM.read(eeAddress + i));
        delay(100);
        Serial.println(savedPW);
    }
    

char mychar= savedPW.charAt(4) ;
Serial.println(mychar);

if (mychar == '#') {
  Serial.print("Passowrd found : ");
  currentPW =savedPW ;
  Serial.println(savedPW.length());
  Serial.println(savedPW); } 
else { 
  Serial.print("No password : "); 
  Serial.print(savedPW); 
  currentPW = defaultPW; }
}


void loop() {

// Time to reset*********************
  int CurrentMillis = millis();
  if ((CurrentMillis-OldMillis) >resetDelay){ //off after given seconds
    PasswordFailed();
    Serial.println("Time Out");
  }
  

 
//**********Reading the KEY******************** 
PrsKey = kpd.getKey();
if (PrsKey != NO_KEY) {oldkey += PrsKey;
KeyPress(); // Make buzzer noice
Serial.println(oldkey);}
//**********Reading the KEY_END**************** 





if (updatePW ==0){
  if (PrsKey == "#"){
    if (oldkey==currentPW)  {
    Serial.println("Door is unlocked");
    PasswordOk();
    digitalWrite(lock,HIGH);oldkey="";}
    else{
    Serial.println("Incorrect Password"  );
    PasswordFailed();
    digitalWrite(lock,LOW);
    oldkey="";}  
  
    
  } // End loop

}


if ((PrsKey == "*")&& (updatePW ==0)){ 

  resetDelay = 15000; // Give more time to change the password (15 seconds are given to change the password)
  //String  tempPW = oldkey+= "#";

  oldkey.replace("*", "#");
  
  if (oldkey==currentPW)  {
  Serial.println("Enter New Password");
  updatePW =1;oldkey=""; PrsKey = "0";PasswordOk();}//Password update mode is Activated
  else{
  Serial.println("Incorrect Password"  );
  digitalWrite(lock,LOW);
  Serial.println(oldkey);
  Serial.println(currentPW);
  updatePW =0; //Password update mode is deactivated
  oldkey="";PasswordFailed();}  
  
}


if ((updatePW ==1)&&(PrsKey == "*")){

  if (oldkey.length() == 5){
    oldkey.replace("*", "#");
    currentPW = oldkey ;
                    // Update EEPROM with new password
                for (int i = 0; i < 5; ++i) {
                    EEPROM.update(eeAddress + i, currentPW[i]);
                }
    oldkey = "";
    updatePW =0;
    Serial.println("New Password is saved");
    PasswordOk();
     } else {oldkey="";updatePW =0;Serial.println("Incorrect Format");PasswordFailed();}

}

} //-------------------------End Void LOOP--------------------------------------


void ClearMemory() {
    
    // Clear EEPROM
    for (int i = 0; i < EEPROM.length(); ++i) {
        EEPROM.write(i, 0); // Write 0 to each address
    }
    
    Serial.println("EEPROM cleared.");
}


void KeyPress(){
  tone(buzzer, 2000); // Send 1KHz sound signal... Incresing the value you can get higher sound
  delay(50);        // ...for 1/10 sec
  noTone(buzzer);     // Stop sound...
  delay(50);        // ...for 1/10 sec
}

void PasswordOk(){
  tone(buzzer, 2000); // Send 1KHz sound signal...
  delay(2000);        // ...for 1 sec
  noTone(buzzer); 
}

void PasswordFailed(){
  tone(buzzer, 2000); // Send 1KHz sound signal...
  delay(200);         // ...for 1/10 sec
  noTone(buzzer);     // Stop sound...
  delay(50);         // ...for 1/10 sec
  tone(buzzer, 2000); // Send 1KHz sound signal...
  delay(200);         // ...for 1/10 sec
  noTone(buzzer);     // Stop sound...
  delay(50);         // ...for 1/10 sec
  tone(buzzer, 2000); // Send 1KHz sound signal...
  delay(200);         // ...for 1/10 sec
  noTone(buzzer);     // Stop sound...
  delay(50);         // ...for 1/10 sec
  tone(buzzer, 2000); // Send 1KHz sound signal...
  delay(200);         // ...for 1/10 sec
  noTone(buzzer);     // Stop sound...
  delay(50);         // ...for 1/10 sec



//Reset the switch
  digitalWrite(ResetRelay, HIGH);
  delay(2000);
  digitalWrite(ResetRelay, LOW);
  delay(2000);
  digitalWrite(ResetRelay, HIGH);
  delay(2000);
}

Credits

SetNFix
17 projects • 35 followers
I am an accountant in profession but, I would more prefer to work with electronics based innovations.
Contact

Comments

Please log in or sign up to comment.