Piezo vibration sensor works only if i touch it with my fingers

Hey,
I connected a MEAS piezo vibration sensor as a knock detector. It works only with I touch it with my fingers, like a Makey-Makey. It doesn't work when I knock on it with something else.
Please help me figure out what the problem is.

schematic attached
Screenshot 2024-05-12 at 19.41.15

the code is:

const byte piezoPin = A0, ledPin = 13;
int rawValue, maxValue, minValue = 1023;
const int samples = 250;
const int threshold = 100; // sensitivity
int randVal = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  maxValue = 0; // reset
  minValue = 1023; // reset
  randVal = random(1000);
  for (int i = 0; i < samples; i++) {
    rawValue = analogRead(piezoPin);
    if (rawValue < minValue) minValue = rawValue;
    if (rawValue > maxValue) maxValue = rawValue;
  }
  if (maxValue - minValue > threshold) {
    Serial.println(randVal);
    digitalWrite(ledPin, HIGH);
    delay(30); // to see LED
    digitalWrite(ledPin, LOW);
  }
}

Possibly you have an open connection. Please post a close up, focused picture of the setup.

In any case, the circuit should work better if you add a 100 nF capacitor from the junction of the 100K voltage divider to ground.

Thanks.
I just noticed that I used 100ohm instead of 1Mohm. I guess it caused some problems. Unfortunately I don't have a 1Mohm resistor.

Resistors can be salvaged from junked electronics.

Those will always need their values checked! Age, excess current, both affect the resistance.

Even out of tolerances, would be good improvement in this case :grinning:

I suspect that when you touch it you are coupling noise into the circuit that is detected having nothing to do with the sensor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.