Arduino peripherals guide series

9

What to do with unused pins on an Atmega328P or Attiny85?

Is it OK to leave unused pins "floating"? The answer is in the datasheet of your favorite microcontroller. Let's decipher it here.

In most projects, you will end up with having several I/O pins on your Arduino or Attiny85 (a cousin of the Atmega328p) left unconnected.

What should you do with these pins?

Attiny85, datasheet recommendation about unused pins

Download the datasheet for the Attiny85.

Go to page 57 and have a read of section 10.2.6 Unconnected Pins. 

I am quoting here (emphasis mine):

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.

Atmel 8-bit AVR Microcontroller with 2/4/8K Bytes In-System Programmable Flash, page 57

You will find the exact same sentence in page 62, section 13.2.6, of the ATmega328P datasheet.

Datasheet recommendation interpretation

So, what does this mean?

If you want to be entirely compliant with the Atmel recommendation, you should connect any unused I/O pins to Vcc or GND via a large (~10KOhm) external resistor. In other words, you should not leave those pins "floating".

GND is preferable to Vcc as it reduces the risk of a short-circuits. 

If you don't want to add the additional external resistors in your circuit, you can simplify your design by opting for the MCU internal pull-up resistors. This, in effect, means that you will tie any unused I/O pins to Vcc. To do this, you can use the Arduino language "pinmode(pin, mode)" function.

Extrapolate for other integrated circuits

In general, you can follow the recommendation I have outlined above for other microcontrollers and their I/O pins. 

There's one differentiator: for unused output-only pins it doesn't matter if you leave them floating.

An example of a an integrated circuit that contains output-only pins is the 595 shift register that I demonstrate in my relevant lectures in Arduino Step By Step Getting Serious. You can leave such pins unconnected.

It's the programmable I/Os you need to think about more carefully. The guidelines from the datasheet should cover all practical cases.

"Arduino Peripherals" series

New to the Arduino?

Arduino Step by Step Getting Started is our most popular course for beginners.

This course is packed with high-quality video, mini-projects, and everything you need to learn Arduino from the ground up. We'll help you get started and at every step with top-notch instruction and our super-helpful course discussion space.

Tech Explorations Arduino intermediate level

Done with the basics? Looking for more advanced topics?

Arduino Step by Step Getting Serious is our comprehensive Arduino course for people ready to go to the next level.

Learn about Wifi, BLE and radio, motors (servo, DC and stepper motors with various controllers), LCD, OLED and TFT screens with buttons and touch interfaces, control large loads like relays and lights, and much much MUCH more.


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>