Introduction: Unlock Your Door Using Phone or Tablet

Picture of Unlock Your Door Using Phone or Tablet

Hi Friends, I came to this idea of controlling door latch/lock remotely using smartphone when I saw many people many times forget to carry latch/lock keys when they go out of house for short trip or the door gets latched accidentally while casually talking to neighbors etc. In such cases there remains no option but to break the lock.
Also sometimes you are inside your bedroom and want to unlock latch when a family member arrives at door then you can unlock it sitting in the room itself.

This project is simple to make and can save your lock. Lets start to make it !!!

Step 1: Materials Required -

1.) Arduino Pro Mini (5v module).

2.) Dot board/Perfboard.

3.) HC-05 or HC-06 Bluetooth module.

4.) Tower pro sg-90 9g servo motor.

5.) A power supply giving an output voltage ranging from 5 volt to 12 volt.

6.) USB B Type cable.

7.) Laptop with Arduino IDE installed.

8.) What's Up Arduino App.

9.) 470 uf capacitor.

Step 2: Hardware Setup

As shown in the picture you can fix the servo motor at an appropriate distance from latch and tie the moving part of the latch to the servo motor shaft. This will require customization because you may have a different latch than what I have. The goal is when the motor shaft moves the latch should be driven in unlock position. Please watch the video so you get an fair idea of it.

Step 3: The Schematic -

Picture of The Schematic -

Follow the schematic to connect the components.

Step 4: The Code -

Once you are ready with the hardware upload the Arduino code/sketch in to Arduino board using IDE.

/******sketch for WhatsUpArduino App*******/

#include <SoftwareSerial.h>// import the serial library
#include <Servo.h>

SoftwareSerial chat(10, 11); // RX, TX
Servo myservo;

int pos = 0;

void setup() {
  chat.begin(9600);
  myservo.attach(8);
}

void loop() {
  if (chat.available()){
    String readStr = "";
    readStr=chat.readString();
    //pinMode
    if(readStr.startsWith("pinMode")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String mode=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      if(mode=="INPUT"){
        pinMode(pinNo, INPUT);}
      if(mode=="OUTPUT"){
        pinMode(pinNo, OUTPUT);}
      if(mode=="INPUT_PULLUP"){
        pinMode(pinNo, INPUT_PULLUP);}
      chat.println("done");
    }
    //digitalWrite
    if(readStr.startsWith("digitalWrite")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String value=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      if(value=="HIGH"){
        digitalWrite(pinNo, HIGH);}
      if(value=="LOW"){
        digitalWrite(pinNo, LOW);}
      chat.println("done");
    }
    //digitalRead
    if(readStr.startsWith("digitalRead")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      int val=digitalRead(pinNo);
      if(val==1){        
      chat.println("it's HIGH");}
      if(val==0){       
      chat.println("it's LOW");}
    }
    //analogWrite
    if(readStr.startsWith("analogWrite")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      String val=readStr.substring(readStr.indexOf(", ")+2,readStr.indexOf(")"));
      int value=val.toInt();
        if(pinNo==10 || pinNo==11){
          chat.println("You were trying to write on pins which are used by bluetooth RX/TX");// analog write/PWM on pins used by bluetooth can interrupt communication.
        }else{
            myservo.write(value);
            delay(5000);
            myservo.write(0);
          }
      }
    //analogRead
    if(readStr.startsWith("analogRead")){
      String pin=readStr.substring(readStr.indexOf("(")+1,readStr.indexOf(","));
      int pinNo=pin.toInt();
      int val=analogRead(pinNo);
      chat.println("it's " + String(val));
  }
 }
}
/********end of sketch**********/

Step 5: About the App -

Download the free android app 'Whats Up Arduino' available on the Google play in your smartphone. We will be using this app to control the lock on Bluetooth. This app is good to control or test the Arduino board remotely. It has an user interface of instant messaging or chatting apps like 'Whatsapp'. It feels like you are chatting with your Arduino bot. It has many functions/commands used by Arduino and is also a good learning tool for Arduino.

Step 6: Using the App -

After downloading the app, go to your phone's Bluetooth settings. Turn on your phone's Bluetooth and then wait until the phone detects Arduino bluetooth module HC-05. Once it appears in the list, click on it and pair the bluetooth module by entering the default password as '0000'' or '1234'.

