Project tutorial
Control Door Lock Remotely Using Smartphone

Control Door Lock Remotely Using Smartphone

This project uses the Arduino Mini board and "Whats up Arduino" Android app.

  • 5,375 views
  • 0 comments
  • 14 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Introduction

Hi, friends. I came to this idea of controlling a door latch/lock remotely using a smartphone when I saw many people many times forget to carry latch/lock keys when they leave the house for a 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 the door, then you can unlock it sitting in the room itself.

This project is simple to make and can save your lock. Let's start to make it.

Wiring

Follow the schematic below to connect the components.

You will need a power adapter to power on the system. I had used a locally available 5V DC power adapter.

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.

"Whats Up Arduino" App

Once you are ready with the hardware, upload the Arduino code/sketch onto the Arduino board using IDE. Now download the free Android app, "Whats Up Arduino," available through Google Play on your smartphone.

We will be using this app to control the lock via Bluetooth. This app is good to control or test the Arduino board remotely. It has a 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.

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; in this case, it will be pinMode (8, OUTPUT). This means we are setting pin 8 of Arduino to OUTPUT mode. Press the SEND button and the message will be sent to Arduino, and it responds with 'done' message.

To unlock the door: go to the 'analogWrite' message group, tap on the button displaying 8, and 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 aha! The door has unlocked.

The Arduino code provided here makes the servo return automatically to the 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.

Code

Arduino sketchArduino
Arduino sketch needs to be uploaded in Arduino board using Arduino 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**********/

Schematics

Schematic
Ff75kidiy4qwk1y 6cgkr45ikt

Comments

Similar projects you might like

Grovey sLocks - Access Control Through A Smart Door Lock

Project tutorial by gerrikoio

  • 998 views
  • 0 comments
  • 6 respects

Control your RoboArm with your Smartphone

Project in progress by Team Zone Team

  • 9,164 views
  • 7 comments
  • 27 respects

Servo Control with TV Remote Control

Project showcase by eldo85

  • 5,591 views
  • 5 comments
  • 17 respects

Control Your Arduino BLE Device Using Smartphone

Project tutorial by Anas Dalintakam

  • 2,698 views
  • 0 comments
  • 5 respects

Arduino Keyless Door Lock System with Keypad and LCD

Project tutorial by DIY Hacking

  • 15,301 views
  • 9 comments
  • 44 respects

Arduino and Android Based Password Protected Door Lock

Project tutorial by Md. Khairul Alam

  • 11,083 views
  • 6 comments
  • 46 respects
Add projectSign up / Login