levkovigor / LTR390

Arduino library for the LTR390 UV sensors.
MIT License
8 stars 3 forks source link

LTR390 incorrect readings when too much light #5

Closed szerwi closed 2 years ago

szerwi commented 2 years ago

Hi,

Today I received my LTR390 sensor. I bought a Waveshare LTR390 from Aliexpress (https://www.waveshare.com/uv-sensor-c.htm) I have noticed that it can only read 5000lux at maximum. When that level is passed, it shows incorrect values like 400lux or 858987712lux. I am using example from this library. Does anyone experienced similar issue?

Example reading when shining a flashlight on a sensor. It should give ~10k lux reading:

UV Index: 0.01
Ambient Light Lux: 6221.00
UV Index: 0.01
Ambient Light Lux: 5885.20
UV Index: 0.01
Ambient Light Lux: 5989.40
UV Index: 0.01
Ambient Light Lux: 6245.00
UV Index: 0.01
Ambient Light Lux: 6510.60
UV Index: 0.01
Ambient Light Lux: 858988544.00
UV Index: 0.01
Ambient Light Lux: 858989120.00
UV Index: 0.02
Ambient Light Lux: 858989248.00
UV Index: 0.02
Ambient Light Lux: 858989376.00
UV Index: 0.02
Ambient Light Lux: 858989888.00
UV Index: 0.02
levkovigor commented 2 years ago

@szerwi Hi, Try to change GAIN and RESOLUTION. As soon as I can carry out these experiments, I can say what the problem

szerwi commented 2 years ago

Yesterday I have noticed that raw ALS value can reach only 65535, even though it should be 20 bit. I have also changed gain and resolution setting, but it didn't seem to help. Today or tomorrow I will test the sensor more and try to find an issue.

levkovigor commented 2 years ago

@szerwi

What mcu do you use?

I remember that I was tested library on Adafruit Sensor and it seems there were no such problems with high intensity lighting

raw ALS is uint32_t, but if you have 65535 as maximum value - it can be uint16_t. Maybe there is problem with I2C connection or with sensor.

szerwi commented 2 years ago

I use Arduino Nano. I will check the sensor with ESP32.

levkovigor commented 2 years ago

@szerwi Arduino Nano should be ok. I've tested it with atmega328, esp32 and stm32f4 series. I know that there are some problems with raspberry pico, but I don't have this mcu.

Will recheck this issue on the next week and inform you.

levkovigor commented 2 years ago

@szerwi Problem found and fixed. New Release 1.0.8 is available to download. Thanks for the issue.

szerwi commented 2 years ago

@levkovigor thank you for the fix!

By the way, is the formula to count UV index correct in your library? I have just found out that the datasheet shows different formula: image

The UV Sensitivity parameter is also different in the datasheet than in your library: image

levkovigor commented 2 years ago

@szerwi

Yes, it's correct according to the latest datasheet (v.1.4) (you can find it in library files)

изображение изображение

szerwi commented 2 years ago

@levkovigor I have one more question regarding LTR390. I am testing the sensor outside and I've noticed that when I put plastic dome over it, the UVI drastically decreases. Without the dome, the sensor shows around 1.0UVI and after I put the dome above it, it drops to 0 - 0.05UVI. I am using exactly the same dome with VEML6075 sensor and it works much better than the LTR390 - the UVI in VEML6075 doesn't drop by that much.

Do you have any tested way to cover the sensor and secure it from the rain? Which sensor do you think is the best to measure outdoors UVI? VEML6075 works pretty good, but it is announced as EOL and that is why I'm looking for alternatives.

levkovigor commented 2 years ago

@szerwi

изображение

You can change WFAC in LTR390.h

Most materials (except quartz glass) do not transmit UV radiation well. If the measurements do not differ much when covered with plastic, then the sensor does not measure UV radiation directly, but gives a value calculated from visible light, which is not always accurate.

Quartz glasses are sold, but keep in mind that quartz is very fragile.

szerwi commented 2 years ago

When there are clouds on the sky, the UVI measurement drops to 0 in most cases, so changing WFAC won't help in my case :/

However, I have noticed that LTR390 works completly different on smaller gains.

With gain set to 18 and resolution 20 I get following results: UVI without dome: 0.24 UVI with dome: 0.02 So the dome makes it 10x lower.

With gain set to 9 and resolution 20: UVI without dome: 0.4 UVI with dome: 0.2 So the dome makes it only 2x lower.

When gain is set to 6, I get similar results to gain 9. Reading is a bit higher than with gain 9, but the dome also makes it around 2-times lower.

All the test were made at the same time. Actual UVI (based on the readings from professional weather stations in my area) was around 0.2. It seems that without the dome the sensor measures correctly with gain set to 18, but to compensate for the dome I need to change the gain setting.

szerwi commented 2 years ago

@levkovigor Today I have done more tests on LTR390 during sunny conditions. Strangely, the UV reading suddenly stopped working on GAIN set to 18. It shows 0.00, even though the real UV index outside is around 2.0. On GAIN 9 and resolution 20, it also works strange. It fluctuates from 0.00 to 2.00. Gain 6 and resolution 16 seems to work the best. It shows around 4.5 (which is too high), but when I cover it with white dome, it drops to 1.7, which is correct reading.

Have you even encountered similar issue with this sensor?