Help with incredibly variable (±50) ADC values

I am struggling to get the ADC on my Arduino UNO to take consistent analogue readings, even when connected directly to ground or 5V. Here is an image from Serial Plotter of what I am typically receiving when a wire is directly connected between 5V and A3 (where I am measuring from).


I have tried this with two different Arduino's, both powered from my laptop, and both are suffering from the same problem. I have also measured the voltage from the potentiometer with my oscilloscope and ensured that it reads the correct voltage, which it does with only 20mV peak-to-peak due to noise. I have also tried software averaging, but this approach feels like it isn't targeting the root of the problem and I would prefer to be able to accurately take measurements without hundreds of individual readings.
Could this be an issue with the ADC itself, my code, or purely unavoidable noise from my environment?
My code and connections can be seen in this Wokwi project, which seems to be functioning exactly as intended.

it means ADC pin is nowhere connected.
why you connect A3 to GND? what is the purpose of that constant resistors?

The Wokwi project is just intended to demonstrate the general idea without the analogue components that the simulator lacks. A3 is only connected to ground temporarily, as it will eventually read my capacitor voltage through a voltage divider when I actually assemble the project. The constant resistors simulate what the Arduino would receive when a phototransistor is irradiated vs when it is not. I am currently focused on resolving the UI issue of the potentiometer, which is connected to A0.

I believe that the ADC pin (analogue input pin?) is properly connected through the potentiometer, but please correct me if I am mistaken.

  • Disconnect everything from the arduino except the serial cable.
  • Connect the analog input to ground.
  • Read input and print to serial port

What does it read?

Repeat with connecting input to +5V, what does that read?

Connect potentiometer wiper to analog in, ends to GND and +5V. What does it read?

1 Like

If you don't see 0 or maybe 5 at most, either you have bad jumper wires or you Arduino is damaged.

Oh wow... I tried all three of your suggestions and the ADC appears to be working excellent with the test code below:

const int analogueInput = A0;
int value;

void setup() {
  Serial.begin(9600);
}

void loop() {
  value = analogRead(analogueInput);
  Serial.println(value);
}

Readings of 0V and 5V are perfectly 0 and 1023 respectively, and I'm getting fluctuations of only ±2-3 values with the potentiometer attached, so my code must be the underlying problem. Would using an I2C display be able to introduce as much noise as I was experiencing earlier, or is something else to blame?
Thanks.

EDIT: Should I move this question to a new topic if it is no longer truly about 'sensors'? This is my first time posting on the Arduino Forums, not educated on post etiquette yet.

Probably not, it's a hardware problem.

if your sketch works as expected in wokwi and strange in real, so it is not a program issue.

Why not also suspect your 5 volt supply?

Now leave it in the potentiometer configuration, again not changing anything, but run your own code. What happens then?

A number of remarks:

1: For clear testing, remove all parts that you think are unrelated to the problem.

2: When using a potentiometer the actual voltage is unimportant. I’ve seen voltages from 5.2 to 4.6V from my own PC. It becomes important if you try to measure voltages from an external source.

3: It looks like the WOKWI picture doesn’t show any connection to a positive voltage.

4: What is the value of your potentiometer? The analog inputs of a UNO are designed for an input resistance up to 10k. A value much higher than that may cause the problems you described.

Always place capacitor between ground and vcc.

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