Using a Piezeo Element to read analog values

Hi

I am using an UNO and a piezeo element connected directly between ground and A0

The additional wires (red + orange) are only being used to hold the very small Piezeo wires in place - nothing else.

My code is

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = 1023-analogRead(sensorPin);    
  // turn the ledPin on
  
  Serial.println(sensorValue);

delay(100);
}

This runs full speed and generally returns 0 if nothing is going on. But if I touch/tap the piezeo element it changes values say jumps to 600 and then slowly reduces back to 0.

This reduction to 0 can take 30 seconds.

I would have expected a much quicker drop to 0

If I was using this to record audio (such as a rain drop or hail) I would need much quicker reduction to 0 since one strong hail stone would be only a few ms not 30 seconds.

Any ideas on what I need to ensure a quicker drop and why it is doing this?

Could there really be that much energy being released over 30 seconds?

Chris

Have you seen this?

OK I have found that if I put a 1M resister between the Red + Black legs of the Piezieo element then I get good data.

Thanks for the info on the knock sensor - it helped but I found it on a youtube video and not on here.

cheers

I have also changed the loop to

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
if (sensorValue >= 5)  
  Serial.println(sensorValue);
  // turn the ledPin on
  delay(100);                  
  
}

So I now have

A0 connected to 1 Leg of 1M resister and then connected to RED leg of Piezo
GND connected to other leg of 1M and then connected to BLACK leg of Piezo

chris