Taming the analog read from a piezo film sensor

Hello. Can you help me with CODE for a simple set-up similar to a “knock” code for an Arduino Leonardo?

I need to get accurate values when bending the piezo vibration sensor. The “knock” code was tweaked a bit and I added a map function so when at rest, the printed value would be “0” up to 100 when vibrating.

Now when I set-up my project again, the code was not changed but the numbers tend to start from around “20”.

Is there a better way to generate more accurate values? I have reviewed Arduino’s website and could only find possible solutions to add a “Calibration” code and a “Smoothing” code to take an average -used on irratic sensors. Is a piezo an irratic sensor?

Please help. I am a beginner at circuitry and programming but am a fast learner.

Thanks!

Piezos are not “accurate” sensors and even if they were, the analog input of a typical microprocessor can’t work well to measure the output.

What is it that you want to measure accurately?

Thank you jremington. The reason that I am on the forum is to see if there is a better way to take a read from the pizeo. My definition of “accurate” would be to have the values read “0” when the sensor is at rest and a x amount(ceiling) when the sensor is compressed and producing its maximum output. The same code as the knock sensor worked then didn’t when the project was set-up again (nothing changed). So now I need to know if there is extra code to add to Calibrate or is there anything else that I can do.

Piezo sensors generate only transient voltages/currents in response to compression or bending, and it is very difficult for the analog input to capture the “ceiling”.

A piezo is probably not the sensor you want for your project, but unless you describe it, forum members probably can’t help further.