"Getting Started with Arduino"

"Using a Pushbutton to Control the LED"

In chapter four, they want you to use a pushbutton to control the LED. They tell you to build the circuit in figure 4-6. It shows using a 10k Ohm resistor on the negative side of the pushbutton. Either I am missing something, or forgetting something (most likely), but why do we need that resistor? Is it to protect the pushbutton, or to protect the input pin on the board?

Thank you,
John
New to this (obviously)

Typically the resistor is a 'pull-down' resistor, between the input pin and ground. The button connects the input pin to +5v so it reads HIGH when the button is pressed.

Johnnymc:
In chapter four, they want you to use a pushbutton to control the LED. They tell you to build the circuit in figure 4-6. It shows using a 10k Ohm resistor on the negative side of the pushbutton. Either I am missing something, or forgetting something (most likely), but why do we need that resistor? Is it to protect the pushbutton, or to protect the input pin on the board?

John,

the concepts demonstrated here are about the most important thing to learn about electronics when working with the Arduino:

  1. An unconnected pin (also called floating input) is undefined and will give you random values when read. That's why the pin is connected either to +5V or Ground. Then you'll get HIGH or LOW properly.

  2. A short circuit between +5V and Ground is bad. It will fry your power suply or regulator or other things you care about on your Arduino. Always make sure there's a component between +5 and Ground and there's no direct connection of those two. And that component in-between should limit the current to reasonable levels. The easiest way is to add a resistor.

And by the way, push-buttons and resistors don't have a positive or negative side, you can mount the either way. Diodes and LED have and need to mounted the right way or they won't do what you expect.

Korman

You could have also read ahead, where the book explains the purpose of the resistor, and ways to avoid needing it.

Korman and johnwasser,

Thanks for the info; very good stuff!

PaulS,

I did in fact read ahead but did not find the explanation. Maybe because I have the "e-version", it was overlooked? Anyway, I did not see it as I read well into chapter five. Thanks anyway!

John

Here's the down & dirty for you then: The ATMega has internal Pull UP resistors.
You "connect" them thusly:
pinMode(pinX, INPUT);
digitalWrite(pinX, HIGH);

Now you can connect a switch (typically a Normally Open push button kind of switch) between pinX and Ground and don't have to worry about shorting out +5V to anything.

When you read the pin:
pinX_state = digitalRead(pinX); // pinX_state will equal 1 when the switch is open, and 0 when it is closed.

There are no internal Pull Down resistors.