Default pin mode

I am using Nick Gammon’s article on low power, I recommend it. It has been falling off a log easy to create a device that I think will run for, well, a looooong time.

As I add to the basic success I wonder why the default pin mode is INPUT and not INPUT_PULLUP?

Some years ago — never mind how long precisely — when we played with CMOS the rule was to never leave inputs unconnected… the idea was that a floating input might maneuver the chip or gate or whatever into a condition where we would not enjoy the extreme low power CMOS provides.

And around here, many problems are solved with a pull-up resistor or a change to INPUT_PULLUP.

So it seems a more logical default condition would be to have the internal pull-ups enabled.

I understand why that might not be a desirable behavior for the chip out of the box, but with the Aduino propensity to protect all over us because we idiots, it seems like init() might have just enabled all the internal pull-ups.

So. Is there that “floating input leads to power consumption” problem here? Or am I remembering incorrectly the logic behind making sure every input goes somewhere, tied to ground e.g. if unused?



Simply because low power is a very much niche application.

When driving CMOS outputs, INPUT_PULLUP equates to driving HIGH. Any grounded load - such as a LED - connected to a pin will be driven with 100 µA.

Sorry, a non-starter! :roll_eyes:

Yes, I saw that ~100 uA with a switch wired to ground. Why would you put an LED on an input pin?

I don’t understand why making all inputs pulled up internally by default is any problem. However that is accomplished.

And what am I misremebering about the floating input thing? Is is OK to leave a CMOS input not pulled up when its logic value (or in-btweeness) is not relevant, like an unused input?

With an logic gate e.g. I know that an unused input must be 0 or 1 because it contributes to the value of the output.

With an input pin one is ignoring on a microprocessor, does it matter that it might be anywhere from 0 to 1? Power consumption or otherwise?

Or exposed, so to speak, to the same thing that makes reading it result in randomly 0 or 1, is that static electricity or moon beams or ions or what?

I’ve long been in the habit of doing something with unconnected pins unless the data sheet marks them as NC.

So… I think I have an idea, but how could I connect, say, a 4 pin DIP switch to 4 inputs and be able to read them during the periodic wakey wake and not have them drawing N * 100 uA where N is the number of switches switched ON to ground?



Because you want to program the pin as output and blink the LED ?

>Why would you put an LED on an input pin?<
Maybe to display the input-state… There’s an output or a switch, or something, driving that input…

>And what am I misremebering about the floating input thing? Is is OK to leave a CMOS input not pulled up when its logic value (or in-btweeness) is not relevant, like an unused input?<
I’ve always left unused inputs floating and “unconfigured”. I suppose you could configure them as outputs… I don’t know if an unconnected output “consumes” any additional current.

>So… I think I have an idea, but how could I connect, say, a 4 pin DIP switch to 4 inputs and be able to read them during the periodic wakey wake and not have them drawing N * 100 uA where N is the number of switches switched ON to ground?<
You could disable the pull-ups after reading.

Per AVR1010: Minimizing the power consumption of
Atmel AVR XMEGA devices

Inputs should not be left floating, to minimize current draw

2.9 State of Digital I/O Pins
All digital I/O pins are by default floating to avoid hardware conflicts. However, since the pins have digital input buffers it is important to ensure that the level on an I/O pin is well-defined to avoid sporadic internal switching and leakage. The leakage caused by floating I/O is relatively small and is mainly observable in sleep, but can be minimized by ensuring that the state of the pins is either high or low.
If a pin is connected to an analog source, the digital input buffer on that pin should be disabled even if it is not configured as an input. This is done by use of the PINnCTRL registers for the individual ports. Please refer to the device manual for information on how to do this configuration.

To minimize power consumption, enable pull-up or -down on all unused pins, and disable the digital input buffer on pins that are connected to analog sources.

THX @CrossRoads!

I’ll admit this game is addictive. Once I was seeing sub-milliamp current I was looking for every 0,1 uA I could…

I think this kind of obsession must obtain in the design of vast quantities of modern portable electronic equipment we all carry around with us - I wish someone would combine this years batts with the circuits of a few years ago.

Like I always advise people to run the oldest software they can bear on the fastest hardware that it will run on. My newest computer is the fastest I’ve ever had, but it does not feel as that way UI-wise.


Only power consumption. The reference to “sporadic internal switching” in what CrossRoads cites is only of significance if you read the input.

Static electricity - and AC mains field anywhere there is mains electricity.

