Monday, 2 May 2016

Locking System

Introduction

Our project is on Advanced Locking System (knock detector door lock). It detects the knock and count the duration between each knock and if the pattern matches, door unlocks.

Team Members

  • Aakash Deep (2015001)

  • Shreyash Arya (2015097)

  • Tushita Rathore (2015108)

  • Akhil Goel (2015126)

Mentor


Prof. Jyoti V. Sinha

Project Scope

We plan to begin by making a simple lock and then connecting it to mobile for security purposes. The main goal is on improving security. Opens the door on detecting secret knock or direct access through the app, connected to mobile for security alarms.

The main objectives of our project are:
  • Opens the door when correct knock with specific interval is detected.
  • Opens the door through alpha-numeric password (keypad).
  • Opens the door through the app.

Members Role and Responsibilities


Although we all were involved in all the activities related to the project. The main responsibilities were:

Aakash Deep:Blog and app development

Shreyash Arya:Connections, mechanical working and poster

Tushita Rathore:Connections, mechanical working and final design of the prototype

Akhil Goel:Arduino code and app development

Block Diagram


Functional Diagram


Pin Diagram


List Of Components

  • Arduino UNO

  • GSM Module

  • Bread Board

  • Piezo Sensor

  • Servo Motor

  • LED

  • Connecting Wires

  • Power Adapter

  • Resistor

  • Keypad Module

Sources Of Components

  • Circuits and VLSI Lab - IIITD
  • https://in.element14.com
  • https://www.amazon.in

Reference


Tools, Apps and Software Needed

  • Arduino IDE
  • Android Studio
  • Android SDK
  • Statioary Tools

