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?
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.
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)
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.
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 then it went down.
Well, I dunno what happens there but I am not sure this is good
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.