Good idea - you set them to INPUT_PULLUP in your code, but you know which ones your code/ hardware does not use, it’s your business, not the compiler.

Using Windoze will cause that. Windoze 10 is presently fouling up my work computers no end! :roll_eyes:

1 Like

Yes IC. I have come to think of we who use Arduino as victims beneficiaries of the preprocessor, that init() off somewhere, and gee, you could be some time before concluding that there has to be a main() involved at all.

Given the number of times it’s a missing pull-up resistor or failure to enable internal pull-up that causes some noob a headache, I would not have been surprised to find that the Arduino ppl hadn’t just included switching them all on in the init().

THX again. All.

I’ll try the several ideas I now have for my DIP switches and when none of them works ask y’all about it…


I think that the analog pin is connected to the ADC input multiplexer, so if you do not read that pin, it is not connected to anything else (except the internal pull-up, if you enable it).
Also for digital inputs, if you do not read the pin, you don’t care if it is floating.

Not true. That sporadic internal switching still draws some power; best to pull the pin high so there is No switching. Think of it as the pullup is charging up some gate capacitance, after that there is no switching, thus no current flow.

Why would they do that though? You can’t do low power on a vanilla Arduino board. You either have to do extensive modification of the hardware, or set up your own circuit. Once you’re that advanced, you should be capable of minding your own inputs.

Unless the pin is used as an interrupt source the digital buffers are disabled in sleep so they do not draw current even in sleep. Worst case current consumption of a floating pin (at room temperature) is 100uA but usually it is much less.
The extra current consumption is not from internal registers changing state but from a “shoot-through” current of the digital buffer when the input voltage is close to its threshold.

You need to be able to connect a pin to a device with its own internal pull-down - at power up that will misbehave if the pin is pulled up as well. (Many motor driver and stepper
driver chips are like this for instance - don’t want them going haywire at start-up!)

No, floating inputs can definitely consume power and read randomly - for a micropower application you’d just tie all the unused inputs to ground to solve the problem.

Sorry, that does not make sense.

If they were all switched on by default, there would automatically be a whole new set of noob headaches such as spooky dim LEDs and all sorts of other malfunctions! :astonished:

Sorry, it is true by your own argument.

I said

You refer to power consumption.

But the argument is that setting them to INPUT_PULLUP is safer as it pulls them fully up but there is no possibility of them being accidentally set to output and HIGH when tied to ground.

OK, that’s something I can get my teeth into, THX.

Haha, I guess so. Noobs be noobs and they will always find a way to show it. I’m glad I so old that most of my own noob period is not part of the record. Only dim personal memories .

For a conservative chap like myself, it seems that unused inputs should be individually sent somewhere with a resistor, like I am in the habit to do with gate inputs.

I’m down to 7 uA during sleep. I think there is more to find but that should be enough for my device to last long enough so its job will be finished before a set of batteries runs out.


I wouldn’t worry, the battery chemistry’s self-discharge rate will be now be the
limiting factor, and once you start powering up every hour for 1 second at 25mA,
you already average 7µA anyway… Under 10µA is usually good enough unless using
exotic power sources such as harvesting ambient RF signals.

Noted. Now it’s down to something of a game.

I’m experimenting to see if I can ditch the watchdog timer, a “major” energy consumer.

I need periodic wakey wakey and pushbutton wake-ups.

I need to track time, but not with so much accuracy that I would need an RTC, but if the RTC can win the energies war that will just be a win-win as good timing would be nice.

Nick Gammon gets around to worrying about 65 mS of power-draining oscillator stabilisation time…

BTW I have come across too many devices where the batteries (like Duracell AAs) have leaked… is there something batteries of that kind do not like about continuous very low current drawn?


The only batteries I recall being suitable for very long term use are primary lithium and
silver-oxide - they have decade-long shelf lives. zinc-carbon cells will run down in a year
or two and always leak if left unattended for long periods. alkaline cells are supposed
not to leak, but some do, old NiCd’s tended to leak badly, newer NiMH seem to be much
better. The hybrid NiMH have a longer self-discharge time than standard NiMH (which
discharge on a timescale of months). ?

Thank you! Yes I am lazy and picking your brains.

I am familiar with the battery university, I have avoided some pain and misery by going a bit deeper into Lipo safety than some.

Recently found a local recycler for a veritable crap-ton of batteries across many chemistries, ages, use cycles, leakiness and abuse.

I sleep better.