How to read LDR output

I'm measuring and logging an LDR to figure out light levels during the day. The Arduino reads a low number under my rooms light and a higher number when a flashlight is put on the ldr. My question is what is the unit of the output?
Code available on request

cool, show sketch

ADC units. you can transform it in Voltage, Resistance, or Lux if you want.

I call it "arbitrary light units". In theory you can calibrate to some standard illumination units, but they are non linear and temperature sensitive so it is difficult.

They are typically useful where relative illumination is sufficient. For example light is on or off rather than the exact light level.

You'd have to calibrate it with a light meter and then you can use map() to show the units you want.

P.S.
Since an LDR is used as part of a voltage divider, the output isn't linear with resistance changes (even if the LDR itself is fairly linear). It might require a bit more "math". The map() function itself is linear.

The reading goes up because the conductance of the LDR is increasing.

Conductance is the inverse of resistance. Measured in Siemens.
However the reading isn't a direct measurement of conductance.

Bits. It converts an infinitely variable* (analog) electrical signal into bits of data of a given resolution. On an Uno, that resolution is 10 bits or 2^10 (1024) read on the Serial Monitor as 0-1023 because 0 means something in binary.

Really infinitely variable? Yes, the natural world is analog and you can always look a little closer to see more variation.

Don't believe me? Nature is groovy.

Not all LDRs will register the same value for same light source. You must pick your input range and output range.


// mosi = 11
//miso = 12
//clk = 13
//cs = 10
//rtc data pin 7
//rtc clk pin 6
// rst =8
//rtc 
#include <SD.h>
#include <SPI.h>
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC (6, 7, 8);
File myFile;
const int chipSelect = 10;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
      //sec, min, day of week, day of month, month, year
myRTC.setDS1302Time(00, 35, 23, 4, 1, 8, 2024);


while(!Serial) {
  ;
}
Serial.print("SD Ready");
if(!SD.begin(chipSelect)) {
  Serial.println("SD Card Failed");
  return;
}
Serial.println("SD Good");
}

void loop() {
  // put your main code here, to run repeatedly:
myFile = SD.open("lightS", FILE_WRITE);

  myRTC.updateTime();
 
  myFile.print("Current Date / Time: ");                                                                 //| 
  myFile.print(myRTC.dayofmonth);                                                                        //| 
  myFile.print("/");                                                                                     //| 
  myFile.print(myRTC.month);                                                                             //| 
  myFile.print("/");                                                                                     //| 
  myFile.print(myRTC.year);                                                                              //| 
  myFile.print("  ");                                                                                    //| 
  myFile.print(myRTC.hours);                                                                             //| 
  myFile.print(":");                                                                                     //| 
  myFile.print(myRTC.minutes);                                                                           //| 
  myFile.print(":");                                                                                     //| 
  myFile.println(myRTC.seconds);                                                                         //| 
                                 
    
myFile.write("    ");
int A0 = analogRead(A0);
myFile.print("LDR =");
myFile.print(A0);
myFile.write ("\n"); //new line
myFile.close();
Serial.println(A0);
delay(1000);
}

if you want to reverse this, just plug the LDR into the analog pin and GND, then use the built in Arduino pullup resistors like this:

const int LDRpin = A0;
void setup(){
  pinMode(LDRpin, INPUT_PULLUP);
}

but you may find the output range too limited with that built in resistor value of at least 20 kOhms:

The value of this pullup depends on the microcontroller used. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board.

source: https://docs.arduino.cc/learn/microcontrollers/digital-pins/

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.