Initial Approach

  • Our initial approach began by familiarizing  ourselves with the different types of micro controllers and motors available.
  • We realised that for a project like ours we would also need gsm connection and therefore will use Arduino mega 2560 with a gsm module.
  • We also realized that while working with motors we also need to include a diode to deny any possible reverse current (that may emerge from the motor's electromagnetic cortex) to damage our micro controller.
  • To detect the duration between the knocks, we used a piezo sensor.
  • We are also making an app that controles the unlocking of the door even when we are not around and wants to open the door for another person.

Journey

  • First we started with the knock part. In this, we tried that the sensor would sense the knock and count the time interval between each knock and compare it with the built in pattern which is in the code. If the pattern matches, the servo motor rotates and the door opens with a blinking green led else red led blinks, which means the pattern of time interval between each knock do not match.
  • We added a keypad for a backup plan, If the time interval between the knocks do not match the actual pattern, then we can enter a password through the keypad and the door unlocks.
  • We made an app which is connected to the gsm module, which opens the door with just single touch on a button. Our app basically sends a message to the sim which we attach in the gsm module. It receives the message and send it to the serial monitor of the arduino and opens the door.
  • App part is also for the remote access. If the owner is not around the lock and he wants to open the door for another person, then the app can be used for this.

    Code

    #include<Servo.h>
    #include<Keypad.h>

    Servo myservo;
    int red=12;
    int green=11;

    int threshhold=50;
    int code[5]={100,25,100,25,25};
    int readings[5];
    int val=0;
    int sensor=A0;


    const byte ROWS = 4; // Four rows
    const byte COLS = 4; // columns
    // Define the Keymap
    char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
    };
    // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
    byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
    byte colPins[COLS] = { 5, 4, 3, 2 };

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


    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
    myservo.attach(10);
    digitalWrite(13, LOW);
    pinMode(red,OUTPUT);
    pinMode(green, OUTPUT);
    }

    void loop() {
      // put your main code here, to run repeatedly:
    char b;
    b=keypad.getKey();
    if(b=='1')
    itskeypad();
    if(b=='2')
    {
      while(Serial.available())
      Serial.read();
    itsgsm();
    }
    if(b=='3')
    itsknock();
    }

    void itsgsm()
    {
     // Serial.println("GSM");
     //Serial.println("AT+CMGF=1\r");  // set SMS mode to text
    //delay(1000);
      
    //Serial.println("AT+CNMI=2,2,0,0,0\r"); 
    //delay(1000);
    Serial.flush();
    while(Serial.available()>0)
    Serial.read();
    char BYTE;
      while (1)
      {
      if(Serial.available()>0)
      {
       BYTE=Serial.read();
       Serial.println(BYTE);
      opendoor();
      break;
      }
      else
       {
        delay(10000);
        opendoor();
      digitalWrite(13, HIGH);
       break;
       }
      
      }
    }



    void itskeypad()
    {
      Serial.print("KEYPAD");
       char b1,b2,b3,b4;
      while(1)
      {
    b1=keypad.getKey();
    if(b1=='1'||b1=='2'||b1=='3'||b1=='4'||b1=='5'||b1=='6'||b1=='7'||b1=='8'||b1=='9'||b1=='0'||b1=='*'||b1=='#')
    break;
      }
    while(1)
    {
    b2=keypad.getKey();
    if(b2=='1'||b2=='2'||b2=='3'||b2=='4'||b2=='5'||b2=='6'||b2=='7'||b2=='8'||b2=='9'||b2=='0'||b2=='*'||b2=='#')
    break;

    }
    while(1)
    {
    b3=keypad.getKey();
    if(b3=='1'||b3=='2'||b3=='3'||b3=='4'||b3=='5'||b3=='6'||b3=='7'||b3=='8'||b3=='9'||b3=='0'||b3=='*'||b3=='#')
    break;

    }
    while(1)
    {
    b4=keypad.getKey();
    if(b4=='1'||b4=='2'||b4=='3'||b4=='4'||b4=='5'||b4=='6'||b4=='7'||b4=='8'||b4=='9'||b4=='0'||b4=='*'||b4=='#')
    break;

    }
    if(b1=='8' && b2=='7' && b3=='2' && b4=='9')
    opendoor();
    }


    void itsknock()
    {
      while(1)
      {
        val=analogRead(sensor);
       if(val>=threshhold)
       {
       getsequence();
       break;
       } 
      }
    }

    void opendoor()
    {
      Serial.print("UNLOCKED");
      myservo.write(90);
      delay(2000);
      myservo.write(0);
      delay(2000);
      
      //myservo.writeMicroseconds(1500);
      //delay(20);
      //myservo.write(90);
      //delay(5000);
    /*digitalWrite(green, HIGH);
    digitalWrite(red, LOW);
    delay(500);
    digitalWrite(green, LOW);
    digitalWrite(red, HIGH);
    delay(500);
    */
    }

    void getsequence()
      {
      Serial.println("Ready to get knocks..");
      int i;
      for(i=0;i<=4;i++)
        readings[i]=0;
      int cno=0;
      int sttime=millis();
      int now=millis();
      digitalWrite(green, LOW);
      delay(150);
      digitalWrite(green, HIGH);
      do
        {
        val=analogRead(sensor);
        if(val>=threshhold)
          {
          Serial.println("knock..");
          now=millis();
          readings[cno]=now-sttime;
          cno++;
          sttime=now;
          digitalWrite(green, LOW);
          delay(150);
          digitalWrite(green, HIGH);
          }
        now=millis();

        }while((now-sttime<2500) && (cno<5));
      if(checkknock()==1)
        opendoor();
      else
        { 
         Serial.println("FAILED..");
         myservo.write(0);
         digitalWrite(green, LOW);
         for(i=0;i<2;i++)
          {
          digitalWrite(red, HIGH);
          delay(100);
          digitalWrite(red, LOW);
          delay(100);
          }
        digitalWrite(green, HIGH);
        }


      }


      int checkknock()
    {
      int i;
      int cno=0;
      int sccount=0;
      int maxinterval=0;
      for(i=0;i<5;i++)
      {
        if(readings[i]>0)
        cno++;
        if(code[i]>0)
        sccount++;
        if(readings[i]>maxinterval)
        maxinterval=readings[i];
      
      }
      if(cno!=sccount)
         return 0;
      else      
      {
        int totaldiff=0;
        int tdiff=0;
      for(i=0;i<5;i++)
      {
      readings[i]=map(readings[i], 0, maxinterval, 0, 100);
      tdiff=abs(readings[i]-code[i]);
      if(tdiff>25)
      return 0;
      totaldiff+=tdiff;
      }
      //if(totaldiff/3>15)
      //return 0;
      return 1;
      }
    }

    Working Videos