What values does the flotilla light sensor return


#1

I wonder what is the maximum value this sensor can return ? I was surprised to get a 5 digit value when I shone a torch at it. I was wanting to use this light value in the brightness value in “motephat.set_pixel” parameters. I know the value should be between 0 and 1 and was expecting to have to divide the light reading down to achieve this, but I was surprised that it did not give an error with a value > 1 so I was wondering how it handled a value >1 ?


#2

The calculated lux value can range from 0 to 65535, but normal levels of ambient (outdoor) illumination should be in the range of 0 to 1000. However you may find lights brighter than 2000 indoors, and shining a bright light directly on the sensor will saturate it as you’ve found.

The best thing to do is to save a MIN_LUX and MAX_LUX to clamp the light level into a sensible range, and then divide by that range. Something like this:

MIN_LUX = 10
MAX_LUX = 1500

# Clamp the light reading between MIN and MAX
lux = max(min(light_sensor_reading, MAX_LUX), MIN_LUX)

# Subtract MIN_LUX so the range is 0 to MAX_LUX - MIN_LUX
lux -= MIN_LUX

# Divide it by MAX_LUX - MIN_LUX to get a 0.0 to 1.0 range indicating level
lux = Float(lux) / (MAX_LUX - MIN_LUX)

#3

Thanks again, that looks just the answer I need