Project tutorial
Smart BT Lock with Custom Number

Smart BT Lock with Custom Number © GPL3+

High security cheap number lock. No one can able to see where the lock from outside the door. Use change password when ever they want.

  • 4,564 views
  • 2 comments
  • 22 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
1434509556 android phone color
Android device
×1
servo motor
×1
Door Lock
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

Bluetooth Controller App

About this project

Lot of Locks are in market to keep the house, office, Locker safe. With Link it one we can able to built a Number lock system very cheaply. In all the lock system even Bio-matrix lock some thing a sensor or any thing is in the front of the door. But when we come to blue tooth operated lock all are behind the door.

Here we going to create a lock. Using the same password is always dangerous, that's why all are required to change the password periodically . So here with this we also able to change our passwords as per our requirement.

Step 1: Materials Required

1) PCB Board 1No

2) Linkit one With Bluetooth Antenna

3) PCB Push Button.

4) Servo Motor

5) Android Phone.

6) Bluetooth Controller App Free Download from Google. I already explain a lot about the app in my instructables Home Automation.

7) Door Lock

8) PCB connector

9) Wires

10) Soldering equipment

Then What the need of Arduino UNO here. That's a different story, explain u in up coming steps.

Step 2: Connection Plan

Not a very complicated circuit. Only program is very logic. So as per diagram Connect a button to pin no 12 for Input as per basic button connection diagram with resister. Also, Connect a servo motor in to pin no 9 as per servo motor connection. Servo motor has three wires first one id black or brown connect it to ground, Second one is red connect it to 5 V and Third one is orange connect it to signal (pin no 9 or 3 because they are PWM pins).

Step 3: Soldering

1) Solder the Circuit like shield.

2) Solder the Push button at the top of the PCB.

3) Connect it with digital pin 12.

4) Solder a 3 pin PCB male connector to the board for servo.

5) Bring wires from GND, +5V, D9.

6) Fix the shield over the Link it one board. So hard ware side finished.

Step 4: Coding

1) Three Libraries are needed for this program.

a) Bluetooth Library.

b) EEPROM Library.

c) Servo Library.

2) Bluetooth Library is used to give pass word and control the system Open and Close. Also used to save new pass word. This all are done using Bluetooth Controller App.

3) EEPROM Library is used to save the existing saved password (Then only even after reboot the system remember the password. Also saved the last door status and retrieve when reboot or after power on.

4) Servo library is used to control the servo motor.

Coding is ave as BTlocker in the coding


Step 5: Testing and Failure

1) With out Servo motor i found the coding works fine and phone shows the status and all.

2) But the main problem is my servo motor not working correctly with

Last 2 days i go through all things in net and still not working correctly. It works but not correct. In the process of testing due to my  fault i lost a servo motor also. It over heat and not working. Then buy a new one and continue. What are all i did is

1) Update the Firmware.

2) Check with pin3.

3) Give 5V power from external power source. check a lot and up to last it turn but very very slow and take lot of interval. Then check it with arduino. It works correctly.


1) So Plan the link the Linkit one with arduino.

2) Connect the Linkit one pin 10 to Arduino pin 12 and Linkit one Gnd to Arduino gnd use resister to protect the pins and per button input. Then connect the Servo pin 9 of the arduino.

3) Upload the BTlockerWA in to Link it one board.

4) Upload the servocontrol to Arduino board.

5) Now connect the servo to arduino.

6) In the program while want to open the door pin 10 in Linkit one set high. Arduino read that through pin 12. Then Open the door.

7) While want to close the door pin 10 in Linkit one set Low. Arduino read that through pin 12. Then Close the door.

Linkit one program is uploaded as BTlockerWA

Arduino program is uploaded as servocontrol


Step 7: Open Close Testing



1) Open Bluetooth Controller App in the Android Phone.

2) Change the Data of Key and Key name as 1,2,3,4,5,6,7,8,9.

3) Click scan to view the Board name.

4) Select the Board Name in the list.

5) At the instance of connect a Welcome message with Door status shown. And ask to type the pass word to open/close the door.

