Design a Luxmeter Using a Light Dependent Resistor (LDR) and an Arduino


The lux (symbol: lx) is the unit of illuminance, or luminous flux per unit area, in the International System of Units (SI). It is equal to one lumen per square meter. By using a lux meter, we can measure illuminance and luminous emittance. Different types of sensors can be used to create lux meters, including photodiodes and phototransistors, but the easiest to use is a light-dependent resistor. The amount of light that strikes LDR changes its resistance. If you can measure the LDR resistance and characteristics of your particular LDR, you can quantify the amount of lux falling on the LDR.


                                


Hardware Required

LDR

5K resistor

Arduino 

Lux meter


The resistance of the LDR is inversely proportional to the amount of light that strikes it. But unfortunately, it is not a linear relationship; it's an exponential one. We must find a mathematical equation for this relationship to get the lux value.

Create a graph of illuminance (lux) vs resistance of the LDR with the help of a digital multimeter. Measure the resistance of the LDR for varying light ranges and plot it on a graph. Use a commercial lux metre to find the illuminance of light while experimenting.


LUX - (y-axis) vs Resistance - (x-axis)



The equation of a straight line is y=mx+c

m - slope

y-intercept.


lux = M x R + b


lux = -1.4 x log10 (R) + 7.098 ,  (where, m = -1.4 and y = 7.098 )



Take the logarithm of both variables. Then plot it again, and you will get a graph like this.


Log(lux) (-y axis) vs log(resistance) (-x axis)




log10(lux) = M x log10(R)+b

Take 10 to the power of each side to get : 

10log10(lux) = 10M x log10(R)+b

 lux            = Rm x 10b  

Here we can see that we need to find LDR's m and b values to find the lux value.


Circuit


Code


#include <Wire.h>

#define LDR_PIN                   0
#define MAX_ADC_READING           1023
#define ADC_REF_VOLTAGE           5.0
#define REF_RESISTANCE            5030     // measure this for best results
#define LUX_CALC_SCALAR           12518931 // from experiment
#define LUX_CALC_EXPONENT         -1.405   // from experiment


void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Light Sensor Test")); Serial.println("");
}


void loop(void) {
  int   ldrRawData;
  float resistorVoltage, ldrVoltage;
  float ldrResistance;
  float ldrLux;

  ldrRawData = analogRead(LDR_PIN);
  resistorVoltage = (float)ldrRawData / MAX_ADC_READING * ADC_REF_VOLTAGE;

  // voltage across the LDR is the 5V supply minus the 5k resistor voltage
  ldrVoltage = ADC_REF_VOLTAGE - resistorVoltage;

  ldrResistance = ldrVoltage / resistorVoltage * REF_RESISTANCE;
  ldrLux = LUX_CALC_SCALAR * pow(ldrResistance, LUX_CALC_EXPONENT);

  Serial.print("LDR Raw Data   : "); Serial.println(ldrRawData);
  Serial.print("LDR Voltage    : "); Serial.print(ldrVoltage); Serial.println(" volts");
  Serial.print("LDR Resistance : "); Serial.print(ldrResistance); Serial.println(" Ohms");
  Serial.print("LDR Illuminance: "); Serial.print(ldrLux); Serial.println(" lux");

  delay(1000);
}




Comments

Popular Posts