I keep hearing and reading about the importance of making sure all the unused inputs are pulled low with a resistor. No reason is given other than "don't keep them floating because you'll get unpredictable results!"
If you take a look at the picaxe 28X board, you see that all the digital inputs are pulled low with a 10K resistor. I understand that this makes it easier to just connect a switch to the pins on the board without having to add an external resistor. The analog inputs are left floating, almost as if by design.
Some people add jumpers next to the analog inputs so they are tied down, like here.
Can anyone explain why it is better to tie down the inputs? Is there a professor-Rik-like way to demonstrate a situation where not connecting them to ground makes the circuit fail?
Without a pull-down (or pull-up) resistor digital inputs can pick up static charge, or other sources of electromagnetic interference, that might cause the voltage on the input to rise high enough for the input to change state, even though its not supposed to. This can cause problems if the input is used somewhere in the code, but even if it isn’t used some digital inputs can waste excess power if they’re not totally in the on or off states, so it’s usually a good idea to tie the inputs down (or up) to be sure.
Adding a pull-up or pull-down resistor to an analog input will cause the read value to be offset either up or down if used, and even if it isn’t used analog inputs are made to work happily over the whole voltage range so leaving them floating typically doesn’t have any consequences.
If you want to do a little experiment, grab a microcontroller or a logic IC and connect a digital output to an LED, and a digital input to a short length of insulated wire. Make it so the LED is on when the digital input is high. Now power it up and try waving the wire around - touch the exposed end, rub the insulation on the carpet, place the wire close to a device that runs off mains power. You can ‘reset’ the input by touching the end of the wire to ground and discharging the pin that way, but you’ll find that it doesn’t take long for stray interference to make the wire’s voltage jump around again.
Second: I already tried to find a difference between floating ADC and tied ADC inputs. Telefox’ experiment can be lots of fun. My version used a PWM’ed LED for added light show effects.
But I did not notice any difference with the practice of tying the unused inputs. As with most best practices, I will continue to tie them anyway. Either up or down.
I am thinking you guys just want me to make a video showing me running around the room while swinging a piece of wire around
seriously; Thanks for those fast responses. I get the static electricity thing, but I’m still unsure how power is wasted through those pins. Is the amount of waste comparable to, say, power that is wasted when tying an input pin high?
Anyway. Now that I understand some of the theory, I’m still looking for proof of actual problems when not tying unused inputs down. I’ll tie them down, mind you, but I am still curious.
And of course I’ll give that experiment a shot. Sounds like fun. But you wont see me doing it on youtube.
The wasted energy thing comes down to one simple property - MOSFETS operate inefficiently when in between ‘on’ and ‘off’ states. Tying a digital input pin high or low locks the associated input circuitry in either the high or low state, and while in this state virtually no energy is used. By comparison an input that is fluctuating uses up a lot more power, but in reality “a lot more” is still a very small amount if you’re using modern microcontrollers.
In the end you should make a decision based on the application. If a wildly fluctuating input will play havoc with the code, or if energy consumption is much more important than PCB space, then a pull-up/down resistor is a good choice (if you don’t have them built in internally already). If PCB space is at a premium, and you’re not using a particular input, you could just as easily leave the resistor off.