Analog sensor connected to A0 show random voltage value of 2, 3, and 4

void setup()
{
Serial.begin(9600); //Open the serial to set the baud rate for 9600bps
}
void loop()
{
int val;
val=analogRead(0); //Connect the analog piezoelectric ceramic vibration sensor to analog interface 0
Serial.println(val,DEC);//Print the analog value read via serial port
delay(100);
}

Hi all, I am doing a vibration detection project. This code supposes to show voltage value only if vibration is detected. However, when there is no vibration (no touching/vibration trigger it), the readings in serial monitor keep repeatedly shows values of 2, 3 , and 4 randomly.

I tried to connect resistor to Gnd and A0, problem is still there.

Measure the voltage output from the sensor itself, then you would verify if the sensor is producing those voltages, or if the Arduino is somehow creating spurious values.

(deleted)

Cr@p, I read "values of 2, 3 , and 4 randomly" as volts, not 2, 3, 4 / 1023 which as you say, is basically 0.

Which Arduino.

What kind of piezo sensor.

Do you have a bleed resistor across the piezo, to stop the pin from ‘floating’.
Leo…

If you are using UNO, the ADC error is +/-2 counts.
Voltage for VREF pin is 5V.

Display 4 corresponds to: (5000 mV/1023)*4 ~= 19 mV, which exceeds the allowable tolerance (10 mV).

Try to display values with this parameters: delay(1000), disconnect sensor from A0-pin, and grounding the A0-pin.

Is it something to do with the Arduino compatible board , i notice this happened only when i use Wemos D1 R1. The sensor reading works normally if I use Arduino Mega 2560.

and for my project, the analog input should not be covert by /1024.

val=analogRead(0);

Is this (0) correct or it should be (A0)?

GRuser: val=analogRead(0);

Is this (0) correct

Yes

GRuser: should be (A0)?

Optional

edit: if you use digitalRead() or digitalWrite() on the analog inputs you need the "A" else it will think you mean the digital pins 0-5. (Or on a Uno call them 14-19)

huimay: i notice this happened only when i use Wemos D1 R1.

The A/D of the ESP8266 on the WeMos D1 mini seems to have a poor quality A/D. One I had returned 8-1024, while it should have been 0-1023. If you have up to 4 values of noise, then you could try to subtract 4 from the returned A/D result.

Don't know what kind of piezo and what sort of vibration/frequency you want to detect. The low 320kohm load of the voltage divider on the A/D pin could kill most of the piezo's low frequencies. Leo..

i am using a piezoelectric vibration sensor, to measure floor vibration to detect human fall. The value should come out from 0v when no vibration detected, and up to 700v when fall is detected

Guys, :) I solved this problem. Its all because of the wire connected at Sensor's input get loosen, after making the proper connection, the readings come out normally. So sorry for my carelessness!

huimay: i am using a piezoelectric vibration sensor, to measure floor vibration to detect human fall. The value should come out from 0v when no vibration detected, and up to 700v when fall is detected

Is it 700v or 700mV?

mV sorry.

i thought it went normal, but now it ends up repeating the amplitude like this when there is not even any vibration detected.

how to solve this problem? i try to connect a 1M resistor between A0 and ground, but its wont help

Give a link to your vibration sensor.

https://store.fut-electronics.com/products/piezoelectric-vibration-sensor-module

This is an analog type sensor and the received signal is normal for this kind of low-cost sensor. The specification of your referred link even does not mention the nature of the output of the sensor.

You may try with a digital type sensor – search google. You may use 3-axis accelerormeter like MPU6050. However note the following quote:

Accelerometers are devices that have specific dynamic response such that they respond to vibrations with specific range of frequencies called the bandwidth. In order to know the bandwidth of the accelerometer you have to revert to its DATASHEET.

Thank you!

(deleted)