6) Type the pass word. Pass word is a 6 digit number. So when u type the last digit.

7) If pass word is wrong, Invalid pass word shown in the mobile screen.

8) If pass word is correct then the servo activated and open of close. Shows the status in the screen.

9) Type again the pass word close the door if open.

Step 8: Time Out Testing

1) When pass word is start type. Don't wait for too long time between keys.

2) The system not wait. After few seconds it shows Time out try again.

3) U want to type the password from the beginning.

Step 9: Change number Testing

1) On press the button on the board.

2) It tell the mobile Type new Password.

3) On hold the button in one hand type the new password in the mobile.

4) When the 6 the digit press. It save the current pass word and reply Password Changed, Remove your hand.

5) Now Remove the hand from the button.

6) Then it conform the hand remove as exit password change.

7) While type password u remove the hand from the button. It come to step 6 and new pass word is not set. Old password is active.

Step 10: Testing In video

See the video of how it works while testing. All the works completed. Want to fix in a box and fitted to work in real world.

Step 11: Assemble the Lock

1) Take a Slide lock.

2) Disassemble all joints.

3) There is a spring in the slide lock, below the slide rod. Remove it makes very smooth movement.

4) Polish the uneven surface of the rod using file.

5) Make a Link between the lock and the rod.

6) Fix both freely to move. Check the movement.

Step 12: Completed

1) Before Fix it in door i check it with two separate wooden boards.

2) Connect the Slide piston in the short side of the Slide valve. So that it have space to move.

3) Check many times and found ok.

See the video first one is taken using Digital Camera. Second one is using old phone.

Code

BTlocker.inoArduino
#include <LBT.h>
#include <LBTServer.h>
#include <LEEPROM.h>
#include <Servo.h> 

int readval;
Servo myservo;

int resultvalue;
int checktime=0;

String readpassword;
String Password;
String msg;

const int buttonPin = 12;
const int ledPin =  13;

boolean firstconn;
boolean changepass;
int Doorstatus;
int Dooraddress=100;

void setup() {
 if(!LBTServer.begin((uint8_t*)"Sivam_LIO"))
 {
 return;
 }  
//  writepass("123456");
  Doorstatus=EEPROM.read(Dooraddress);
//  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  firstconn=false;
  changepass=false;
  readpassword="";
  Password=readpass();
  myservo.attach(9);
  delay(100);
}

void servocommand()
{
  if (Doorstatus==0)
  {
    myservo.write(0);
    delay(100);
  }
  else
  {
    myservo.write(180);    
    delay(100);
  }
}

void loop() {
 uint8_t buf[1];
 int bytesRead;
if(LBTServer.connected())
 {
   if (firstconn==false)
   {
     firstconn=true;
     delay(200);     
     LBTServer.write("Hello Welcome");     
     delay(100);
     if (Doorstatus==0)
     {
       LBTServer.write("Door is close");            
       delay(100);       
       LBTServer.write("Type Password to open");
       delay(100);       
     }
     else
     {
       LBTServer.write("Door is open");            
       delay(100);       
       LBTServer.write("Type Password to close");
       delay(100);              
     }
   }
   if (digitalRead(buttonPin) == HIGH && Doorstatus==0 && changepass==false)
   {     
     changepass=true;
     LBTServer.write("Type new password");
     readpassword="";
     delay(100);
   }
   else if (digitalRead(buttonPin) == LOW && changepass==true)
   {
     changepass=false;
     LBTServer.write("Exit from password change");
     readpassword="";
     delay(100);     
   }
   while(true)
   {
     bytesRead = LBTServer.readBytes(buf, 1);
     if(!bytesRead)
     break;
     readval = buf[0];
     readpassword = readpassword + char(readval);
     checktime=0;
//     msg = "U type -" + readpassword;
//     LBTServer.write(msg);   
//      Serial.println(readpassword);
     if (readpassword.length()==6)
     {
       if (changepass==false)
       {
         if (readpassword.equals(Password))
         {
           if (Doorstatus==0)
           {
             Doorstatus=1;
             servocommand();
             EEPROM.write(Dooraddress,1);
             LBTServer.write("Door Open");
           }
           else
           {
             Doorstatus=0;
             servocommand();
             EEPROM.write(Dooraddress,0);           
             LBTServer.write("Door Close");           
           }
         }
         else
         {
           LBTServer.write("Invalid Password");              
         }  
       }       
      else
      {
        writepass(readpassword);
        Password=readpassword;
        LBTServer.write("Password Changed");
        delay(100);
        LBTServer.write("Remove Your hand");
        delay(100);
      }
       readpassword="";
     }     
   }
   delay(100);
 
  if (readpassword!="")
  {
   checktime=checktime+1;
   if (checktime>5)
   {
     readpassword="";
     changepass=false;
     checktime=0;
      LBTServer.write("Time out. Try again");
      delay(100);     
   }
  }
  
  }
  else
  {
     readpassword="";
     firstconn=false;
     changepass=false;
     LBTServer.accept(5);
  }
  
//  if (digitalRead(buttonPin) == HIGH) {
//    Serial.println(2);
//    digitalWrite(ledPin, HIGH);
//  }
//  else {
//    Serial.println(3);
//    digitalWrite(ledPin, LOW);
//  }  
  
  delay(100);
}


