A photocell or photo resistor is a Light Dependent Resistors (LDR). LDR’s are sensors that detect light. They are small, inexpensive, low-power, easy to use and don’t wear out.
An LDR is a resistor that changes its resistive value (in ohms Ω) depending on how much light is shining onto it. They are very low cost, easy to get in many sizes and specifications, but are very innacurate. Each LDR sensor will act a little differently than the other, even if they are from the same batch. The variations can be really large, 50% or higher! For this reason, they shouldn’t be used to try to determine precise light levels. Instead, you can expect to only be able to determine basic light changes. When light falls on the sensor the resistance will drop. When it is dark the resistance can be as much as 10Mohm, when the light increases the resistance can drop to 1Kohm. You can test the photocell with a multimeter. Below you see a graph how the resistance of the LDR changes when the light changes.It is a logaritmic scale.
The photocell is the most sensitive between the green light (400nm) and the red light (700nm). You can test how your photocell works by connecting a multimeter in resistance-measurement mode to the two leads and see how the resistance changes when you shine a light on it and then shading the sensor with your hand. Because the resistance changes a lot, put the meter in auto-ranging mode. Otherwise, just make sure you try different ranges, between 1MΩ and 1KΩ.
In this example the sensor is connected to the power (5V) and to a pull down resistor to ground. Then the point between the pulldown resistor and the LDR is connected to the analog input of a microcontroller.
The analog voltage reading is used to determine if the LED is on or off. The darker it is, the LED will be on, if it is light the led will be off. The LED has to be connected to a ouput pin, port PB0 of the ATmega328.In the example the ATMega328 board is used. The circuit can be build on a breadboard.
For more detail: Photocell or LDR