Relative newbie to electronics. What's the purpose of the resistor with circuit

I am working thru the Getting Stated With Arduino 2nd Edition book. I have a rudimentary knowledge of electronics. I know what resistors, capacitors, ICs, inductors, etc are and what they do in a very basic way. I know that there is a voltage drop across a resistor as well as a corresponding amount of current used.
That being said what is the purpose of the resistor in this circuit:

getting started with arduino example03.jpg

To act as a pull up resistor. See:- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

However there is an error in that diagram - There MUST be a resistor in series with the LED otherwise you will damage the Arduino.

Thank you for the information regarding the pull up/down resistors, but now I have a new question. Why do you need a resistor inline with the LED?

To stop the LED drawing too much current from the arduino and damaging it. http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

You can also make the LED very unhappy that way... and really too bright.

or in some newbie language, the Arduino is working with 5V, while most common LEDs work with 2-3V - give it too much 'juice' and "kapow!"

retronet_RIMBA1ZO: or in some newbie language, the Arduino is working with 5V, while most common LEDs work with 2-3V - give it too much 'juice' and "kapow!"

Now, LED's are not voltage-driven components, so it's not correct to say, that they work with 2-3 volts.

LED's are always current-driven - the voltage drop across the LED depends on the chemistry inside it. It is usally around 2 volts for standard Red, green and yellow, and for blue & white, it's around 3.6 volts.

The current all depends on the kind of LED - standard junkbox LED's (indicator lights) can handle around 20 mA.

So if driving a standard red indicator LED from an Arduino-output, you would calculate the resistor like this:

5V (Arduino voltage) - 2V (LED Voltage drop) = 3 volts we need to "burn off" in a resistor. 3 / 0.02 (2 mAmps) = 150 ohms. If your calculation ends up with a value of resistor not in your parts bin, you take the next higher value. e.g. if your calculation says that you need a 130 ohm, you use a 150 ohm.

// Per.

Zapro:

retronet_RIMBA1ZO: or in some newbie language, the Arduino is working with 5V, while most common LEDs work with 2-3V - give it too much 'juice' and "kapow!"

Now, LED's are not voltage-driven components, so it's not correct to say, that they [u]work with[/u] 2-3 volts.

... ... // Per.

i thought it was a generic enough verb to explain it simply without going into too much detail that may confuse, depending on the level of EE knowledge of the OP.

didn't want to unnecessariy go into the detail that would spark debates of "follows Ohmic law", etc - that one dizzied me when i first asked about trying to calculate the resistance OF an LED !

i also left it short as some senior would then give a more comprehensive answer better than i would be able to.

I have a related question, if someone who knows wouldn't mind answering it for me.

In the circuit diagrammed here: http://arduino.cc/en/Tutorial/Loop#.UxQNR_ldXEZ, why are we using multiple resistors, each hooked up to the anode of one of the LEDs? (At least I think those are the anodes... current is flowing into them -- right?)

Why not hook up a resistor in series between the common ground and the ground input on the Arduino, then hook up all of the anodes directly to the output pins on the Arduino?

Because if you did use one resistor the more LEDs that were on the dimmer they would be. This is because the voltage across a resistor is bigger the bigger the current through it, this is called ohms law. And lots of LEDs would give lots of current which would produce lots of voltage so there would not be so much to light the LEDs,

There are also problems with current sharing, even if you reduce the resistance to give the same total current:

  1. Different colors of LEDs drop different voltages when in forward conduction, which would cause some LEDs to burn out as they’d hog the current, then the next higher voltage LEDs would carry too much current, burning them up, until possibly all your LEDs are burned out.
  2. Even variations among one color can cause current hogging.
  3. Voltage across an LED drops with temperature, so once an LED starts drawing more current, the forward bias voltage drops, causing more current hogging.