String readpass()
{
  String mempass;
  int memval;
  int memadd;
  mempass="";
  for(int i=0;i<6;i++)
  {
    memadd=200+i;
    memval=EEPROM.read(memadd);
    if (memval>9)
    {
      memval=0;
    }
    mempass=mempass + memval;
  }
  return mempass;
}
void writepass(String passw)
{
  String mempass;
  int memval;
  int memadd;
  for(int i=0;i<6;i++)
  {
    mempass=passw.substring(i,i+1);
    memval=mempass.toInt();
    memadd=200+i;
    EEPROM.write(memadd,memval);
  }
}
BTlockerWA.inoArduino
#include <LBT.h>
#include <LBTServer.h>
#include <LEEPROM.h>
//#include <Servo.h> 

int readval;
//Servo myservo;

int resultvalue;
int checktime=0;

String readpassword;
String Password;
String msg;

const int buttonPin = 12;x
//const int ledPin =  13;
const int ctrlpin =  10;

boolean firstconn;
boolean changepass;
int Doorstatus;
int Dooraddress=100;

void setup() {
 if(!LBTServer.begin((uint8_t*)"Sivam_LIO"))
 {
 return;
 }  
//  writepass("123456");
  Doorstatus=EEPROM.read(Dooraddress);
//  Serial.begin(9600);
  pinMode(ctrlpin, OUTPUT);
  pinMode(buttonPin, INPUT);
  firstconn=false;
  changepass=false;
  readpassword="";
  Password=readpass();
//  myservo.attach(9);
  delay(100);
}

void servocommand()
{
  if (Doorstatus==0)
  {
    digitalWrite(ctrlpin, LOW);
//    myservo.write(0);
//    delay(100);
  }
  else
  {
    digitalWrite(ctrlpin, HIGH);
//    myservo.write(180);    
//    delay(100);
  }
}

