Unused pins : what to do with them ?

I have read an old thread on the subject, and wanted to post a reply, but the thread was 8 years old and was warned to start a new thread.

It appears as though the "best practice" (at that time) for unused and unconnected pins is to define them as INPUT, and enable PULLUP.

Has anything changed ? Is this still the best way to handle unused pins, including Analog pins ?

If it is the case, then I'm considering writing a function that will set ALL my pins as INPUT, PULLUP, and call it at the start of setup(), then my setup code can re-define them as needed. That will ensure I don't forget any. Can anyone think of any problems this might have ?

TIA

Nothing has changed and your plan is a good one. 8)

What is the reasoning behind that?
Leo..

I must confess I have always ignored my unused pins and have never had a problem.

...R

However if pins are initialised as INPUT_PULLUP and later need to be set as an OUTPUT LOW, it must be written LOW before making it an OUTPUT, otherwise there will be a brief HIGH pulse.

Of course, it will be weakly HIGH anyway on INPUT_PULLUP.

In conventional digital logic gates, the unused input lines are tied to ground potential to ensure that none of them can pick up any noise signal. For MCU based final design/product, I still follow the same strategy -- configure the unused IO lines as inputs without internal pull-ups and then tied them to ground potential.

For conventional logic gates that is because they will react to changes on the inputs. This is why you can't leave them floating, or they may start using excessive power with gates switching all the time or even ending up in undefined states.

Your Arduino doesn't do anything with unused inputs.

Check and see what init() does - BEFORE writing code for setup()!

Mark

The Datasheet in Unconnected Pins section says:

If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode).
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. In this case, the pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pull-up or pull-down. Connecting unused pins directly to VCC or GND is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output.

In other words setting unused pins as INPUT_PULLUP is the best practice as OP says.
Letting them float is probably acceptable solution if you are not interested in possibly increased power consumption it is a viable option.
Connecting the pins to power rails or to each other is dangerous practice - with no real benefit.

1 Like

Smajdalf:
Connecting the pins to power rails or to each other is dangerous practice - with no real benefit.

I've seen guidance where unused pins are configured as output/low and wired to ground. The rational is that these are effectively additional ground pins which reduces the noise level induced on ADC measurements by digital outputs switching. Obviously this presents the risk of damage from misconfiguring the grounded pins, but the bigger point is that the "optimum configuration" depends upon what performance one is trying to optimize.

The additional power draw from leaving unused pins floating may be insignificant during normal operation, but in low power sleep modes, it can be a dominant contributor to power draw.

There may be some strange applications for using GPIO pins as additional (or alternative) power pins but you should know why you do this. Not as a "default configuration". There is always some application where not following "best practices" is better - but you should know what are the reasons behind the "best practices" and why it does not apply at your particular case.

MrMark:
I've seen guidance where unused pins are configured as output/low and wired to ground. The rational is that these are effectively additional ground pins which reduces the noise level induced on ADC measurements by digital outputs switching.

An I/O pin has a 50 Ohm effective resistance. Compared to the straight ground bonding to the substrate, the effect would be negligible. :roll_eyes:

Compared to the risk of accidentally shorting out a pin, simply not worth it at all. :astonished:

The IO pins default to INPUT LOW. Just what happens if they're left to float? Please, they're in Z-state, if you don't read them (the unused pins part of the description) then how is there an actual not might-do problem worth noticing?

An interesting discussion...

I am doing a couple of projects, and finalising detail of PCB's etc

I will be implementing a global initialisation function to set all my pins to INPUT_PULLUP as I suggested. Here is how it is as of now, for the Nano, and the Teensy 3.2, but I will be adding other boards as I use them. My PCB designs will be grounding unused pins, as there is little chance I will ever need them once PCB production has occurred.

void unusedPins() {
  for(int i=2; i<=12; i++) {
    pinMode(i, INPUT_PULLUP);
  }
 pinMode(13, OUTPUT);        // LED Pin
  for(int i=14; i<=19; i++) {
    pinMode(i, INPUT_PULLUP);
  }
#ifdef Teensy_32
  for(int i=20; i<=23; i++) {
    pinMode(i, INPUT_PULLUP);
  }
#endif
}

I never have had to use pin 13 as anything other than the LED, but don't see any reason for it not to be an input, even if it does have a resistor and LED on it. It just means the driving circuit will need to deliver the LED current, in order for the pin to reach VinH.

1 Like

Input pins are sampled and synchronized to the clock. The related flip-flops consume power and produce internal noise when toggling due to noise on floating inputs. If mode INPUT_PULLUP is too weak, the unused pins can be connected together and pulled up by a single lower external resistor.

DrDiettrich:
Input pins are sampled and synchronized to the clock. The related flip-flops consume power and produce internal noise when toggling due to noise on floating inputs. If mode INPUT_PULLUP is too weak, the unused pins can be connected together and pulled up by a single lower external resistor.

The increased current consumption is caused by the digital buffer, not the flip flop - it is increased when signal is close to Vcc despite no switching happens (i.e. the MCU is in a sleep mode where I/O clock is stopped).

Connecting unused pins together is as bad idea as connecting them to a power rail. You turn them as output by mistake and BOOM! Anyway since the pin is unused it is not connected to a long wire/trace - its capability to pick up noise should be small and even if it toggles rarely nothing bad happens. The problem is only a floating pin dragged to a voltage close to Vcc/2 for some longer time.

daba:
My PCB designs will be grounding unused pins, as there is little chance I will ever need them once PCB production has occurred.

This is a bad idea. The problem is the code may turn the pins OUTPUT HIGH by mistake. When this happens ANYTIME, it will probably damage the product. INPUT_PULLUP is safer.

Smajdalf:
The problem is the code may turn the pins OUTPUT HIGH by mistake.

When was the last time you had code that did anything "by mistake" ?

daba:
When was the last time you had code that did anything "by mistake" ?

It may come from a bug in your SW. A power glitch may cause wrong code execution. The probability of such error may be very low and damage not severe. But since you gain nothing by grounding the pins why do you want to take the risk?

If you don't ever read the UNUSED PINS LEFT AS INPUT then none of the terrible consequences happen, do they?

Like what happens when someone applies house mains across Arduino VCC and GND, just because it could?

A lot of Arduinos have led13 powered by an opamp that will dimly light the led when the pin is INPUT_PULLUP.
There's your power suck, small as it is and no mistake needs to happen, it's coded to do that.

GoForSmoke:
If you don't ever read the UNUSED PINS LEFT AS INPUT then none of the terrible consequences happen, do they?

They DO happen: peripheral circuit reading the pin have no idea if the CPU will decide to read the pin. So it reads it and prepares the value in PINx register every clock cycle. If the pin floats AND is close to Vcc/2 it may lead to increase current consumption. Again, look into the Datasheet, it is described here (or look at my post #8 where the most important part is cited). But this is only increased current consumption - depending on application it may be negligible - not much terrible consequence. Really terrible ones may happen only if you connect the unused pin to GND, Vcc, another pin or other low impedance source - which is a bad practice despite suggestions of others.

GoForSmoke:
A lot of Arduinos have led13 powered by an opamp that will dimly light the led when the pin is INPUT_PULLUP.
There's your power suck, small as it is and no mistake needs to happen, it's coded to do that.

A pin driving a LED either directly or via an op amp may be hardly considered "unused".