Courtesy of All About Circuits
A simple way to describe a lux meter is to say that it measures the brightness of the light falling on the sensor. Commercially available lux meters can vary in price from around $15 up to hundreds of dollars, but it’s cheaper and way more fun to build one yourself. For this project, we’ll characterize an LDR, write software to calculate illuminance, and build an Arduino and LDR based luxmeter.
Characterizing the LDR
Plug the LDR into your breadboard and ensure that the flat part of the sensor is parallel with the ground.
Connect the DMM to the LDR’s leads and set it to the DMM to measure resistance. Place your commercial LDR’s sensor beside the LDR.
Ensure that the same levels of light fall on the two sensors, then record a reading of the light meter lux and the LDR resistance. Repeat this process for several different lighting levels from very dark (close to 0 lux) to very bright (thousands of lux). It’s important that you do your best to ensure that both sensors get the same amount of light at all of these different light levels.
Next, you’ll need to transfer your readings to a spreadsheet (or you can just enter them directly while you are making measurements) and make a plot of the illuminance (lux) as a function of resistance. You can download the spreadsheet which will create the plot and perform all of the necessary analysis from your entries.
You can download the Lux spreadsheet on All About Circuits.
The graph above indicates that resistance will decrease exponentially as the brightness of the light increases. Ultimately, we’re looking for an equation for this graph into which we can plug the resistance to obtain the lux. The equation can be obtained directly from the graph, but it can be a little tricky. It is much easier to obtain the equation from a straight line where the form of the equation is
(m is the slope of the line and b is the line’s y-intercept). If you take the logarithm of both variables (illuminance and resistance) and re-plot, you’ll end up with a straight line (more or less). The base of the logarithm could be anything in theory, but I’ll use a base-10 log. Here is the plot of log of the lux as a function of the log of the resistance.
The plot above is pretty close to a straight line. Using Excel (although you can also do this by inspection), I obtained a best fit line with a slope of -1.405 and a y-intercept of 7.098 which gives us the equation:
Building the Lux Meter
Building the lux meter is simple. You only need an Arduino, an LCD shield, an LDR, and a 5 kohm resistor. In theory, you can use any resistance value, but I chose 5 kohm because the LDR’s resistance was in the order of a few kilo-ohms under typical room lighting conditions.
Plug the shield into the Arduino, and build a simple voltage divider circuit with the LDR and resistor. The voltage divider circuit is the crux of our sensor circuit. The 5 volt supply is split between the LDR and the 5 kohm resistor. As the LDR’s resistance changes, the fraction of the voltage across the two resistors changes as well. If the voltage across the 5 kohm resistor is measured by the Arduino, it’s easy to add some code to determine the resistance that the LDR is exhibiting. The LDR connects to 5V, the resistor connects to ground, and the point in between connects to analog input 0.
The voltage divider circuit doesn’t need a breadboard and can be connected directly to the LCD shield. The picture below shows the completed circuit with the LDR and 5 kohm resistor in the LCD shield.
The Light Meter Code
The equation shown above relates the illuminance to the resistance, but the Arduino’s analog input pin of only measures voltage. There are a couple of calculations that have to be done in order to obtain the resistance.
First, we need to obtain the digital representation of the analog voltage by using the analogRead function (this is the voltage across the 5 kohm resistor, not the voltage across the LDR)
rawData = analogRead(LDR_PIN);
Next, the digital representation needs to be converted back into a voltage by scaling the analog-to-digital converter value to the reference voltage:
// MAX_ADC_READING is 1023 and ADC_REF_VOLTAGE is 5
resistorVoltage = (float)ldrRawData / MAX_ADC_READING * ADC_REF_VOLTAGE;
Then, we need to determine the LDR voltage. Since 5V is split between the 5 kohm resistor and the LDR, you’ll need to subtract the resistor voltage from 5V:
ldrVoltage = ADC_REF_VOLTAGE - resistorVoltage;
Finally, we need to calculate the LDR’s resistance based on the voltage (simple resistance calculation for a voltage divider circuit):
ldrResistance = ldrVoltage/resistorVoltage * REF_RESISTANCE; // REF_RESISTANCE is 5 kohm
Once we obtain the resistance, the illuminance (in lux) can be calculated and the value can be output to the LCD.
ldrLux = LUX_CALC_SCALAR * pow(ldrResistance, LUX_CALC_EXPONENT);
// LUX_CALC_SCALAR and LUX_CALC_EXPONENT are determined by the Excel
// They are set to 12518931 and -1.405 respectively in my example
The calculations and display output are all done in the loop function. An LCD shield from Adafruit is used to display the lux measurement, so you’ll need to download the LCD library must be downloaded for this sketch to work
You can download the Lux Meter code on All About Circuits.
Putting it All Together
With the hardware has been assembled, the code written, all we need to do is upload the code and compare the results with the commercial light meter. You can see a side by side comparison of the LX-102 light meter from Lutron and our LDR light meter in the video below.
Overall, I’d say that the LDR light meter is good enough for a normal room when you just want a ballpark measurement of the lighting levels. If you want very precise and accurate measurements you’ll want a different kind of sensor.