Keyless entry

By Zack and Vec

Description:

Our project was to open a box without having to physically opening it. This was to done by using three servos, one unlocking the box and two opening the box, and a piezo. Attempting to open the box could simply be done by either touching the piezo or just a simple clap.

How the program works:

The program works quite simple. We have a simple touch or clap on the piezo, and the first servo will unlock the box. After a few seconds, the second set of servos open the box. After ten seconds, the second set of piezos shut the box, and the box is locked all over again. The program only works if the two wires are touching each other.

Arduino Program:

int servoPin = 13; // Declares the variable pin number 13 as the servo

int inputPin = 11; // Declares the variable pin number 11

int myAngle; // Declares the variable for the angle of the servo

int pulseWidth;

int KnockSensor = 2; // Declares the variable pin number 2 as the piezo

byte val = 0;

int statePin = LOW; // Declares what state the pin (on or off) is before the loop starts

int THRESHOLD = 10; Identifies the strength of the vibrations that it can hear for the program to work; the lower the number the weaker the vibration has to be for the program to work

void setup ()

{

pinMode(servoPin = OUTPUT); // Declares pin 13 as an output

pinMode(inputPin = INPUT); //Declares pin 11 as an input

}

void servoPulse (int servoPin, int myAngle)

{

pulseWidth = (myAngle * 10) + 600; // Translates myAngle to the correct delay in order to make the servo move to the correct angle

digitalWrite(servoPin, HIGH); //

delayMicroseconds(pulseWidth);

digitalWrite(servoPin, LOW);

}

void loop ()

{

val = digitalRead(inputPin); // Reads the inputPin state

if (val == HIGH) { // Checks if the input if HIGH

val = analogRead(knockSensor); // // Reads the piezo state

if (val >= THRESHOLD); // Checks to see if the vibration is higher or equal to the threshold it was given

servoPin = 13; // Tells which servo is to turn on if the vibration is higher than the threshold

for (myAngle=0; myAngle<=180; myAngle++) // Turns the servo angle from zero to 180

{

servoPulse(servoPin, myAngle); // Calls the servoPulse Procedure and sets pin and angle

delay (20); // Wait .02 seconds; Refreshes cycle

}

servoPin = 11; // Switches over to servoPin number 11

for (myAngle=0; myAngle<=90; myAngle ++) // Turns the servo angle from 0 to 90

{

servoPulse(servoPin, myAngle); // Calls the servoPulse Procedure and sets pin and angle

delay(20); // Wait .02 seconds; Refreshes cycle

}

delay (10000); // Wait 10 seconds

for (myAngle=90; myAngle>=0; myAngle--) // Turns the servo angle from 90 back to 0

{

servoPulse(servoPin, myAngle); // Calls the servoPulse Procedure and sets pin and angle

delay(20); // Wait .02 seconds; Refreshes cycle

}

servoPin = 13; // Sets back to servoPin 13

for (myAngle=180;myAngle>=0; myAngle--) // Sets the angle of the servoPin from 180 to 0

{

servoPulse(servoPin,myAngle); // Calls the servoPulse Procedure and sets pin and angle

delay(20); // Wait .02 seconds; Refreshes cycle

}

}

}

}

Problems encountered:

We encountered many problems with this project. First problem was having to get the piezo to work on the second clap The program would not work with the second clap, and it would start the loop all by itself. We overcame this by dropping the second clap idea and giving it a decent threshold for it to work. The second problem that we had was figuring out how to open the box with the little power that the servo gave. We overcame this by using two servos opening the box with the motor of the servo pushing the box open.

Things we would like to add:

If we had more time, we wish that we could have added a decent lock to go with the box. Also, we could have added more power to the servos, so that it could push the box open more than it already does. Lastly, we wish we could have gotten the second clap to work so that we could have a certain code for the program to work.