Why use pull down resistors?

In the tutorial section here:
http://www.arduino.cc/en/tutorial/button

it says that:

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor)

Why does it connect the pin 2 to the ground using a resistor? Can't I simply connect a wire from the ground pin to the lower leg of the pushbutton at place of the resistor? If not , then what is the reason behind it?

Because it wouldn't work.

Time for me to go to bed.

That I know but what's the reason?
Now if pin 2 were a potential source then i know there wouldn't be any charge flow because by shorting I would essentialy be creating a equipotential circuit so no charge flow.

I've been studying stuff and have done nothing but ask questions on this forum, so let me take a swing at it. If you didn't have the resistor, the arduino pin would be connected to the arduino ground through the button when it was pressed. When you didn't press the button, their would be no connection at all since the button is now "open" or lack of a better term, broken. So the resistor is there to maintain the connection from the pin to the ground so that the circuit can continue.

I may be wrong but I would think of it like this. Lets say you are the pin, and your sole purpose was to check if a button was on. How would know the button was pressed if you weren't, urself, already on? With the resistor, there is a constant flowing circuit, and when the button is pressed and "closed" then you can say "ok, now I see this button is on in my circuit and I can do whatever the button is telling me to do."

Hopefully that didn't do more harm than damage, but that's how I see it in my mind, can someone fact check? :smiley:

EDIT* I am assuming that we use a resistor to limit the voltage coming from an arduino and going right back into itself. I believe that if you used just a jumper wire, to make the connection it could harm the arduino with too much voltage, or may even increase voltage exponentially...which would literally make the arduino explode XD

When the switch is not pressed, it makes no connection between the Arduino input pin and +5V - the pin is just "floating".

Without the resistor, there is a chance that the input pin would pick up electrical noise and read it as a positive voltage, causing a false reading (as if the switch had been closed).

Adding the resistor between the input pin and ground holds the input pin at ground when the switch is open - much less chance of a false reading.

The value of the resistor means that, when the switch is closed and it connects the input pin to +5V, you still get a correct reading.

By the way, it is better practice to use a pull-up resistor to +5V (or the internal pullup inside the Arduino chip) and have the switch wired to connect to ground when closed.

Why does it connect the pin 2 to the ground using a resistor? Can't I simply connect a wire from the ground pin to the lower leg of the pushbutton at place of the resistor? If not , then what is the reason behind it?

If one side of the switch is connected to +5V and the other side of the switch is grounded, you'll have a short between +5V and ground when you push the button (and you'll kill the power and maybe damage something.)

If you had a double-throw switch you could switch between +5V and ground. (That's not normally done on the input of a microcontroller.)

FYI - The arduino has optional [u]Internal Pull-up Resistors[/u]. If you enable the internal pull-up, you can use that instead of a pull-down and you don't have to supply the resistor.

Of course with a pull-up, the button is wired differently and pushing the button forces the input low. That means you have to reverse the logic of your sketch.

Hackscribble:
When the switch is not pressed, it makes no connection between the Arduino input pin and +5V - the pin is just "floating".

Without the resistor, there is a chance that the input pin would pick up electrical noise and read it as a positive voltage, causing a false reading (as if the switch had been closed).

Adding the resistor between the input pin and ground holds the input pin at ground when the switch is open - much less chance of a false reading.

The value of the resistor means that, when the switch is closed and it connects the input pin to +5V, you still get a correct reading.

By the way, it is better practice to use a pull-up resistor to +5V (or the internal pullup inside the Arduino chip) and have the switch wired to connect to ground when closed.

I get your point that the pin needs to be connected to the ground. But my doubt is that instead of using an additional component(resistor) to connect the pin to ground, can't I simply hook a wire directly to the ground at the place in breadboard where resistor is placed. In that case pin 2 would still be connected to the ground.

You're missing the point of what would happen with wire when you CLOSE the switch.

When the switch is open the resistor pulls the input pin to ground. A wire (as you propose) would do exactly the same. Score: Resistor 1, Wire 1.

When the switch is closed a piece of wire would create a direct short between 5V and GND. The resistor doesn't. Score: Resistor 1, Wire nil.

Resistor wins 2, 1. :wink:

yaafm:
You're missing the point of what would happen with wire when you CLOSE the switch.

When the switch is open the resistor pulls the input pin to ground. A wire (as you propose) would do exactly the same. Score: Resistor 1, Wire 1.

When the switch is closed a piece of wire would create a direct short between 5V and GND. The resistor doesn't. Score: Resistor 1, Wire nil.

Resistor wins 2, 1. :wink:

wait...really? I thought if you added just an ordinary wire, it would act as if it was just an extra long ground cable. maybe I am unfamiliar with what a Short is, but if you had an ordinary wire, you would just have a button that was connected to a pin, a positive, and a ground. I guess my question is, if you a button connected to a postitive and a ground, there wouldn't be an issue, so what part of connecting it to the pin is causing the short?

@resistorswtf - well they say experience is a good teacher so why don't you try it. :smiling_imp:

Here's the usual things seen.
Top left - external pulldown resistor, button connects pin to Vcc (+5) for a HIGH reading.
Top middle - what can happen - wiring mistake allows button to connect Vcc to Gnd, causes processor to reset. May take out the power supply or regulator.
Bottom left, bottom right - no resistor, after button release, input pin "floats" around affected by hands waving around, input can read HIGH or LOW.

Top right - preferred method. Use internal pullup, button to Gnd only, no external connection to Vcc, no chance of shorts, no extra parts needed. Code looks for a LOW to indicate a button press:

// in setup()
pinMode (pinX, INPUT_PULLUP); //input with internal pullup
or
pinMode (pinX, INPUT);
digitalWrite (pinX, HIGH); // enable internal pullup

//then in loop():
pinState = digitalRead(pinX);
if (pinState == LOW){
// button pressed, do something
}

or
if (digitalRead(pinX) == LOW){
// button pressed, do something
}

yaafm:
@resistorswtf - well they say experience is a good teacher so why don't you try it. :smiling_imp:

Challenge accepted! lol jk, I don't doubt the knowledge on these forums, so im sure it would short, my question would just be what caused the short...after some googling and reading up on good ol' Thévenin and his damn theorem I think I understand. A positive and a ground are not supposed to operate on the same voltage. With a resistor, the V's are "resisted" and lowered before they hit the ground on the arduino. If you just use a cord, all you are doing is using a switch to connect a 5v power supply to a ground wire and run it straight into the arduino. I assume quite a bit of damage would result...it would be the equivalent of running a wire straight from ur power pin to your ground pin right?....or I could be completely wrong. Can I get a google power fact check?

Yes, connecting Power direct to Gnd is bad.

CrossRoads:
Yes, connecting Power direct to Gnd is bad.

IKR? these are the kinds of things that I figured I would have read on the forum on day one. My name is resistorwtf because I don't understand them. Complete noob and it would have helped to see something like that. Not being sarcastic at all, some of us are TRUE beginners, so its like, we plug one side of a battery to a motor, and the other side to a battery, and it comes on, we would think that the same current was flowing to both sides so there is no issue, but obviously in that scenario the current it takes to slow down the current is preventing the short when it gets back to the ground...but as soon as it pieced it together I thought about a car battery when u touch jumpers together :smiley: click