Hey,
I connected a MEAS piezo vibration sensor as a knock detector. It works only with I touch it with my fingers, like a Makey-Makey. It doesn't work when I knock on it with something else.
Please help me figure out what the problem is.
schematic attached
the code is:
const byte piezoPin = A0, ledPin = 13;
int rawValue, maxValue, minValue = 1023;
const int samples = 250;
const int threshold = 100; // sensitivity
int randVal = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
maxValue = 0; // reset
minValue = 1023; // reset
randVal = random(1000);
for (int i = 0; i < samples; i++) {
rawValue = analogRead(piezoPin);
if (rawValue < minValue) minValue = rawValue;
if (rawValue > maxValue) maxValue = rawValue;
}
if (maxValue - minValue > threshold) {
Serial.println(randVal);
digitalWrite(ledPin, HIGH);
delay(30); // to see LED
digitalWrite(ledPin, LOW);
}
}