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.
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.
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.
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.