Ultraviolet measuring sensor

First, sensor introduction

  • Provides reliable and accurate measurement of uv index (UVI)
  • Suitable for measuring the total ultraviolet intensity of sunlight;
  • The world Health Organization uv index classification standard was compared
  • Detection UV wavelength: 200-370nm;
  • Fast response, less than 0.5 seconds;

Two, wiring diagram

Iii. Uv index conversion table

4. Complete code

-- Define function: convert sensor output voltage (mv) into uv indexindex
function GetUvIndex(v)
    ifV < 50.0 then index= 0
    elseif v < 227.0 then
        index = 1;
    elseif v < 318.0 then
        index = 2;
    elseif v < 408.0 then
        index = 3;
    elseif v < 503.0 then
        index = 4;
    elseif v < 606.0 then
        index = 5;
    elseif v < 696.0 then
        index = 6;
    elseif v < 795.0 then
        index = 7;
    elseif v < 881.0 then
        index = 8;
    elseif v < 976.0 then
        index = 9;
    elseif v < 1079.0 then
        index = 10;
    else
        index = 11
    end
    returnIndex end -- Configure the USB port of Core to work in virtual serial mode, so that the output of print() displays LIB_UsbConfig("CDC") -- Configure the AD voltage collection function and set the maximum sampling value4096The corresponding3.6V Input voltage -- when the channel is full1When, the cache is full, and the collection interval of each point is300ms
LIB_ADConfig(1.300000) -- Start the big cyclewhile(GC(1) = =true)
do- every300- you can connect the sensor to any channel from A1 to A3, or you can connect multiple channels to multiple sensors, using the same method as below300)
    A0_full_flag, A0_buf = LIB_ADCheckBufFull("A0")
    if A0_full_flag == 1 then
        vol_mv =  A0_buf[1] *3600/4096.0Uv_index = GetUvIndex(vol_mv) uv_index = GetUvIndex(vol_mv) uv_index = GetUvIndex(vol_mv)string.format("A0=%04d vol=%.0fmv index=%02d",A0_buf[1],vol_mv,uv_index))
    end
end
Copy the code

Five, code operation test results (weather: sunny in early summer, 10:00 am sunshine)

Step 1: Place the sensor in an indoor environment without sunlight At this time, the sensor output voltage is close to 0mV, and the UV index level is also 0Step 2: Place the sensor in an indoor environment with sunlight but through Windows At this point, the sensor output voltage is 150Around 160mV, uv index level 1Step three: Put the sensor into the indoor environment with direct sunlight At this point the sensor output voltage is 470Around 480mv, uv index level 4Step four: Put the sensor in the outdoor sunlight directly At this time, the output voltage of the sensor is about 660~ 670mV, and the UV index level is also 6Conclusion:It can be seen from the above experiment that the output voltage values of the sensor in the four states of “no sunlight “- >” indoor separated by glass “- >” indoor separated by glass “- >” outdoor direct sunlight” are 0mv, 160mv, 480mv, 670mv respectively, corresponding to the uv index grade 0,1,4,6.

It can be seen that the higher the uv intensity, the higher the sensor output voltage value, the higher the corresponding UV index level.