18

I am using the A0 port on my Arduino Uno to read the voltage output from an LM35 temperature sensor. I observed that the reading fluctuates a lot if I leave the remaining analog input ports A1 to A5 floating. Would floating analog inputs affect the accuracy of readings on input ports connected to some signals.

2 Answers 2

13

Any floating pin will act as an antenna, and may interfere with values around it, this is one of the major disadvantages of using analog.

To get the most accurate readings with minimal amount of interference, you can pull all unused inputs to ground.

The accuracy will not change, as the accuracy is determined by the sensor itself. However it will reduce the amount of noise / interference, which will give you more accurate readings.

These pull to grounds can be accomplished by configuring the unused analog pins as digital outputs, and setting them low.

pinMode(A1, OUTPUT);
digitalWrite(A1, LOW);
5
  • Not sure if it is a lucky guess, but driving an output pin (including An) low is the most energy effective way too. Driving high or enabling the pull-up consumes more energy from the power source.
    – jippie
    Commented Mar 3, 2014 at 5:59
  • @jippie - If you don't have any board leakage, they're likely to take about the same power. If you do have leakage, it depends on whether it's to power or ground. Commented Mar 3, 2014 at 7:39
  • 1
    @FakeName No they don't. I read an article one on the very issue. Driving the pin low takes approximately as much current as leaving it high impedance. Driving high or pull-up draws more current. I'll try to find the article later today.
    – jippie
    Commented Mar 3, 2014 at 7:42
  • I haven't read the article, but can confirm that driving all pins high pulls marginally more current than all low. Commented Mar 3, 2014 at 7:56
  • @jippie - Huh, that's weird. I'd expect totem-pole outputs to be symmetrical. Go figure! Commented Mar 3, 2014 at 8:19
1

Even if setting the unused pins to OUTPUT/LOW consumes a little bit less power than INPUT with PULLUP enabled, i guess the second option is more save.

To quote somebody else:

If you accidentally touch a hot wire to an output set low you short-circuit your processor and frie it. If you accidentally touch a ground wire to an output set high you short-circuit your processor and frie it. If you accidentally touch either wire to an input with pull-up you won't even notice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.