Go Down

### Topic: "Getting Started with Arduino" (Read 1 time)previous topic - next topic

#### johnnymc

##### Jun 01, 2011, 03:38 am
"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)

#### johnwasser

#1
##### Jun 01, 2011, 04:18 am
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.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### Korman

#2
##### Jun 01, 2011, 09:38 am

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

#### PaulS

#3
##### Jun 01, 2011, 11:15 am
You could have also read ahead, where the book explains the purpose of the resistor, and ways to avoid needing it.

#### johnnymc

#4
##### Jun 01, 2011, 06:36 pm
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

#5
##### Jun 01, 2011, 06:53 pm
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.