Hi thank you very much for replying.

The piezo beam I am using is - https://www.sparkfun.com/datasheets/Sensors/Flex/MiniSense_100.pdf

I have add 2 scope pic of the signal peak hope u can see it.

And after countless attempts now I got to this code:

void setup() {

Serial.begin(9600);

}

void loop() {

vibe = analogRead(knockSensor);

if (vibe > 12 && vibe < 30) {

xEvg();

getData();

for (int k = 7, zeroSum = 0 ; k < 13; k++) {

zeroSum += amp[k];

}

if (zeroSum <= 2)

zeroCheck = 1;

else

zeroCheck = 0;

if (((evgAmp[1] - evgAmp[2]) > 10) && (amp[6] == 0 && amp[7] == 0) && (evgAmp[0] < 22) && (zeroCheck == 1)) { // checking trash hold conditions

zeroCheck = 0;

knock = 1;

}

else

knock = 0;

if (knock == 0) {

for (int k = 0 ; k < 8; k++)

evgAmp[k] = 0;

for (int k = 0 ; k < 16; k++)

amp[k] = 0;

}

if (knock == 1) {

Serial.print("detection: ");

Serial.println(knock , DEC);

Serial.println("the knock Data: 8bit ,16 bit ");

for (int k = 0 ; k < 8; k++) {

Serial.print(evgAmp[k], DEC);

Serial.print(", ");

}

Serial.print("\n");

for (int k = 0 ; k < 16; k++) {

Serial.print(amp[k], DEC);

Serial.print(", ");

}

Serial.print("\n\n");

delay(70);

Amplitude = (xEvg1 + xEvg2) / 2 - (xEvg3 + xEvg4) / 2;

knock = 0;

for (int k = 0 ; k < 8; k++)

evgAmp[k] = 0;

for (int k = 0 ; k < 16; k++)

amp[k] = 0;

signalMax = 0;

signalMin = 254;

ampCount = 0;

}

delay(1);

}

}

void xEvg() {

for (int k = 0 ; k < 4; k++)

xEvg1 += amp[k];

xEvg1 /= 4 ;

for (int k = 4 ; k < 8; k++)

xEvg2 += amp[k];

xEvg2 /= 4;

for (int k = 8 ; k < 12; k++)

xEvg3 += amp[k];

xEvg3 /= 4;

for (int k = 12 ; k < 16; k++)

xEvg4 += amp[k];

xEvg4 /= 4;

Evg[0] = xEvg1;

Evg[1] = xEvg2;

Evg[2] = xEvg3;

Evg[3] = xEvg4;

return;

}

void getData() {

for (int k = 0, ampCount = 0 ; k < 16; k++) { //measure the max and min signal in one knocking time

for (int i = millis(), j = millis() ; i < (j + tapTime); i = millis()) { //measure the max and min signal in one knocking time

vibe = analogRead(knockSensor);

if (vibe > signalMax) {

signalMax = vibe;

}

else if (vibe < signalMin) {

signalMin = vibe;

}

}

amp[ampCount] = signalMax;

signalMax = 0;

signalMin = 254;

ampCount++;

}

for (int k = 0, i = 0 ; k < 8; k++, i += 2) {

evgAmp[k] = (amp* + amp[i + 1]) / 2;*

}

return;

}

I will be glad to get any comments for improving the algorithm so I can really Isolate the knock peak from others noises.