Project tutorial

Unlock your door with a knock

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

  • 15,194 views
  • 10 comments
  • 49 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

DIY Relay Outlet Arduino

Project tutorial by Ben Jones

  • 20,567 views
  • 16 comments
  • 24 respects

Uber Home Automation

Project in progress by Eric Tsai

  • 25,185 views
  • 3 comments
  • 112 respects

Magoo

Project in progress by 4 developers

  • 5,123 views
  • 12 comments
  • 26 respects

Arduino to Excel using V-USB

Project tutorial by Ray Burnette

  • 32,523 views
  • 6 comments
  • 32 respects

Magic Morse on Arduino

Project tutorial by Ray Burnette

  • 19,160 views
  • 7 comments
  • 23 respects

Track and Control Your Car Remotely

Project tutorial by Ashraf Nabil

  • 12,792 views
  • 3 comments
  • 42 respects
Add projectSign up / Login