A cadmium sulfide (CdS) photocell is a passive component whose resistance decreases when light shines on it. CdS photocells can be used to detect when lights turn on, to orient things toward a light source (electronic sunflower), and to detect shadows passing across them.
To use a CdS photocell, you put it in series with a resistor and put a voltage across them. This forms a voltage divider: the voltage at their junction is determined by the proportion of the two resistances. If you want brightness to increase the measured voltage, put the photocell on top; if you want darkness to increase the measured voltage, put the photocell on the bottom.
All that remains is to determine an appropriate value for the complementary resistor. Assuming you want output voltage to increase when brightness increases, the goal would be to make the output read as close to 0V as possible when it’s as dark as you expect it to be, and as close to your maximum voltage as possible when it’s as bright as you expect it to be.
To begin this calculation, I measured the resistance of the photocell (out of circuit) in light and dark conditions. With the photocell shown above, I found the following values:
|450KΩ||in the dark (my finger pressed over it)|
|36KΩ||in average light|
|7.6KΩ||in bright light (under my fluorescent desk lamp)|
I discovered later that the photocell’s carrier PCB isn’t entirely opaque and a noticeable amount of light does leak in around the edges even when the face is covered. The resistance in true darkness would probably be even higher.
I decided to scale the photocell’s circuit to the range from darkness to normal room lighting, so calculating for a resistance range of 450KΩ to 36KΩ. Because this is only a single order of magnitude variation of resistance, I could already tell the voltage swing of the output wasn’t going to be as large as I’d like. I picked a 100KΩ resistor and estimated the voltage range:
5V * (100KΩ / (100KΩ + 450KΩ)) ≅ .91V
5V * (100KΩ / (100KΩ + 36KΩ)) ≅ 3.7V
So it has a swing of about 3V out of a 5V range. Not ideal, but it still provides a fair amount of resolution.
Finally, I connected the photocell to my LogoChip’s A0 input and confirmed its behavior by running
print read-ad 0. I got a wide range of values out of the A/D converter, making this circuit quite usable for microcontroller interfacing.
I also posted a cookbook version of using the photocell on the TASD class wiki.