phatduinoa personal home automation technology arduino





Photocell

Light sensor

Purpose: Detect sunset and sunrise to set the Phatduino to "night mode"

Characteristics: The light sensor is actually nothing more than a photocell: A resistor that changes its resistance depending on the light that it is exposed to. Therefore a simple measuring circuit can be used as shown.

Naturally the photocell shows an infinitesimal resistance when it is exposed to full light. But as there is also a resistance in the wires (in my case about 5 mts. long) the total resistance of the photocell branch of the circuit can never be zero. But keeping in mind that I am only interested in light level at dawn and sunset and not measuring in absolute but relative values those external influences do not have to be taken into consideration.

Thumbnail of a photoWith the circuit I measure the voltage, which Arduino divides into 1024 equal levels. Thus it does not even have to take the actual voltage, but a value between 0 and 1023 as indicator for sunset and sunrise.This is how the photocell should be connected. For the automation there is no importance in converting this value into voltage or into a unit for brightness.

However I simply converted the value into a percentage, what should not be done as it suggests that the light/voltage-curve of the photocell is a linear function what is not the case. Maybe I will imply a proper conversion function in the code in the future, but for now the measurement is reliable enough to diffentiate between day and night.
There is an excellent tutorial on using photocells with Arduino at ladyada.net, I almost used her code 1:1! (But to be honest... reading a photocell is no big deal if you got the hardware set up.) See it for yourself:

The Code

// Get light
 
   light = analogRead(photocellPin);
   lightlevel = int((float(light)*100)/1024);