Piezo vibration sensor's signal is bouncing

Hello, I am kind of new to Arduino and would like some help with the following:

I am using a piezo vibration analog sensor (ceramic round ones) in this fashion
The sensor has a small weight on top, and I am placing it on top of a motor gearbox to track its vibration. It seems to work half well, as the values bounce. The sensor when left alone and without the weight reads incrementing values (which should not be the case as it is not being moved and sitting still) instead of 0. And the reference or average of the values is shifted

so the serial monitor prints(for example): 0,0,0,0,0,1,1,1,1,11,3,3,3,3,7,7,7,7,7,11,11,11,11,50,50,50,50,50,
29,29,29,29,29,40,40,40,40,40,59,59,59,59,59,59,59
I can't seem to be able to attach images for some reason.

and the code:

float vibration = 0;
int threshold = 500;

void setup() {

  Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
}

void loop() {
  
  float vibration = analogRead(A0);
  Serial.println(vibration);
  if( vibration >= threshold){
    digitalWrite(13,HIGH);
    digitalWrite(12,LOW);
  } 
  
  else{
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  }
  delay(40);
}'''


Does anyone have any idea how to debounce the signal or have it at 0 when there is no force or vibration applied to the sensor?
Thanks in advance, and hope my explanation was clear
edit: I connected the vcc to 5 volts, 3.3 volts and no volts and the same happens

If you are not going to use A1, ground A1.

With A1 grounded

vibration is declare global and

in setup vibration is being declared locally. Only declare vibration in one place, in this case. Either make vibration global or local.

Put a 103 ceramic cap into the Uno's Aref pin and ground for more stable readings.

1 Like

Did you add a 1Megohm pull down resistor across the piezo.
Leo..

1 Like

I thought the module already had a resistor internally. I tried it and it is stable now

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