Photocells act as light sensors. Inlike infrared sensors that are good for line followers or detecting the presense of an object, photocells are good when you just want to detect light. For example, you might want a sensor that detects when a flashlight is on, or when the sun is out. Photocells are used in automatic night lights and in street lamps that turn themselves on at night. Sometimes known as photoresistors, photocells are available from a number of sources. They look like a small (0.5 to 2 inch) disk with two leads out the back. Radio Shack sells a multi-pak of cells for about $2.50 under part number 276-1657. A picture of one of the cells in this pack is shown below.

In operation, a photocell acts like a light sensitive resistor with a high resistance when dark and a low resistance when in the light. Photocell properties vary widely from model to model so you may have to do a lot of experimenting. You can test sensitivity to light by measuring the photocell resistance as you subject it to light and dark.

When using with a Stamp, the photocell is wired up like a switch so that the Stamp reads the detector as 0 when dark and 1 in bright light. The schematic below shows the basic photocell circuit.

You may have to vary the value of the resistor to get the behavior you want. Run this program while covering and uncovering the surface of the photocell and see what happens.

check: debug dec in1 : pause 250 : goto check 

For more control over the light level that causes the stamp pin to switch, you can use the RCTIME command and set a switch threshold depending on what light levels you have. For this implementation, use the schematic show below.

Download this sample code for details