Getting wacky results when reading two analog pins

I seem to be getting some weird bleed through or carryover when I read two analog pins one after the other. Even when one has a static input, it still changes when I read a potentiometer at the same time. Anyone have any insight? I really need to get quick, accurate readings from

The setup:

  • Connect a 1M resistor between ground an A0.
  • Connect a 10M pot with the outside pins to Gnd and +5v, the center pin to A1.

Run this sketch and all will be well, A0 will report 0:

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

void loop() {
  int resistorValue = analogRead(A0);
  Serial.println(resistorValue);
}

HOWEVER if you run this sketch and rotate the pot the value of A0 will change too! In my tests instead of returning 0 it returns about 1/3 of the value of the pot!

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

void loop() {
  int resistorValue = analogRead(A0);
  int potValue = analogRead(A1);
  Serial.print(resistorValue);
  Serial.print(" : ");
  Serial.println(potValue);
}

Anyone have any idea what's going on and how to fix it? (Preferably in code since the circuit is on its way to printing.)

Troubleshooting attempted:

  • Different analog pins for both components: No change.
  • Different components (including the Arduino): No change.
  • Swapping the read order of the pins. No change.
  • Adding a delay between reading the pins. No change.

The input impedance of your analog voltage sources is way too high. To get accurate readings, it should be in the kOhm range, not the MOhm range.

When you take an analog reading, the voltage in the pin is used to charge/discharge a capacitor. If the input impedance is too high, the cap will not completely charge/discharge during the sampling time and you will get an incorrect reading that is biased in the direction of whatever voltage source was last used to charge the cap (i.e. whatever channel you last performed the analog read on). The way around this is to use a slower ADC clock (so that you sample longer), or to take many samples in a row without changing the channel, and discard the first few readings because those will be wrong. The point is that you need to give the ADC cap time to settle to the input voltage. There is no way to quickly AND accurately sample analog voltages with such a high output impedance (you're constrained by the RC time constant).

  • Ben

To get accurate readings, it should be in the kOhm range, not the MOhm range

I think the recommendation (from the datasheet) is 1K to 10K.

Also from previous threads with same topic, try to ground the unused analog inputs.