59
\$\begingroup\$

After learning and experimenting with microcontrollers, I've understood the concept of pull-up- and pull-down resistors. I now understand when and how to use them, and how they work. I've mainly used pull-ups because I was taught to, but it has always seemed a little backwards to me, as closing the switch sets the MCU input to LOW. I think it would make more sense to use a pull-down resistor, so that the input is LOW when the switch is open, but that is just my way of thinking.

Should I pull my single-throw inputs up or down? When is pulling down preferred over pulling up and vice versa?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ As an(other) electronics new-bee I have to say that this question is in no way stupid. Not become I don't know either, but because: "Viewed: 1989 times". \$\endgroup\$ Commented Sep 25, 2014 at 16:42
  • \$\begingroup\$ *because *12998 times \$\endgroup\$ Commented Sep 14, 2015 at 8:12

5 Answers 5

34
\$\begingroup\$

The answer depends on what you want the "default" configuration to be. For example, say you have a down-stream N-channel MOSFET, and you want it default off. Then you would use a pull-down resistor to ensure this behavior if the input becomes high impedance.

schematic

simulate this circuit – Schematic created using CircuitLab

On the other hand, suppose you have an upstream P-channel MOSFET, and want it default off. This time a pull up resistor is required to create this behavior.

schematic

simulate this circuit

There's also the alternative case where you want a device to be default-on, in which case the above two cases would be reversed (pull-up for the N-channel MOSFET, pull-down for the P-channel MOSFET).

A few other considerations:

  1. I2C lines specify pull-up resistors because devices are "expected" to have an open-drain to ground, and thus need some way to raise the line potential.

  2. Analog comparators are usually configured as open-drain devices, and thus also need pull up resistors to get a high potential output.

  3. You may draw more current using pullup/pulldown resistors, depending on what's hooked to the input/output.

  4. Either configuration could works equally well in your application (i.e. there's no significant advantage one way or the other).

... And any number of very application-specific reasons why one configuration may be preferred.

\$\endgroup\$
21
\$\begingroup\$

If the signal doesn't already have a specification, use whichever one makes the most sense to you. It is your choice to make an input active-high or active-low.

If it's buttons, make sure to use a debounce circuit (or do it in software).

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1 for the only side-by-side comparison of active-high vs. active-low I've seen. Nice, clarifies things. \$\endgroup\$
    – TomServo
    Commented Dec 1, 2018 at 11:10
16
\$\begingroup\$

If your circuit design is such that you can choose - in other words you aren't required by the rest of the circuit to use a pull up or pull down - then you should consider safety and security in the case of failure.

If your microcontroller fails, or just that output fails, the pull up or pull down will be in effect. How will this change the operation of your device? Will it put the user in danger - for instance by forcing a heating element on? Will it affect security, such as disabling a door lock?

Pull up/down resistors determine the default state of the wire. Deciding what the default state should be depends on safety, security, and finally the desired functionality of the circuit.

\$\endgroup\$
6
\$\begingroup\$

If you are working with an Arduino/ATmega328 you can use the built in pull-up resistor.

There are 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed by setting the pinMode() as INPUT_PULLUP. This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on.

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 Raspberry Pi has them as well.

\$\endgroup\$
4
\$\begingroup\$

You often want pull-ups or downs - often downs - on outputs of programmable devices like microcontrollers to define their state during power up sequences. Such outputs are often high impedance on power on, and connected devices can get unintended signals if this is not done. If for example multiple supplies are involved it's best to design each section as safe with zero volts on the inputs and to use pull-downs.

Bit more obscure than the other answers, but I've seen examples involving blue smoke and threats of legal action.

\$\endgroup\$
1
  • \$\begingroup\$ Clarification: the question was not why one should use pull-up or pull-down resistors, but whether one should pull up or down. \$\endgroup\$
    – osvein
    Commented Sep 25, 2014 at 17:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.