Push button on arduino

Hello,
I would like to try the push button example with the arduino but the following circuit desc confuses me:

 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

First of all. If I connect the push button to the pin 2 directly, like

5V o----push-button-----o pin 2
and nothing else, do I get a short while pressing the button? Or are the pins protected for such stuff?

Now to the circuit: I get the first line, since this is basically what I meant I would have done.
But I dont get the second line. Is this to protect the arduino? And protect from what? I dunno how much Ampere Arduino's 5V provides, but 10K reduces it to pretty nothing, is that right? Would it get too much otherwise?

Damn, I dont have enough 10K resistors then

Without the 10K resistor, the state of the pin is undefined. When the switch is pressed, 5V is connected to the pin, and it is definitely HIGH. When the switch is released, what is the voltage at the pin?

Connecting the pull-down resistor pulls the pin down to ground when the switch is released, eliminating the ambiguity.

Ohm's law (V = IR) says that a 10K resistor (R) and 5V (V) results in a current flow of 5/10000 or 1/2 a milliamp. That's pretty nothing, all right.

4.7k would work also

but really if you did it backwards you would not need a resistor because the atmega chip has internal pull up resistors (and personally it makes more logical since, when the button is down so is the signal)

darn, I dont have enough 10K resistors then

You only need one (per switch). You could use 2 5K resistors in series. Or, any values that add up to approximately 10. Or, you could use 2 20K resistors in parallel.

I stiull have some issues to get that. When button is pushed I have a high, why do I not have a low when I simply release it?

And could some body show me the circuit or tell me where to add the resistor since I have issues to see how to connect two wires to one pin

why do I not have a low when I simply release it?

cause its floating, digital stuff has to be pulled high or low

2------/_---+5
    |
    /
    \
    /
   |
  gnd

thanks for the explanation.

But when the button is pressed, then it is high? even with the r connected to gnd?
Basically the Resistor prevents from getting a short since 5V --- button --- GND is evil, right?
How can pin 2 still get pulled high even if with gnd connected?

well the magic trick here is to use a large enough resistor going tween the pin and ground so it doesnt matter much (like paul mentioned 5 microamps)

the arduino is still providing a path tru it to ground so which ever one is the lower resistance wins

when the button is released the pin has no choice but to be pulled to ground

[edit]that should be 500 microamps
and again if the stupid tutorial was not teaching everyone the more parts way you could just use the internal pull up resistors and connect the button from pin 2 to ground[/edit]

Your edit did not work. More strange it produced an effect, where the led was constanly on as long as I dont move my hand near the whole arduino :slight_smile: then it went down.
Well, I dunno what happens there but I am not sure this is good :slight_smile:

The solution with the 10K R works well.

Thanks :slight_smile:

you have to turn on the pull up's in software

what you do is define a pin, then make it an input, then digitalWrite to it high, this will turn on the internal pullups

Sorry to revive an older thread but it hits my main question perfectly.

Can somebody please explain in a little more detail why a resistor on the pin side of the button leading to ground is necessary. I'm having a difficult time understanding it with the explanations already provided in this thread.

Also, in what applications is this necessary.. all inputs?

When the button is not pressed, it doesn't let current through.. as if you snipped the wire.
The wire that goes to the ground provides the pin with a ground, meaning it is actually connected (when the button isn't pressed) to something
The arduino can do funky tricks when a pin isn't connected, and you read from it.
Like the 'magic happens when I move my hand towards the arduino!' phenomena.

edit: the resistor has the job to make the pin get the current from the 5V when the button is pressed, as opposed to the ground getting all the current.

Got it, thank you.

One of the better tutorials on this
http://www.ladyada.net/learn/arduino/lesson5.html