There are two ways of pulling the pins in Arduino – using internal and external resistor. I wonder when I should use external resistor instead of INPUT_PULLUP.
You can use either the internal or external resistor in normal application.
Each method has each own advantages:
- Pros: flexible to change by changing the code
- Pros: Reduce PCB size
- Pros: Reduce cost (very small)
- Cons: It may make MCU hot
- Pros: Reduce heat for MCU
- Cons: Not easy to replace when it is built-in PCB
- Cons: Increase PCB size
Besides, Pull-up and pull-down resistors are not only used for INPUT port but also for OUTPUT port. In the case of OUTPUT port. The external resistor has another advantage: flexibility in connecting devices with different I/O voltages. For example, in I2C hardware see I2C at the Hardware Level.
NOTE: As far as I know, at the writing time, Arduino library does NOT support INPUT_PULLDOWN
"Cons: It may make MCU hot"
It will not. P=V^2/R, so 5*5/20,000 = 1.25mW, that will not make the processor hot. Even turning all 80 in a Mega2560, and pulling them all low, will only dissipate 0.1W.
"NOTE: As far as I know, at the writing time, Arduino library does NOT support INPUT_PULLDOWN" That is because Atmega328P, '1284, '2560, etc. family of devices do not have internal pulldown resistors. Only pullup. See Section 14 of their datasheets, "I/O Ports".
This pullup is generally insufficient for I2C pullup, the rising edge created by the 20K to 50K internal pullup is very slow. External 4.7K down to around 2.2K (depends on how many I2C devices are connected) are needed. And the I2C bus spec says they should be at the end of the bus, not the origin of bus (which is generally the processor).
If you have a long wire coming from a button or switch, that is generally a good time to use an external pullup to ensure good switching levels between high and low.
The "Arduino Language" (i.e. the
pinMode() function) only knows INPUT_PULLUP.
So you need external resistors for PULLDOWN resistors.
OUTPUT signals are not floating, so the term PULLUP/PULLDOWN resistor does not really apply there.
Besides, the value of an internal pullup resistor is not adjustable. If that value (20 .. 50k) is not appropriate (I²C needs something less than 10k) an external resistor is required.