Read the pin twice and keep the second value, or add a short pause after changing channel.
What the message means
The converter has one input shared by all pins. Right after switching, the sampling capacitor holds some charge from the last pin, which pulls the first reading.
Fix it in this order
- Call analogRead twice and use the second result.
- Or add delay of a few milliseconds after changing the channel.
- Use sensors with a low output impedance, or add a buffer for high-impedance ones.
- Add a small capacitor across the sensor output close to the pin.
- Average several readings.
Why it happens
The Uno’s converter has one sampling capacitor shared by all analog pins through a multiplexer. After a channel switch the capacitor still holds some charge from the previous pin and needs a moment to settle on the new one. The ATmega328P datasheet recommends a source impedance of about 10 kΩ or less, because a higher one charges the capacitor too slowly and makes the first reading wrong.
Reading twice and discarding the first result is the usual fix. A buffer or an op-amp follower helps with high-impedance sensors, and a small capacitor at the pin supplies charge for the sampling pulse.
If you see this, do this
| You see | Do this |
|---|---|
| Value drifts toward the last pin | Settle the ADC. |
| Large noise on all readings | Add a capacitor and average. |
Related
unconnected analog pin, ESP32 ADC noise.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
Why this happens
The ADC in an AVR chip has one sample-and-hold capacitor shared by all analog pins, fed through a multiplexer. When you change channel, the capacitor still holds charge from the previous pin and must settle to the new voltage within the sampling time. The datasheet for the ATmega328P recommends a source impedance of about 10 kΩ or less. A sensor with a higher output resistance cannot refill the capacitor quickly, so the first reading after a switch is pulled towards the old value.
The effect is largest when two neighbouring channels have very different voltages, for example one at 0 V and one at 5 V. Reading the same channel twice and keeping the second value is the common cure.
How to confirm the cause
- Connect A0 to ground and A1 to 5 V, then alternate reads between them and print each result. If the first read after the switch is off by tens of counts and the second is right, you have the settling effect.
- Measure or estimate the output resistance of the sensor. A potentiometer with a large total resistance or a sensor with a series resistor is a likely cause.
- Compare the result with a single channel read repeatedly. If that is stable, the multiplexer switching is the cause.
- Add a short delay between channel switch and reading and see whether the error shrinks.
Worked example
A helper that throws away the first reading after selecting the channel. The delay is small and can be tuned.
int readSettled(int pin) {
analogRead(pin); // discard: mux and capacitor settle
delayMicroseconds(100);
return analogRead(pin); // keep this one
}
void loop() {
int a = readSettled(A0);
int b = readSettled(A1);
Serial.print(a); Serial.print(' '); Serial.println(b);
}Common mistakes
- Averaging the first reading into the result.
- Driving the pin from a high-resistance divider and expecting a fast reading.
- Reading a floating pin and treating its wander as a fault in the code.
- Switching channels in a very tight loop with no pause for a high-impedance sensor.
- Applying this advice to an ESP32 without checking its own ADC behaviour.
If this did not fix it
- Noise on the reference or the supply; a 0.1 µF capacitor close to the sensor output can help.
- On an ESP32 the second ADC group cannot be used while Wi-Fi is on.
- A sensor that needs warm-up time after power is applied.
- A divider with large resistors; lower the values or add a buffer.