void loop() {
 uint8_t buf[1];
 int bytesRead;
if(LBTServer.connected())
 {
   if (firstconn==false)
   {
     firstconn=true;
     delay(200);     
     LBTServer.write("Hello Welcome");     
     delay(100);
     if (Doorstatus==0)
     {
       LBTServer.write("Door is close");            
       delay(100);       
       LBTServer.write("Type Password to open");
       delay(100);       
     }
     else
     {
       LBTServer.write("Door is open");            
       delay(100);       
       LBTServer.write("Type Password to close");
       delay(100);              
     }
   }
   if (digitalRead(buttonPin) == HIGH && Doorstatus==0 && changepass==false)
   {     
     changepass=true;
     LBTServer.write("Type new password");
     readpassword="";
     delay(100);
   }
   else if (digitalRead(buttonPin) == LOW && changepass==true)
   {
     changepass=false;
     LBTServer.write("Exit from password change");
     readpassword="";
     delay(100);     
   }
   while(true)
   {
     bytesRead = LBTServer.readBytes(buf, 1);
     if(!bytesRead)
     break;
     readval = buf[0];
     readpassword = readpassword + char(readval);
     checktime=0;
//     msg = "U type -" + readpassword;
//     LBTServer.write(msg);   
//      Serial.println(readpassword);
     if (readpassword.length()==6)
     {
       if (changepass==false)
       {
         if (readpassword.equals(Password))
         {
           if (Doorstatus==0)
           {
             Doorstatus=1;
             servocommand();
             EEPROM.write(Dooraddress,1);
             LBTServer.write("Door Open");
           }
           else
           {
             Doorstatus=0;
             servocommand();
             EEPROM.write(Dooraddress,0);           
             LBTServer.write("Door Close");           
           }
         }
         else
         {
           LBTServer.write("Invalid Password");              
         }  
       }       
      else
      {
        writepass(readpassword);
        Password=readpassword;
        LBTServer.write("Password Changed");
        delay(100);
        LBTServer.write("Remove Your hand");
        delay(100);
      }
       readpassword="";
     }     
   }
   delay(100);
 
  if (readpassword!="")
  {
   checktime=checktime+1;
   if (checktime>5)
   {
     readpassword="";
     changepass=false;
     checktime=0;
      LBTServer.write("Time out. Try again");
      delay(100);     
   }
  }
  
  }
  else
  {
     readpassword="";
     firstconn=false;
     changepass=false;
     LBTServer.accept(5);
  }
  
//  if (digitalRead(buttonPin) == HIGH) {
//    Serial.println(2);
//    digitalWrite(ledPin, HIGH);
//  }
//  else {
//    Serial.println(3);
//    digitalWrite(ledPin, LOW);
//  }  
  
  delay(100);
}


String readpass()
{
  String mempass;
  int memval;
  int memadd;
  mempass="";
  for(int i=0;i<6;i++)
  {
    memadd=200+i;
    memval=EEPROM.read(memadd);
    if (memval>9)
    {
      memval=0;
    }
    mempass=mempass + memval;
  }
  return mempass;
}
void writepass(String passw)
{
  String mempass;
  int memval;
  int memadd;
  for(int i=0;i<6;i++)
  {
    mempass=passw.substring(i,i+1);
    memval=mempass.toInt();
    memadd=200+i;
    EEPROM.write(memadd,memval);
  }
}
servocontrol.inoArduino
#include <Servo.h> 
const int buttonPin = 12;
int buttonstate = 0;
Servo myservo;


void setup() {
  myservo.attach(9);
  pinMode(buttonPin, INPUT);
}

void loop() {
  if (digitalRead(buttonPin) == HIGH && buttonstate==0)
  {
    buttonstate=1;
    myservo.write(0);
    delay(15);          
  }
  else if (digitalRead(buttonPin) == LOW && buttonstate==1)
  {
    buttonstate=0;
    myservo.write(180);
    delay(15);          
  }
}

Schematics

Diagram
Connection%20plan

Comments

Similar projects you might like

Smart BT Door Lock (Simple Arduino)

Project showcase by Arun

  • 13,080 views
  • 1 comment
  • 23 respects

How to Make a Smart Central Lock System for Motorcycle

Project tutorial by Shubham Shinganapure

  • 2,501 views
  • 0 comments
  • 9 respects

Electronic Safe with Arduino

Project showcase by chummer1010

  • 34,346 views
  • 30 comments
  • 67 respects

Intelligent Door Lock

Project in progress by Md. Khairul Alam

  • 25,748 views
  • 24 comments
  • 117 respects

Arduino and Android Based Password Protected Door Lock

Project tutorial by Md. Khairul Alam

  • 16,632 views
  • 7 comments
  • 57 respects

Octopod: Smart IoT Home/Industry Automation Project

Project tutorial by Saksham Bhutani

  • 12,370 views
  • 9 comments
  • 39 respects
Add projectSign up / Login