It's not for protection, it's to form a voltage divider with the photocell.
For a typical photocell, the resistance may vary between say, 5 kΩ (light) and 50 kΩ (dark)
Note that the actual values may be quite different for your sensor (you'll need to check the datasheet for those)
If we leave the resistor out, the analog input will see 5 V either way (assuming an analog input of a high enough impedance not to affect things significantly)
This is because there is nothing to sink the current and drop voltage.
No Resistor
Let's assume the sensor is connected to an opamp with an input resistance of 1 MΩ(pretty low as opamps go, can be 100's of MΩ)
When there is no light shining on the photocell and it's resistance is at 50 kΩ we get:
$$ 5~\mathrm{V} \times \frac{1~\mathrm{M}\Omega}{1~\mathrm{M}\Omega + 50~\mathrm{k}\Omega} = 4.76~\mathrm{V} $$
When there is light shining on the photocell and it's resistance is at 5 kΩ, we get:
$$ 5~\mathrm{V} \times \frac{1~\mathrm{M}\Omega}{1~\mathrm{M}\Omega + 5~\mathrm{k}\Omega} = 4.98~\mathrm{V} $$
So you can see it's not much use like this - it only swings ~200 mV between light/dark. If the opamps input resistance was higher as it often will be, you could be talking a few µV.
With Resistor
Now if we add the other resistor to ground it changes things, say we use a 20 kΩ resistor. We are assuming any load resistance is high enough (and the source resistance low enough) not to make any significant difference so we don't include it in the calculations (if we did it would look like the bottom diagram in Russell's answer)
When there is no light shining on the photocell and it's resistance is at 50 kΩ, we get:
$$ 5~\mathrm{V} \times \frac{20~\mathrm{k}\Omega}{20~\mathrm{k}\Omega + 50~\mathrm{k}\Omega} = 1.429~\mathrm{V} $$
With there is light shining on the photocell and it's resistance is 5k we get:
$$ 5~\mathrm{V} \times \frac{20~\mathrm{k}\Omega}{20~\mathrm{k}\Omega + 5~\mathrm{k}\Omega} = 4.0~\mathrm{V} $$
So you can hopefully see why the resistor is needed in order to translate the change of resistance into a voltage.
With load resistance included
Just for thoroughness let's say you wanted to include the 1 MΩ load resistance in the calculations from the last example:
To make the formula easier to see, lets simplify things. The 20 kΩ resistor will now be in parallel with the load resistance, so we can combine these both into one effective resistance:
$$ \frac{20~\mathrm{k}\Omega \times 1000~\mathrm{k}\Omega}{20~\mathrm{k}\Omega + 1000~\mathrm{k}\Omega} \approx 19.6~\mathrm{k}\Omega $$
Now we simply replace the 20 kΩ in the previous example with this value.
Without light:
$$ 5~\mathrm{V} \times \frac{19.6~\mathrm{k}\Omega}{19.6~\mathrm{k}\Omega + 50~\mathrm{k}\Omega} = 1.408~\mathrm{V} $$
With light:
$$ 5~\mathrm{V} \times \frac{19.6~\mathrm{k}\Omega}{19.6~\mathrm{k}\Omega + 5~\mathrm{k}\Omega} = 3.98~\mathrm{V} $$
As expected, not much difference, but you can see how these things may need to be accounted for in certain situations (e.g. with a low load resistance - try running the calculation with a load of 10 kΩ to see a big difference)
All LEDs can be modelled as zener diodes with a colour/substrate specific forward voltage Vf and a series resistive Rs, where they combine both to give the Vf at rated current.
Rs tends to be small so you can neglect it for approximations of adding current limiting series resistors. (see below)
Therefore the current is non-linear and proportional to the voltage difference between the supply and the Vf drop at desired current.
Batteries with low voltage variation are ideal such as Lithium primary cells. Most White flashlights using 3V per LED use these without series resistors as the Li cell is also 3V. However they may be specify a sorted bin of LED's to achieve this.
My Rule of Thumb is to string arrays of LED's such that the voltage difference is ~1V for the current limiting Resistor for a fixed regulator. If the supply range has a wide range, e.g. 10 ~15V then a constant current sink circuit is best.
Additional Info
For more accuracy over a wider range of currents, you can determine the Rs value from the specsheets for a given temperature. The Vf forward voltage also is a function of temperature which affects the results slightly. THe Rs of LED's is much lower than the dynamic Rs of Zeners using silicon junctions.
- 20mA HB devices are <20 ohms.
- 300mA HB devices are < 2 ohms.
- 1Amp power modules are ~ 0.3 ohm.
- Rs for LED arrays , add in series, and divide in parallel.
- Old technology LEDs were much higher Rs values.
- Rs will reduce as the current increases but you can approximate it at the 10% of rated current value and extrapolate if the device stays at constant temp.
- Because of the Shockley effect with voltage variationmyou can actually calculate the junction temperature from the voltage drop of a calibrated LED.
Best Answer
All batteries have an internal resistance. You can imagine it as an ideal voltage source with a resistor in series with it. So the more current you try and draw, the more voltage is dropped across this resistance. In turn this means the voltage you see across your circuit will reduce. At some point you will reach an equilibrium.
Imagine the following:
simulate this circuit – Schematic created using CircuitLab
If you have a 9V battery as you say, then Vs=9V. In the schematic, Rs is the internal resistance of the battery, lets say it is 50Ohms (About realistic for a PP3 battery).
Now when you have no load attached (Rload = Infinity), then there will be no current flowing and so no voltage will be dropped across Rs (Ohms law). So Vload would be 9V. If you measure the battery with a multimeter, you would see 9V as the meter has a very high resistance.
Now lets say you attached your 9Ohm resistor, Rload. This would mean you now have Vs driving a circuit containing a 50Ohm resistor Rs and 9Ohm resistor Rload. Using ohms load, you can find that
I = V/R = 9/(50+9) ~= 150mA
. What gives? Surely there should be 1A flowing through your load as you calculated.Lets look a bit further. Using ohms law again, you can find that
Vload = I*Rload = 0.15*9 = 1.4V
. Ah, there we go. Essentially what has happened in the voltage at the terminal of your battery (Vload) has dropped significantly, so now you essentially have a 1.4V voltage source driving a 9Ohm resistor.If you lower the resistance, the current will go down and the load voltage will go up.
If you were to instead use a 9V power supply which had an internal resistance of say, 0.1 Ohms, you would indeed get almost 1A flowing through your resistor. Notice I said almost. Why? Same reason as the 9V battery example, the load voltage will drop slightly due to the internal resistance.