Eating Batteries

I discovered^ that floating pins can, relatively speaking, consume a significant amount of power. This is particular important for battery powered applications. In my case, by enabling the internal pullup resistors, my project went from consuming about 28ma to consuming a steady 25ma.

  • Brian

^ "Discovered" in the sense that it's news to me; a newbee. I searched these forums for a similar post but couldn't find one.

Interesting.

What if you left the pins as "undefined", as in not either INPUTS or OUTPUS? Would that have an effect on the consumption?

What if you left the pins as "undefined"

As far as I can tell, that isn't possible. It's my understanding that a pin can be configured in three ways...

INPUT - this is the default on power-up
INPUT w/ Internal Pull-up Enabled
OUTPUT

If you know of a way to make a pin undefined, please let me know. I'm certainly willing to test.

  • Brian

So what happens on startup, if you don't do a pinmode() on a particular pin? Does it default to either input or output?

Pins default to input.

  • Brian

Pins do default to inputs, and it is generally NOT a good idea to leave digital inputs unconnected to anything; they can float "in between" the allowed digital states, which can cause excessive power consumption. Turning on the pullups is a good solution, actually...

Interesting information!

Why not have the Arduino in the next bootloader version set all inputs to have the pull-ups enabled as default?

Why not have the Arduino in the next bootloader version set all inputs to have the pull-ups enabled as default?

Probably best to not mess with the AVR default for input pins, say if interfacing with 3.3volt logic levels or other obscure interfaces the pull-ups be a problem.

Lefty

  1. @ Coding Badly, is there a typo in your original post, re: 28ma vs. 25ma? I reckon that as a 10-12% difference, or 6-7 minutes per hour of battery life.

  2. Keeping retrolefty's caveat in mind, would it be better for minimal power consumption to use setup() to consciously set the internal pull-ups on unused pins, or set all unused pins to output? (output LOW? HIGH?)

  1. @ Coding Badly, is there a typo in your original post, re: 28ma vs. 25ma? I reckon that as a 10-12% difference

No typo. I've measured the current using a few applications and the difference seems to be fairly consistent.

Bear in mind I'm using a multimeter to measure the current and, when the inputs are floating, the current can fluctuate wildly so it's a little difficult to get a accurate number. In other words, your milage may vary.

, or 6-7 minutes per hour of battery life.

How do you get that?

would it be better for minimal power consumption to set the internal pull-ups or set all unused pins to output

When I have time and if I can remember, I'll do some testing.

  • Brian

or 6-7 minutes per hour of battery life.

How do you get that?

10-12% of 60 minutes

If you're using a multimeter, I can do that here too. I'll race you... :wink:

10-12% of 60 minutes

Dang! I must be sleep-reading. :-[ Somehow I missed the "per hour" part of your message. Sorry about that.

I'll race you...

You'll definately win! Our new puppy arrived yesterday. Last night she kept us up all night and, from the look in her eyes, she is planning to do the same tonight. :cry:

  • Brian

In my case, by enabling the internal pullup resistors, my project went from consuming about 28ma to consuming a steady 25ma.

I assume this is on a 14-pin Duemilanove? Can you imagine what it would be on a Mega? :slight_smile:

Did you set just the digital pins, or the analog pins as well?

Did you compare setting to OUTPUT and LOW vs HIGH?

I myself have not gotten around to answering that question with my multimeter. I may not get to it right away either. In any case, we should have a number of independent measurements to compare to. I'll keep the thread posted with my results when I get to it.

Currently, I have a Teensy w/ Pins and a Teensy++ w/ Pins for testing...

http://www.pjrc.com/teensy/

The Teensy(++) has an onboard LED at pin 6 which is always turned off. For testing, neither Teensy was connected to anything except the USB port on a laptop.

The code used (which has some Teensy specific things in it)...

#define TEST_NOTHING    0
#define TEST_INPUT      1
#define TEST_PULLUP     2
#define TEST_OUTPUT     3

#define WHICH_TEST      TEST_OUTPUT

#define EXTRA_PINS      3

void setup( void )
{
  #if WHICH_TEST != TEST_NOTHING

    #if WHICH_TEST == TEST_INPUT
      const uint8_t pm = INPUT;
    #elif WHICH_TEST == TEST_PULLUP
      const uint8_t pm = INPUT_PULLUP;
    #elif WHICH_TEST == TEST_OUTPUT
      const uint8_t pm = OUTPUT;
    #endif

    #if defined(__AVR_AT90USB162__)
      const uint8_t dp1 = 0;
      const uint8_t dpN = 20;
    #elif defined(__AVR_AT90USB646__)
      const uint8_t dp1 = 0;
      const uint8_t dpN = 45;
    #else
      #error Put code here!
    #endif


    #if defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB646__)
  
      uint8_t i;
    
      for ( i=dp1; i <= dpN; ++i )
      {
        if ( i != 6 )
        {
          pinMode( i, pm );
        }
        else
        {
          pinMode( 6, OUTPUT );
          digitalWrite( 6, HIGH );
        }
      }

      #if WHICH_TEST == TEST_OUTPUT
        #if EXTRA_PINS >= 1
          digitalWrite( 7, HIGH );
        #endif
        #if EXTRA_PINS >= 2
          digitalWrite( 5, HIGH );
        #endif
        #if EXTRA_PINS >= 3
          digitalWrite( 4, HIGH );
        #endif
      #endif

    #else
  
      #error Put code here!

    #endif

  #endif
}

void loop( void )
{
}

WHICH_TEST can be set to...

  • TEST_NOTHING - don't touch the pins
  • TEST_INPUT - set all digital pins except pin 6 to INPUT
  • TEST_PULLUP - set all digital pins except pin 6 to INPUT with the internal pull-up resistor enabled
  • TEST_OUTPUT - set all digital pins to OUTPUT driven LOW; pin 6 is driven HIGH to turn off the onboard LED

EXTRA_PINS can be set to zero, 1, 2, or 3. This is the number of pins beyond pin 6 that are driven HIGH.

Results...

  • There doesn't seem to be any difference between configuring the pins as INPUT w/ PULLUP vs OUTPUT set LOW. The current was consistently stable at 20.02 mA on the Teensy and 40.5 mA on the Teensy++.
  • Floating inputs are bad news. The highest current consumed by the Teensy was 27.72 mA (28.5% higher than pins set to INPUT w/ PULLUP). The highest current consumed by the Teensy++ was 47.9 mA (18.3% increase).
  • If the LED on pin (6) is configured as an INPUT w/ PULLUP an extra 200 uA is consumed (20.04 mA vs 20.24 mA)
  • Unconnected OUTPUTs seem to consume the same (low) power regardless of their state

The conclusion for these two boards is the same. To reduce power consumption...

  • Unused pins should be set to INPUT w/ PULLUP or OUTPUT
  • Pin(s) connected to an onboard LED should be set to OUTPUT with the LED turned off

Good luck,
Brian

Was it ever established if enabling pullups in INPUT is better or worse or the same as setting unused pins to OUTPUT?

while a newbee to Arduino i have a little experience. It is generally good practice to define all pins not used as outputs set low. this will not cause any power consumption and after the intial writing of the registers, should not use any additional processor time. the problem with floating inputs is that the comparitors are still running as input buffers and using some ampunt of power, just in case you want to read the pin.

Lepton_man,
That makes sense. Thanks!

Just read this thread, very interesting, but I have a question
" by enabling the internal pullup resistors"
how is this done?
Thanks in advance from a new person.