AnalogRead issues

rpg600

New member
Hello, I'm a total beginner in the arduino/teensy world, and I'm facing issues on my first attempt.

I have the following code :
Code:
void setup() {
  Serial.begin(9600);
}
void loop() {
  int sensorValue1 = analogRead(A0);
  Serial.println(sensorValue1);
  delay(10);
}

For now, nothing is connected to the A0 pin. I was expecting a flat "0" value, but I'm seeing fluctuations instead. I don't understand why this is happening.
I'm using a teensy 4.1


Capture d’écran 2024-07-20 à 16.49.28.png


IMG_7057 2.jpg
 
The ADC pin is sensitive and not connected to anything. It can easily "hear" any electrical noise from your environment.

I ran your program on a Teensy 4.1 here, plugged into a breadboard but no wires connected. It also hears noise.

serialmonitor.png
 
I also tried touching the pin while the test was running. The noise changes pretty substantially. It also goes to zero if I plug a wire between pin 14 and GND.

The hardware is working as it should. Sensitive analog inputs don't read 0 when unconnected. They pick up electrical noise from your environment.
 
Thank you very much for your answer. My goal is to be able to read analog data from a piezo sensor as accurately and precisely as possible.

It responds well if I tap the sensor :
Capture d’écran 2024-07-20 à 17.35.13.png



But if I do nothing it fluctuates :
Capture d’écran 2024-07-20 à 17.34.50.png

Capture d’écran 2024-07-20 à 17.35.02.png


The setup :


IMG_7060.jpg


I measured less than 1mV fluctuations when connected to an oscilloscope, and I expected the same reading with the Teensy.

Is it possible to achieve that?
 
The 'scope has a far lower input impedance (1 or 10 Mohms) than an analog pin (well up in Gohms range at low frequencies), this explains how the 'scope can see lower noise voltages from the piezo. Pieze elements are charge sources so the impedance they see defines the voltage gain. Also high impedances have more voltage noise anyway. The ADC expects to be driven from a low impedance to see low noise and high frequency signals.
 
Try and set analog read averaging to 32 in your setup. This will be slower reads. (On phone and not sure on the exact method call)

But if you want higher accuracy you should use an external adc. Like the ads1115 (can read 16 bit adc values)
 
Back
Top