The easiest way to measure light with an Arduino is with an LDR.

LDR’s (Light dependend resistors) have a low resistance in bright light and a high resistance in the darkness.

If you would us the LDR as the lower part of a voltage divider, then in darkness there would be a high voltage over the LDR, while in bright light, there would be a low voltage over that resistor.

Ofcourse if you would use it as the upper part of a voltage divider, it would be the reverse: low voltage in the darkness, high voltage in bright light

Doing that on an Arduino Analog port, would give a reading between 0 and 1024, which ofcourse are really non-descriptive numbers.

What you would want is an output in Lux or Lumen

That is possible but mind you that LDR’s are not really accurate for precise readings.

There is a somewhat rough formula that relates the resistance of an LDR to the light in Lux. That is:

`R`

_{ldr}=500/Lux, or

Lux=500/R_{ldr} (in kOhm)

as R_{ldr} is related to the voltage measured over it, reading the Voltage over it, can be used to calculate the Rldr and thus the Lux level

If the LDR is the lower part of a 5 Volt Voltage divider and a 10kOhm resistor the upper part, the Voltage will be:

`Vout=(5/(10+R`

(remember: multiplication before division)_{ldr}))*R_{ldr}

Vout=5*R_{ldr}/(10+R_{ldr})

as we do not measure a voltage, but a value between 0 and 1024, every step can be defined by 5/1024=0.0048828125.

`=> Vout=Analogreading*0.0048828125`

as Rldr=(10Vout)/(5-Vout) (remember Rldr is expressed in kOhm)

=> Lux=(500*(5-Vout))/(10*Vout)

=> Lux=(2500-500*Vout)/(10*Vout)

=> Lux=(2500/Vout-500)/10

=> Lux=(2500/((AnalogRead*0.0048828125)-500))/10

Anyway, in an arduino program that will look like:

//Lux

double Light (int RawADC0){

double Vout=RawADC0*0.0048828125;

//int lux=500/(10*((5-Vout)/Vout));//use this equation if the LDR is in the upper part of the divider

int lux=(2500/Vout-500)/10;

return lux;

}

void setup() {

Serial.begin(115200);

}

void loop() {

Serial.println(int(Light(analogRead(0))));

delay(1000);

}

Anyway, as said, an LDR is not the most accurate to measure light intensity. A photodiode would be better

Full work out of the Formula, for those interested (remember, this expresses R_{ldr} in kiloOhm and is for a 10kOhm reference resistor:

`V`

_{out}=(5R_{ldr})/(R_{ldr}+10)

5R_{ldr}=V_{out}(R_{ldr}+10) *// multiplied both sides with (R _{ldr}+10) and switch left and right*

5R

_{ldr}=V

_{out}*R

_{ldr}+10

_{out}

*// executed the right side multiplication*

5R

_{ldr}+(-V

_{out}*R

_{ldr})=(V

_{out}*R

_{ldr}+10V

_{out})+(-V

_{out}*R

_{ldr})

*//added equal value (-Vout*R*

_{ldr}) to both sides5R

_{ldr}+(-V

_{out}*R

_{ldr})=V

_{out}*R

_{ldr}+10V

_{out}-V

_{out}*R

_{ldr}

*// work out right side additions and subtractions*

5R

_{ldr}-V

_{out}*R

_{ldr}=V

_{out}*R

_{ldr}+10V

_{out}-V

_{out}*R

_{ldr}

*//work out left side additions and subtractions*

5R

_{ldr}-V

_{out}*R

_{ldr}=V

_{out}*R

_{ldr}-V

_{out}*R

_{ldr}+10V

_{out}

*// ditto*

5R

_{ldr}-V

_{out}*R

_{ldr}=10V

_{out}

*//ditto*

R

_{ldr}(5-V

_{out})=10V

_{out}

*//expressed left side as multiplication of R*

_{ldr}R

_{ldr}=10Vout/(5-V

_{out})

*// divided both sides by equal value (5-V*

_{out})For a reference resistor other than 10k the soluton is as follows

`R`_{ldr}=(R_{ref}*V_{out})/(5-V_{out})

Also.. remember that though we expressed the value of R

_{ldr}as a function of V

_{out}, ofcourse the value does not depend on V

_{out}, it is the other way around, but it is necessary to inject the function of V

_{out}into the Lux formula

whether a reference book on the formula

=> Lux=(500*(5-Vout))/(10*Vout)

and where it comes from 500

Found it somwhere on internet but as i am travelling right now it is a bit hard to search for the link

I tested the above code with this sensor (http://www.fezhydra.com/GHI-Light-Sensor-3-Pin-eblock/dp/B00614OY6K), an Arduino Uno, and an Android application as a reference to check the values (https://play.google.com/store/apps/details?id=com.bti.lightMeter&hl=en).

However I get different indications – especially when there is a lot of brightness.

Is there any tip on how to calibrate it correctly?

I am not sure. I used the formula as is. Will look into it

Sonicon, The formula is a rough approach. If you want precise readings you best make a look up table in which you have lux value for a specific reading by your Arduino, or for a specific resitance of the LDR.

For that table ofcourse you need a Luxmeter, but if you know a photographer with a Lightmeter…. these will indicate the amount in LUX