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