This tutorial covers measuring light levels by interfacing a Light Dependent Resistor (LDR) to a Hobbyduino Mini. The example sketch will vary the blink rate of an LED based on the intensity of light that strikes the LDR.

Suggested Applications

Automatic light dimmer

Automatic blinds or curtains

Automatic night-light

Camera light meter

Light sensitive switch

Parts List

Arduino or Arduino clone (a Hobbyduino Mini V3 is used for this tutorial)

Upload the sketch to the Arduino and open the serial monitor (be sure the baud rate in the serial monitor matches that of the sketch). The below light levels are what I measured but, your readings may vary based on the level of light and the LDR you chose to use.

Ambient Light:

Bright Light:

No Light:

Discussion

The resistance of the LDR decreases when the amount of light it detects increases. The level of light across the LDR changes the voltage level measured by analog pin 0. You’ll notice in the above screen shots that the voltage is near 5V when maximum light is shined on the LDR and near 0V when minimum light is shined on the LDR. The blink rate of the LED is scaled to a value between 100 and 1000 usec by way of the Arduino map() function.

The ATMega328 used on the Hobbyduino Mini contains a 6 channel, 10-bit analog to digital converter (A/D). The A/D maps input voltages between 0 and 5 VDC into an integer value between 0 and 1023. This conversion is achieved by the Arduino analogRead() function.