Digital Pins: Properties of Pins Configured As INPUT
Digital Pins: Properties of Pins Configured As INPUT
This also means however, that pins configured as pinMode(pin, INPUT) with nothing
connected to them, or with wires connected to them that are not connected to other
circuits, will report seemingly random changes in pin state, picking up electrical noise
from the environment, or capacitively coupling the state of a nearby pin.
The value of this pullup depends on the microcontroller used. On most AVR-based
boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it
is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the
microcontroller on your board.
When connecting a sensor to a pin configured with INPUT_PULLUP, the other end
should be connected to ground. In the case of a simple switch, this causes the pin to
read HIGH when the switch is open, and LOW when the switch is pressed.
The pullup resistors provide enough current to dimly light an LED connected to a pin
that has been configured as an input. If LEDs in a project seem to be working, but
very dimly, this is likely what is going on.
The pullup resistors are controlled by the same registers (internal chip memory
locations) that control whether a pin is HIGH or LOW. Consequently, a pin that is
configured to have pullup resistors turned on when the pin is an INPUT, will have the
pin configured as HIGH if the pin is then switched to an OUTPUT with pinMode().
This works in the other direction as well, and an output pin that is left in a HIGH state
will have the pullup resistors set if switched to an input with pinMode().
Prior to Arduino 1.0.1, it was possible to configure the internal pull-ups in the
following manner:
NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins
because it has an LED and resistor attached to it that's soldered to the board on most
boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V
instead of the expected 5V because the onboard LED and series resistor pull the
voltage level down, meaning it always returns LOW. If you must use pin 13 as a
digital input, set its pinMode() to INPUT and use an external pull down resistor.
Short circuits on Arduino pins, or attempting to run high current devices from them,
can damage or destroy the output transistors in the pin, or damage the entire Atmega
chip. Often this will result in a "dead" pin in the microcontroller but the remaining
chip will still function adequately. For this reason it is a good idea to connect
OUTPUT pins to other devices with 470Ω or 1k resistors, unless maximum current
draw from the pins is required for a particular application.