Arduino based tilt motion lock

Last Updated on March 16, 2024

   By using Accelerometer and solenoid lock we can create tilt motion lock system with simple and easy to use arduino board.




Circuit diagram

arduino based sequential tilt motion lock

Construction and Working

   Here the Accelerometer output and bias pins are connected with analog pins of arduino board, and the solenoid lock connected with digital pin D10 through switching transistor BC548.

 When the motion detected by the accelerometer then the arduino board gives switching output through D10 pin and controls solenoid lock.

Arduino code

 

int GNDPin=18;

int VccPin=19;

int xPin =A3;

int yPin=A2;

int zPin=A1;

int wrongMove=13;

int currentMove = 1;

int resetTrigger = 0;

int solenoidPin = 10;

long x;

long y;

long z;

void setup()
{

Serial.begin(9600);

pinMode(GNDPin, OUTPUT);

pinMode(VccPin, OUTPUT);

digitalWrite(GNDPin, LOW);

digitalWrite(VccPin, HIGH);

pinMode(wrongMove, OUTPUT);

pinMode(solenoidPin, OUTPUT);//Set the pin that will control the solenoid in OUTPUT mode

digitalWrite(solenoidPin, LOW);//Write a low voltage signal to the solenoid on startup – this will break the circuit

Serial.println("close");

Serial.println("Please place the Accelerometer on a flat\nlevel surface");

delay(1000);//Give user 1 seconds to comply

Serial.println("Calibration complete");

}

void loop()
{

delay(20);//delay for readability
resetTrigger++; //increment the reset trigger

x = analogRead(xPin);

y = analogRead(yPin);

z = analogRead(zPin);


if (currentMove==1)
digitalWrite(wrongMove, LOW);

else
digitalWrite(wrongMove, HIGH);
if(y>=420)
{

if(currentMove==2){

Serial.println("Second move successful");

currentMove++;
delay(1000);

}

else if(currentMove==5){
Serial.println("Fifth move successful – opening");

currentMove=1;

  while(1)
  { 
digitalWrite(solenoidPin, HIGH);
  
  delay(100);
  
}

}

else
{

Serial.println("WRONG MOVE!");

currentMove=1;

}

}


if(y<=360)
{


if(currentMove==4)
{

Serial.println("Forth move successful");

currentMove++;

delay(1000);

}


else{

Serial.println("WRONG MOVE!");

currentMove=1;

}

}

if(x>=420)
{


if(currentMove==1)
{

Serial.println("First move successful");

currentMove++;

delay(1000);

}

else if(currentMove==3)
{

Serial.println("Third move successful");

currentMove++;
delay(1000);

}

else
{

Serial.println("WRONG MOVE!");

currentMove=1;

}

}


if(resetTrigger==3000)
{ //do this every minute (3000 iterations * 0.02 seconds = 60 seconds)

currentMove=1; //reset currentMove back to 1, so user can try to do the sequence again
resetTrigger=0; //set the resetTrigger back to 0 so it can start another iteration to 3000


}

}


 



Leave a Reply

Your email address will not be published. Required fields are marked *