Hi,
I am fairly familiar with the Arduino and very at home with programming, but lacking an engineering background, I get stumped at times, so please bear with me for the following:
1. I bought some piezos for a project (
https://www.sparkfun.com/products/10293), studied the Knock example and read everything I could find in the Forum. Put together and tested one of the piezos. The sketch seems to function according to decription, but for my application it won't work because I need to:
a) read a knock at any moment in time (with the best possible resolution) but, with the delay at the end of the sketch, I miss some hits that happen in between readings; a smaller delay doesn't do it either.
b) get one (and only one) hit for each time the piezo is struck, when at peak voltage value; but every time I get a hit, no matter how hard or soft, I get more than one knock (previous hit dropping from peak voltage?)
2. Initially I thought of taking various readings until a delay had elapsed, as in a debouncing algorithm, but that only works with buttons because the voltage eventually gets stable (correct?). So I came up with the following algorithm, which is based on the idea that "if voltage just started dropping, it means we just left peak value":
void loop()
{
currentReading = analogRead(knockSensor);
if(currentReading >= threshold)
{
if(currentReading >= previousReading) // RISING OR REPEATING...
{
// if we are rising again, we reset to allow for the next hit...
if(hit) hit = false;
}
else
{
if(!hit) // DROPPING...
{
Serial.println("Knock!");
hit = true;
}
}
previousReading = currentReading;
}
}
3. I would appreciate any critique to this solution. Is my basic assumption correct? Any caveats or limitations? It seems to work, but I am not sure how reliable this is...
4. How long does it take for one of those piezos to get back to zero after being hit? Couldn't find it in the datasheet...
5. How strong are these components? How long do they last? How much abuse can they take? My intention is to use them attach to a wooden plate to be struck by (hard and soft) mallets.
Sorry about the long post.( I didn't split these questions to avoid repeating the same the story over and over...)