10

Below is a simple circuit involving an Arduino, a push-button, and an LED. However, I don't quite understand what the purpose of the resistor is. Wouldn't the circuit function without it?

Source:"MAKE: Getting started with Arduino"

Note: Since this question is concerning the behaviour of the circuit rather than the functioning of the Arduino, I've posted this here instead of the Arduino stack exchange.

Xetra
  • 103
  • 3
  • 5
    Very nice drawing, but we prefer schematics as they are easier/faster to read. There is a built in editor on the spaces where you can write your question. – Wesley Lee Apr 22 '18 at 18:57

4 Answers4

31

It's a pull down resistor, its purpose is to set the voltage of the Arduino input to 0 V when the button is open. It just sets a default voltage value to the connected node.

But, why is such a resistor needed? Well, when the button is open, the voltage is not totally equal to zero due to antenna effects or surrounding components. It is then possible that the Arduino input is triggered for no reason.

Note that the value of pull up or pull down resistors is usually around 10k - 100k. If the value is too low, it's going to draw too much current when the button is closed. If the value is too high, the resistor will behave as an open circuit, making the pull down resistor useless.

As it is widely used in electronics, I recommend you to read some more about this concept.

Null
  • 7,448
  • 17
  • 36
  • 48
M.Ferru
  • 3,926
  • 3
  • 22
  • 48
  • 5
    Simply call it "floating" :) – Long Pham Apr 22 '18 at 15:02
  • 6
    Even absent crosstalk, there's no reason that the voltage would change to zero when the switch opens. The intrinsic capacitance in the GPIO pin would tend to hold the voltage, and that will slowly drift due to non-zero leakage current. Depending on the direction of that current, it could drift down toward 0V but could also drift upwards. – Ben Voigt Apr 22 '18 at 17:22
15

This looks like a pull-down resistor.

a pull-[down] resistor is a resistor used to ensure a known state for a signal.

[They] are used in electronic logic circuits to ensure that inputs to the [microcontroller] settle at expected logic levels if external devices are disconnected or high-impedance. 'Just because you have nothing at all connected to an input pin doesn't mean it is a logical zero.'

[D]igital logic circuits have three logic states: high, low and floating (or high impedance). The high-impedance state occurs when the pin is not pulled to a high or low logic level, but is left “floating” instead. [...] a microcontroller might unpredictably interpret the input value as either a logical high or logical low. Pull-[down] resistors are used to solve the dilemma for the microcontroller by pulling the value to a logical [low] state

By the way, as your LED seems to lack a current limiting resistor, it will likely burn out pretty quickly, unless it has some integrated current limiting circuitry that is not visible in the drawing.

Dampmaskin
  • 3,787
  • 1
  • 16
  • 29
  • Good, complementary and helpful answer, as you include actual links instead of just lecturing "[...I recommend you to read some more about this concept.](https://electronics.stackexchange.com/a/370063/102305)" – uhoh Apr 22 '18 at 15:39
  • @uhoh Except link-only answers are not so valuable on SE since links often die or change. – Todd Wilcox Apr 23 '18 at 16:41
  • 1
    In my defense, I don't think anyone expects Wikipedia to go away anytime soon. But yes, it did enter my mind. Would it help if I quoted some of the key points from the links? – Dampmaskin Apr 23 '18 at 17:00
  • @Dampmaskin that's the *ideal* answer at least, a nice concise, clear explanation together with helpful supporting links. – uhoh Apr 23 '18 at 17:10
  • I have now inserted quotes/paraphasings from the sources, to increase its long term usefulness. – Dampmaskin Apr 23 '18 at 17:40
5

People tend to think that undefined is equal to zero. Compare it to something in a store that has no price label: customers will joke it is for free ($ 0.00), but it is not: the price is unknown.

It is the same with voltages/potentials. If you simply remove the resistor and the button is not pressed (not conducting) the potential on input 7 is not defined. It is tempting to say it will be 0V, but there is no reason for it to be. By connecting it to 0V (gnd) trough a (pull-down) resistor it suddenly is defined: there is no current (where would the energy come from), so the voltage over the resistor must be 0V as well. 0+0=0V.

If we replace the resistor with a short circuit (between the button and gnd) the voltage would be zero as well, as long as the button is not pressed (not conducting). But what would happen once you press the button? The left side of the button is at 5V, the right side at 0V (gnd). The result is a short circuit: the maximum current will flow from 5V to the gnd and you still do not have a defined voltage at input 7 (and on top of that things can get pretty warm).

Johan
  • 155
  • 4
1

Pull-down resistor in a digital circuit can be seen in the figure. A pushbutton switch is connected between the supply voltage and a microcontroller pin. In such a circuit, when the switch is closed, the micro-controller input is at a logical high value, but when the switch is open, the pull-down resistor pulls the input voltage down to ground (logical zero value), preventing an undefined state at the input. The pull-down resistor must have a larger resistance than the impedance of the logic circuit, or else it might be able to pull the voltage down by too much and the input voltage at the pin would remain at a constant logical low value – regardless of the switch position.

Taken from below site Read more http://www.resistorguide.com/pull-up-resistor_pull-down-resistor/

user186641
  • 21
  • 3
  • 1
    The OP is asking about the pull-down resistor connected to the switch. He hasn't shown (or asked about) the required current-limiting resistor in series with the LED. – Peter Bennett Apr 22 '18 at 18:05