Project tutorial
Unlock your door with a knock

Unlock your door with a knock

Open your door with a special knock using Arduino, Android Phone and 1Sheeld

  • 26,753 views
  • 15 comments
  • 67 respects

Components and supplies

About this project

//www.youtube.com/embed/8Gymdcg99b4?theme=light&color=red

Hardware Implementation

Connect your component together as shown in the schematics:

  1. connect 1Sheeld with Arduino
  2. connect AND gate with 1sheeld like in attached picture
  3. connect transistor with AND gate
  4. connect relay with transistor

For more security, We use AND gate. Since, any one can use the Push button shield in the application and try all the pins to open the door. So, we have to let the output from more than 1 Pin in the Arduino and then collect them all using AND gate.

You will find the code here:

https://codebender.cc/sketch:56684

Test and Have Fun

Now test1-Press on A Button on Keypad shield to record your special knock

  1. Press on A Button on Keypad shield to record your special knock
  2. Press on B Button when you want to open your door "now it records your knock"
  3. Final Press on C Button to open your door "note C button compares between your record one and your knock when you open the door "


Code

Untitled fileArduino
// Basically the code hear and save the knock and compare it to any other knock to open the door

#include <OneSheeld.h>
int pin1 = 9;
int pin2 = 10;
int pin3 = 11;
int pin4 = 12;
int led4 = 13;
int counter = 0;
int sec = 0;
int hear[20] = {};
int saved[20] = {};
int flagc = 0;
int flags = 0;
int flagf = 0;
int i = 0;
int ii = 0;

void setup()
{
  OneSheeld.begin();
  pinMode(pin1,OUTPUT);
  pinMode(pin2,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin4,OUTPUT);
  pinMode(led4,OUTPUT);
}
void loop()
{
  if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(3))
  {
    set();
  } 
  else if (Keypad.isRowPressed(1) && Keypad.isColumnPressed(3))
  {
    record();
  }
  else if (Keypad.isRowPressed(2) && Keypad.isColumnPressed(3))
  {
    check();
  }
  else {
    flagf = 0;
    digitalWrite(pin1,LOW);
    digitalWrite(pin2,LOW);
    digitalWrite(pin3,LOW);
    digitalWrite(pin4,LOW);
    digitalWrite(led4,LOW);
  }  
}

void clc ()
{
  counter = 0;
  for (int i=0; i<=20;i++)
  {
    hear[i] = 0;
    saved[i] = 0;
  }
  i = 0;
  ii = 0;
  digitalWrite(led4,LOW); 
}

void set()
{
  if (flagf == 0)
  {
  clc();
  }
  if(Mic.getValue() > 80 && flags == 0)
  {
    digitalWrite(led4,HIGH);
    saved[ii] = millis() - sec;
    sec= millis();
    ii++;
    flags = 1;
  }
  if (Mic.getValue() < 80)
  {
    digitalWrite(led4,LOW);
    flags = 0;
  }
  flagf = 1;
}  

void record ()
{
  
  if(Mic.getValue() > 80 && flagc == 0)
  {
    digitalWrite(led4,HIGH);
    hear[i] = millis() - sec;
    sec= millis();
    i++;
    flagc = 1;
  }
  if (Mic.getValue() < 80)
  {
    digitalWrite(led4,LOW);
    flagc = 0;
  }
}

void check ()
{ if (i == ii)
  {
    for (int j=1;j<=i;j++)
    {
      int x = hear[j];
      int y =saved[j];
      if (x+400 >= y && x-400 <=y )
      {
        counter++;
      }
    }
    if (counter == i)
    {
      digitalWrite(pin1,HIGH);
      digitalWrite(pin2,HIGH);
      digitalWrite(pin3,HIGH);
      digitalWrite(pin4,HIGH);
    }
  }
  counter = 0;
  for (int i=0; i<=20;i++)
  {
    hear[i] = 0;
  }
  i = 0; 
}
Codebender
https://codebender.cc/sketch:56684

Comments

Similar projects you might like

Track and Control Your Car Remotely

Project tutorial by Ashraf Nabil

  • 25,407 views
  • 5 comments
  • 58 respects

4x4x4 LED cube with Arduino Uno and 1sheeld

Project tutorial by Hassan Ibrahim

  • 29,731 views
  • 6 comments
  • 60 respects

Unlock Your Door With a Hand Gesture

Project tutorial by AdhamN

  • 989 views
  • 0 comments
  • 4 respects

Universal Remote Control

Project tutorial by Ashraf Nabil

  • 3,305 views
  • 0 comments
  • 12 respects

Smart BT Door Lock (Simple Arduino)

Project showcase by Arun

  • 7,265 views
  • 1 comment
  • 19 respects

Arduino can hear and understand your voice with 1Sheeld !

Project tutorial by Alessandro Didonna

  • 2,963 views
  • 1 comment
  • 10 respects
Add projectSign up / Login