Is there a conversion table/formula for this sensor?
I have another pi-based system which gives me LDR (the same LDR as airpi) and lux from a TSL2561 Luminosity Sensor which provides a LUX reading from both ambient visible and IR (LUX is visible light only so it subtracts the IR portion. While it gives a reasonable approximation to the LDR: graph curves are mostly the same shape, I am not sure if it is possible to give a calibration data set from this. It will also depend on any bias resistors in the LDR circuit which may change the readings in a different system. Have a look here xively.com/feeds/106057 at light-level and lux just below it.
I have not done any analysis of the potential to calibrate an LDR against it.
This is attached to my development system so it is not always working
I'm going to determine a benchmark light reading by taking the unit outside on a very clear day with the sun as close to it's zenith as I can determine. I'll take a number of readings over 10 minutes and use the average for my number. I'm also aware, based upon another post somewhere, that the readings are inversed, that is, higher when it's darker. There is a code fix I think.
I've derived a formula for the conversion of the measured resistance to lux. The (empirical) formula is derived from fitting AirPi-measured LDR data to that of the TSL2561 digital lux sensor. Basically, the formula is:
y = 5e9 * log10(x)^-12.78 (r-squared = 0.99),
where y is the light intensity in lux, and x is the measured resistance (from the LDR).
If necessary, I can show how to implement this in the AirPi script.
So, what I did was put the TSL2561 digital lux sensor and a LDR on the same breadboard, and took a bunch of measurements under different light conditions. Because both the sensors are so close to each other, I assumed that they both received the same amount of radiation.
Afterwards I plotted the coupled measurements and applied a least of squares fit (see image for an Excel-example). Be aware that x-axis actually shows the log-values of the resistance, rather than the actual resistance.
The R-squared value is an indication for the level of correlation between the two variables. An R-squared value of 1 means a perfect correlation, so that by knowing either x or y you can predict the other variable perfectly (within the range of measurements). So a correlation of 0.99 means that the lux and resistance measured are closely related to each other. The formula to calculate lux from resistance is:
lux = 5e9 * log10(resistance)^-12.78.
I've implemented this in the code by adding a "separate" sensor, like this:
Within the sensors section I've added a file (ldr.py), which is basically the analogue sensor with the added conversion:
import mcp3008 import sensor import math class Analogue(sensor.Sensor): requiredData = ["adcPin","measurement","sensorName"] optionalData = ["pullUpResistance","pullDownResistance"] def __init__(self, data): self.adc = mcp3008.MCP3008.sharedClass self.adcPin = int(data["adcPin"]) self.valName = data["measurement"] self.sensorName = data["sensorName"] self.pullUp, self.pullDown = None, None if "pullUpResistance" in data: self.pullUp = int(data["pullUpResistance"]) if "pullDownResistance" in data: self.pullDown = int(data["pullDownResistance"]) class ConfigError(Exception): pass if self.pullUp!=None and self.pullDown!=None: print "Please choose whether there is a pull up or pull down resistor for the " + self.val$ raise ConfigError self.valUnit = "Ohms" self.valSymbol = "Ohms" if self.pullUp==None and self.pullDown==None: self.valUnit = "millvolts" self.valSymbol = "mV"
def getVal(self): result = self.adc.readADC(self.adcPin) if result==0: #print "Check wiring for the " + self.sensorName + " measurement, no voltage detected on A$ return None if result == 1023: #print "Check wiring for the " + self.sensorName + " measurement, full voltage detected on$ return 0.0 vin = 3.3 vout = float(result)/1023 * vin
Hi, can you post your original data (11 points?) or your Excel spreadsheet? Quoting 1 part of your equation as 4 significant figures and another part to 1 is an issue for me plus I would like to try other variations to see if a straight line plot could somehow be obtained.
Error: could not import sensor module ldr.py Error: Did not import sensor plugin LDR Traceback (most recent call last): File "airpi.py", line 88, in <module> raise e File "/root/AirPi/sensors/ldr.py", line 5 requiredData = ["adcPin","measurement","sensorName"] ^ IndentationError: expected an indented block root@raspberrypi:~/AirPi#