Getting useful peak data from a piezo sensor

Hi all, this has been driving me nuts for a while!

Im trying to use a piezo sensor to allow me to get velocity sensitive data coming out my arduino.. I have the piezo connected to analog in, pin 0 and a megaohm resistor across the legs of the piezo between the input and ground.

My first sketch initialised a variable (threshold) and i stated: val = analogRead(piezoOne); if (val >= THRESHOLD) { Serial.print(val, DEC);

and then delayed some time inside that 'if' loop to stop repeated readings. I noticed the numbers i was getting out were seemingly pretty random, though the thresholding worked relatively well. A very hard hit would often register a low val, and consequently a soft hit might have a very high val.

I realise maybe that this is because it is simply throwing out the first value that it samples that is above my threshold. I wanted to find the peak value though, or an indication of relative hit velocity.. Is there a way I could incorporate this well in software on the Arduino?

I looked at a link to todbot: spooky-arduino-projects-4-and-musical-arduino/ which claims to have a hack attempt at measuring velocity of a piezo's hit... but it really didnt work... the t variable did not seem relative to my strike velocity at all!!

Thanks for any advice or comments, all.

complete guess

You should try streaming the entire output, see if you actually are getting those high values. Or, add a few if statements with small delays, like

if(val >= threshold) { delay(1); val = analogRead(piezoOne); delay(1); if(val >= threshold) { Serial.print(val, DEC); } }

That way that first 'bump' won't get printed, but the next reading value will.

Have a look at:-

Also consider putting a small capacitor across the transducer to hold the peak, or using a peak detector circuit in front of the A/D.

Thanks for the replies so far. What do you deem to be a 'small' capacitor rating? The piezo's are attached to the underside of a drum skin right now, detecting hits.

It doesn't have to be physically on across the sensor just electrically at the Arduino end. say start with a 0.1uF and see where that gets you.