[SOLVED]Difference between INPUT_PULLUP and an external pull down resistor?

Hello,

I am new to Arduino, and electronics in general. I was wondering what the difference between using the Arduino's built in 20K resistor using INPUT_PULLUP, and an external pull down resistor is, other then the logic being reversed where for example with a button HIGH means it is not pressed, and LOW means it is? When would I use one over the other?

Thanks

The main reason to use an external pulldown (or external pullup) instead of the internal pullup would be to match some requirements for the external device that you are connecting. A pushbutton switch, for example, is ether fully open or fully closed, and can have its other side connected to either ground or +V, so there is little reason to use an external resistor. Some sensors or other external devices will have more limited choices. A typical example would be I2C (twi) devices; the I2C protocol specifies an external pullup in a typical range of 1k to 10k ohms, so the internal pullup is not ideal. TTL logic devices are famous for having a "standard" pullup value of 2.2k, because their inputs actually consume some current.
A requirement for a pulldown is actually rather uncommon, except that it allows switches to match "expectations" that HIGH means "On"...

If you needed a pull-up, the internal pull-ups are handy - if you need either a pull-up or a pull-down, you would naturally go for pull-up and use the internal ones if you wanted to avoid installing extra resistors.

The internal pull-ups are very weak (datasheet says 20k to 50k - typically this is too high for a high-noise environment (lots of motors, automotive, factory...). An external pull up or pull-down would then be used - could be as low as 1k or so. Normally this is not an issue though.

If you are wanting to interface some buttons switches the most convenient setup is to connect the buttons between signal pins and ground (ground is always available), then pull-ups are required - this is why only pull-ups are provided, this is the common case.

Sometimes you need pull-downs though - because some other device mandates them, or because you want to power-down parts of the circuit without causing inputs to change.

Also sometimes you might be pulling down an output rather than an input (for instance the gate of an n-channel MOSFET is typicall pulled down with a resistor so that it doesn't do random things while the circuit is powering up or reseting.

Sometimes you might want to pull to a different voltage (3V3 for example when driving an I2C sensor that runs at 3V3 - the internal pull-ups can't do this)

Thank you both. So if I understand correctly, if a device I am using is compatible with the internal pullups, then I should use those, but if it isn't then use an external one, and only use a pulldown if something requires it, or if something is expecting on to mean HIGH, correct?

B1ueB1aze:
or if something is expecting on to mean HIGH, correct?

The question of HIGH = ON (or whatever) is based on however you write your code to interpret it. Consider:

  • switch_open = TRUE;
  • switch_closed = TRUE;
    Well, you can test for the switch being open or closed. It's more a question of how, functionally, you're thinking about the way your circuit operates.

or if something is expecting on to mean HIGH, correct?

Yes. A classic example is a simple SPST momentary push-button switch (a button switch). In reality the switch has only two physical states, being pushed or not being pushed. A mistake a lot of beginners make is assuming that they must wire up the switch such that when pushing it, it creates a HIGH at the input pin it's wired to. That of course would require an external pull-down resistor to place an electrical 0 when the switch is not pressed. The fact that the AVR chip has programmable optional internal pull-up resistor available for every input pin, it makes it simpler and cheaper to just wire the switch between ground and the input pin and then enable the internal pull-up. That means when the switch is pressed it will present a 0 to the input pin and when released a 1 will be read from the pin. That of course means that the programmer has to know that when the value of 0 is read from the pin that it means the switch is being pressed, but that is simply applying the correct logic to the programming statements being performed. So one should not restrict their thinking that a HIGH always means 'on' and a LOW always means 'off', as there is no real restriction on how you can interrupt a given logical state in one's program, it depends only on how the external signals are defined and wired up if it's to be interpreted as 'true logic' or 'negative logic'.

to be Lefty or NOT to be lefty, that is the question to be asked. :wink:

Just to be complete I should perhaps mention that a pull-up or pull-down is only needed when the signal source is only able to drive one way (a button switch can only connect to one of the power rails for instance. Most signal sources drive up and down (this is called totem-pole or push-pull output) - certainly most digital ICs drive most outputs this way.

Some buses and devices use an open-drain (sometimes called open-collector) output which only pulls down, requiring a pull-up resistor on the signal line. The I2C bus is a notable example.

Alright, thanks everyone.