Meas sensor reading

I have a circuit built using a Piezo vibration sensor large Meas with mass weight. I used the code similar to the knock sensor.

void setup()
{
Serial.begin(9600); //
}
void loop()
{
int val;
val=analogRead(0);//Connect the sensor to analog pin 0
//if (val>100)
float rating = val*(500/1023.0);
Serial.println(rating);
//Serial.println(val,DEC);//
//else Serial.println();
delay(100);
}

It works very well and gives me streaming data to the serial monitor. What I can’t figure out is a way to make it print just the highest value per impact. Each impact will occur and be followed by no activity for a couple seconds. Currently I am seeing pretty reliable data but I can’t figure out what to do. I tried to change the delay and I tried to assign a value to different ranges without success.

Something like this should get you going:

int highestval = 0;
int val;
// Loop a few times and read the values, saving the highest
for (int i = 0; i<=100; i++) {
   val = analogRead(0);
   if (val >= highestval) {
       highestval = val;
   }
}

// Now output they highest value
Serial.println(highestval);

// Sleep and then do it again
delay(100);

You can play around with how many times you go in the loop - not sure if 100 is your number but you can probably figure that out.

Good luck,
Dave