In: Computer Science
The goal is to design a program that prints out "unlock" when a 3 knock pattern is knocked on a sensor. this program will be ran on an arduino with a pizeo sensor.
Consider a pizeo transducer connected . It has to be connected to an Analog pin.
There happens to be 2 cases,
1. Any 3 knocks of any intensity.
2. 3 Knocks of predecided intensity each. like only (high high low) will open the door.
For both the cases, below program can be tweaked to get desired output. For case 1, make low intensity as minimum and high intensity as highest. For case 2 kindly decide low and high intensity.
Program:
const int pizSensor = A0;
const int Highestintensity = 300;
const int LowestIntensity = 100;
const int LenofKnock = 4;
const int KnockPattern[ LenofKnock ] = {0, 0, 1};
int inppatterncounter = 0;
int sensorinpt = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorinpt = analogRead(pizSensor);
if (sensorinpt >= Highestintensity) {
if (KnockPattern[ inppatterncounter ] == 1) {
inppatterncounter++;
} else {
inppatterncounter = 0;
Serial.println("Restart Pattern");
}
delay(50);
} else if (sensorinpt >= Lowestintensity) {
if (KnockPattern[ inppatterncounter ] == 0) {
inppatterncounter++;
} else {
inppatterncounter = 0;
Serial.println("Restart Pattern");
}
delay(50);
if (inppatterncounter == (LenofKnock) ) {
Serial.println("Unlock");
delay(500);
inppatterncounter = 0;
}
}
Hope This Helps!