light sensers
The most commonly used light sensor in our robots is a light dependent resistor which,
as its name implies is a resistive sensor. The resistance of a typical LDR, such as the
ORP12, ranges from 1 MΩ or more in darkness to about 80 Ω in bright sunlight. Indoors,
with indirect daylight or artificial illumination, their resistance is a few kilohms.
LDRs respond to light of most colours, with a peak response in the yellow. Of all the light
sensors, the LDRs are the slowest and their response times are several tens or hundreds of
milliseconds. Although this is seems quite fast to humans, the PIC works much faster
than this. Programs may need a short delay to allow time for the LDR to catch up with it.
The potential divider (see drawing opposite) can have a fixed resistor, a variable resistor,
or both. The variable resistor allows for setting the output voltage for any given light
level. The total resistance should be in the same range as the average resistance of the
LDR under the expected operating conditions.
Another popular light sensor is the photodiode. The action of these depends on the fact
that the leakage current when the diode is reverse biased varies with light intensity. The
circuit is on p. 73. The leakage current is very small. In darkness it is only a few
nanoamps and rises to about 1 mA in bright light. The resistor has a resistance of a few
hundred thousand ohms, so the current generates a reasonable voltage across it. Often a
330 kΩ resistor provides suitable output voltage. The output must be connected to a high
impedance input so that the voltage is not pulled down. The PIC is a CMOS device so has
high-impedance inputs.
A photodiode is generally more responsive to light from the red end of the spectrum.
Some are specially sensitive to infrared. These are used with infrared LEDs for reading
optical encoders (p. 84). They are employed as sensors in line-following robots because
they are less subject to interference from external sources of visible light.
The response time of a photodiode is fast, generally a few hundred nanoseconds, so there
are no problems with this.
A phototransistor (overleaf) has properties similar to those of a photodiode, though their
response time is longer. They are connected in the same way as an npn transistor in a
common-emitter amplifier. Phototransistors often lack a base terminal and, if present, the
base is usually left unconnected.