Pages: [1]   Go Down
Author Topic: "Getting Started with Arduino"  (Read 614 times)
0 Members and 1 Guest are viewing this topic.
Chesterfield, MI
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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)
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Central Europe
Offline Offline
Edison Member
*
Karma: 6
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Chesterfield, MI
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 437
Posts: 23670
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: