The best tools to make your project dreams come true

Login or Signup

By All About Circuits

Design a Luxmeter with an LDR and an Arduino

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.

Hardware Required

Characterizing the LDR

Plug the LDR into your breadboard and ensure that the flat part of the sensor is parallel with the ground.

Plug the LDR into your breadboard

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.

Connect the DMM to the LDR’s leads

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.

Lux as a function of Resistance

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.

log(R) vs. log(lux)

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:

 best fit line 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.

Design a Luxmeter with an LDR and an Arduino

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)

Copy Code
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:

Copy Code
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:

Copy Code
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):

Copy Code
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.

Copy Code
 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.

Final Word

      • The LDR luxmeter isn’t incredibly accurate, but is good enough in some conditions.
      • During LDR characterization, it’s important to ensure that the light falling on the LDR and commercial sensor is identical.
      • This LDR luxmeter is cheap and easy to make. You’ll only need one commercial light sensor to help you make all the LDR light sensors that you want.

Key Parts and Components

Add all Digi-Key Parts to Cart
  • PDV-P8103-ND
  • 1050-1024-ND
  • 1528-1451-ND