Now open the app and it will show the paired Arduino Bluetooth module then tap on it. A new page with chatting interface will open up. Tap on 'connect' in the top right corner of the app to connect to Arduino. Once it is successfully connected, at the bottom you will find different Arduino commands and pin numbers like smileys.

Go to the 'pinMode' group, choose the OUTPUT option and press on the pin number where servo motor is connected i.e. pin 8. A message will be constructed automatically which describes the Arduino command like in this case it will be pinMode( 8, OUTPUT). This means we are setting pin 8 of Arduino to OUTPUT mode. Press SEND button and the message will be sent to Arduino and it respon ds with 'done' message.

To unlock the door, go to the 'analogWrite' message group, tap on the button displaying 8, adjust the analog value with the help of the scroller to 180 (Note that 180 is the degrees you want to move the servo shaft. If you select 90 then the servo will move 90 degrees instead of 180 degrees). Now press on the SEND button and ahaa! the door has unlocked.

The Arduino code provided here makes the servo return automatically to original position i.e locking position after 5 seconds. You can change this by changing the code e.g. you can make the latch return to lock position only after you give another command.

Comments

RyukiAkihiba (author)2017-03-14

I want to ask what is the apps,i cant find in the google playstore. And the program i still cant understand,its my first arduino project

soardr (author)RyukiAkihiba2017-03-14

The name of the app has changed. It's name is now "Arduino Programming Remotely". You can search by this name or you can just click on the link given in the instructables. If you want to download the app in your phone, then open the same instructables in your phone and click on the link and then download the app.

Now because this is your first instructables, I suggest you to start with the basic Arduino projects and codes. After you learn basic programming, you will understand the code. If you have any more quires, feel free to comment.

RyukiAkihiba (author)soardr2017-03-14

I still want to try this project but i dont know what the problem ?

soardr (author)RyukiAkihiba2017-03-16

Tell me if you are using the same code given in the instructables, or you have modified it. If you have modified the code, paste the parts of the code where you have modified the it.

RyukiAkihiba (author)soardr2017-03-14

Everytime i send the pin mode in apps it wont send back the messages

ahmedcheriff9 (author)2017-02-14

it's a very easy and useful way to unlock doors

good job

soardr (author)ahmedcheriff92017-02-20

Thank You ahmedcheriff9. Comments like these encourage me to make many interesting, useful and easy projects

ttlog (author)2017-01-23

Thank you for the helpful tutorial. I have one question. After I send the eg analogWrite(8,180) , the servo turns but after a few seconds it returns to it's original position. How can I stop it from happenning?

soardr (author)ttlog2017-01-23

Happy to know you found it helpful.

To stop the servo returning to original position find a line in code 'myservo.write(0)' and remove it. This line/command is asking the servo to go to position '0' i.e original position. You can also see the command 'delay(5000)' just above it which asks the Arduino to wait for 5 seconds before the servo returns to original position.

Further I would like to tell you that if you send analogWrite(8, 90) the servo will turn 90 degrees instead of 180 this means you can control how much the servo turns so that you can fine tune your project. Hope this helps.

I love to answer queries so please do not hesitate to ask if you have more queries.

ttlog (author)soardr2017-01-24

Yes, I saw the lines in the code, right after I asked the question, but I thought I might ask for verification! I have one more question. My phone disconnects a lot and sometimes the HC05 module switches off and I have to power down the Arduino and power it on again. I changed the charger with a 2A one, but it still does the same. Have you had similar experiences?

soardr (author)ttlog2017-01-24

No, I didn't experience such problem .

if this is happening when the servo is operating then it may be loading related issue like the lock lever may be tight.

I am using Arduino pro mini, if you are using a bigger board it might be taking more power. I had tried using UNO but it did not power up at all on the same power adapter. Unfortunately I do not have the adapter details because I have used a scrapped old mobile charger which does not have any label of ratings.

Please let me know your findings, in the mean time I will try to simulate your issue.

ttlog (author)soardr2017-01-24

It might be because I am using a Nano. I'll try with a mini. Thanks for your time

About This Instructable

5,690views

83favorites

License:

More by soardr:Powering ESP8266-01 Using BatteriesSoil Water Level Status Using ESP8266Simple LED Blink Using ESP8266
Add instructable to: