Let's Make Robots!

Not all Arduino pins default to input!

Every now and then I come across a problem that takes a long time to solve. When I find the solution it is usually something very simple. I hope this will save someone else some time.

Today I am writting a program for testing the Spider controller. Since all the I/O pins connect directly to the processor there is not much that can go wrong. Basically the program just needs to check for short circuits and open circuits due to bad soldering or faults in the PCB.

Since the Arduino powers up will all pins set to inputs (according to the reference) and analog pins can also be used as digital pins I decided the simplest way was to short them all together.

The program would then scan through the pins one at a time. Change the pin to output, make it high, read all the other pins, change it to low, read all the other pins and then change it back to an input and move on to the next pin. Sounds good in theory.

In practice the first time round I got error messages when the output was supposed to be high indicating there was a short to ground. next time through the loop everything read ok.

The fact is when an Arduino powers up, all pins are set to input except pin 13 which has been set to output by the bootloader to flash the LED on pin 13. The first time through the loop pin 13 was pulled low and shorting my pins until it was it's turn to be tested. At the end of it's first test my program changed it to an input so there was no more problem.


This quote from the Arduino reference is incorrect!

Properties of Pins Configured as INPUT

Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode(). Pins configured as inputs are said to be in a high-impedance state.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Trying to control some motors I noticed I had to always pinMode OUTPUT.   I forgot once to pinMode the appropriate pins, but noticed #13 still worked.  I use BBBs now and they don't have the LED connected to 13 (its just off the regulator), it now makes sense the original Arduino/bootloader sets this to output, I guess for the "Hello LED" start here program.

BTW - nice debugging/QA process.