LTR390 UV Index conversion

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ajit_saurav
 
Posts: 5
Joined: Fri Sep 16, 2022 11:59 am

LTR390 UV Index conversion

Post by ajit_saurav »

Hi, I am using adafruit ltr390 uv sensor. i get reading, but how will i convert uv count output into uv index?

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: LTR390 UV Index conversion

Post by dastels »

You don't say what whether you are using CircuitPython or C++.

If CircuitPython, use the uvi property which returns the UV index.

If C++, you can use the calculation that is in the CircuitPython library to calculate uvindex from teh value returned by uvs:

Code: Select all

uvs
/ (
    (Gain.factor[self.gain] / 18)
    * (2 ** Resolution.factor[self.resolution])
    / (2**20)
    * 2300
)
* self._window_factor
Gain.factor references the 5th values in this table (which entry depends on the set gain):

Code: Select all

Gain.add_values(
    (
        ("GAIN_1X", 0, "1X", None, 1, None),
        ("GAIN_3X", 1, "3X", None, 3, None),
        ("GAIN_6X", 2, "6X", None, 6, None),
        ("GAIN_9X", 3, "9X", None, 9, None),
        ("GAIN_18X", 4, "18X", None, 18, None),
    )
)
Resolution.factor references the 5th values in this table (which entry depends on the set resolution):

Code: Select all

Resolution.add_values(
    (
        ("RESOLUTION_20BIT", 0, "20 bits", None, 20, 4.0),
        ("RESOLUTION_19BIT", 1, "19 bits", None, 19, 2.0),
        ("RESOLUTION_18BIT", 2, "18 bits", None, 18, 1.0),
        ("RESOLUTION_17BIT", 3, "17 bits", None, 17, 0.5),
        ("RESOLUTION_16BIT", 4, "16 bits", None, 16, 0.25),
        ("RESOLUTION_13BIT", 5, "13 bits", None, 13, 0.03125),
    )
)
and self._window_factor defaults to 1.

Dave

User avatar
ajit_saurav
 
Posts: 5
Joined: Fri Sep 16, 2022 11:59 am

Re: LTR390 UV Index conversion

Post by ajit_saurav »

sir i am using c++ in aurdino.

User avatar
ajit_saurav
 
Posts: 5
Joined: Fri Sep 16, 2022 11:59 am

Re: LTR390 UV Index conversion

Post by ajit_saurav »

can you post the whole code.

User avatar
ajit_saurav
 
Posts: 5
Joined: Fri Sep 16, 2022 11:59 am

Re: LTR390 UV Index conversion

Post by ajit_saurav »

#include "Adafruit_LTR390.h"

Adafruit_LTR390 ltr = Adafruit_LTR390();

void setup() {
Serial.begin(115200);
Serial.println("Adafruit LTR-390 test");

if ( ! ltr.begin() ) {
Serial.println("Couldn't find LTR sensor!");
while (1) delay(10);
}
Serial.println("Found LTR sensor!");

ltr.setMode(LTR390_MODE_UVS);
if (ltr.getMode() == LTR390_MODE_ALS) {
Serial.println("In ALS mode");
} else {
Serial.println("In UVS mode");
}

ltr.setGain(LTR390_GAIN_3);
Serial.print("Gain : ");
switch (ltr.getGain()) {
case LTR390_GAIN_1: Serial.println(1); break;
case LTR390_GAIN_3: Serial.println(3); break;
case LTR390_GAIN_6: Serial.println(6); break;
case LTR390_GAIN_9: Serial.println(9); break;
case LTR390_GAIN_18: Serial.println(18); break;
}

ltr.setResolution(LTR390_RESOLUTION_16BIT);
Serial.print("Resolution : ");
switch (ltr.getResolution()) {
case LTR390_RESOLUTION_13BIT: Serial.println(13); break;
case LTR390_RESOLUTION_16BIT: Serial.println(16); break;
case LTR390_RESOLUTION_17BIT: Serial.println(17); break;
case LTR390_RESOLUTION_18BIT: Serial.println(18); break;
case LTR390_RESOLUTION_19BIT: Serial.println(19); break;
case LTR390_RESOLUTION_20BIT: Serial.println(20); break;
}

ltr.setThresholds(100, 1000);
ltr.configInterrupt(true, LTR390_MODE_UVS);
}

void loop() {
if (ltr.newDataAvailable()) {
Serial.print("UV data: ");
Serial.print(ltr.readUVS());
}

delay(100);
}

User avatar
ajit_saurav
 
Posts: 5
Joined: Fri Sep 16, 2022 11:59 am

Re: LTR390 UV Index conversion

Post by ajit_saurav »

i am using this code, wher should i add to get uv index?

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”