Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Problem with UV sensor

Problem with UV sensor

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 4 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    After some research i've found out that my UVM-30A is outputting 0-1V (as stated in the datasheet). The analog input on my nano pro however, expect 0-5V to calculate the 0-1170 analog value that is used for the UV calculation in the sketch (see: http://www.mysensors.org/build/uv)

    Right now i'm multiplying the input times 5 to correct the issue. But I was wondering whether it is the sketch or my nano pro who is wrong here..

    1 Reply Last reply
    0
    • skywatchS Offline
      skywatchS Offline
      skywatch
      wrote on last edited by
      #2

      I was scratching my head over this problem last year, but found a solution that works for me.....Try this.....

      sensorVal = analogRead(sensorPin); //The pin the UV sensor is connected to
      sensorVal = constrain(sensorVal, 0, 1180);
      sensorValue = map (sensorVal, 0, 246, 0, 1180); //sensorValue is the number you
      //are looking for

      Then I did a look up for the UV index as follows......

      if (sensValue >= 0 && sensValue <= 226)
      uvVal = 0;
      else if (sensValue >= 227 && sensValue <= 317)
      uvVal = 1;
      else if (sensValue >= 318 && sensValue <= 407)
      uvVal = 2;
      else if (sensValue >= 408 && sensValue <= 502)
      uvVal = 3;
      else if (sensValue >= 503 && sensValue <= 605)
      uvVal = 4;
      else if (sensValue >= 606 && sensValue <= 695)
      uvVal = 5;
      else if (sensValue >= 696 && sensValue <= 794)
      uvVal = 6;
      else if (sensValue >= 795 && sensValue <= 880)
      uvVal = 7;
      else if (sensorValue >= 881 && sensorValue <= 975)
      uvVal = 8;
      else if (sensValue >= 976 && sensValue <= 1078)
      uvVal = 9;
      else if (sensValue >=1079 && sensValue <=1169)
      uvVal = 10;
      else if (sensValue >= 1170)
      uvVal = 11;

      And now I get the values I expect!
      Look at the map function on the arduino page to see how it works!

      Skywatch

      1 Reply Last reply
      0
      • BulldogLowellB Offline
        BulldogLowellB Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by
        #3

        @skywatch said:

        if (sensValue >= 0 && sensValue <= 226)
        uvVal = 0;
        else if (sensValue >= 227 && sensValue <= 317)
        uvVal = 1;
        else if (sensValue >= 318 && sensValue <= 407)
        uvVal = 2;
        else if (sensValue >= 408 && sensValue <= 502)
        uvVal = 3;
        else if (sensValue >= 503 && sensValue <= 605)
        uvVal = 4;
        else if (sensValue >= 606 && sensValue <= 695)
        uvVal = 5;
        else if (sensValue >= 696 && sensValue <= 794)
        uvVal = 6;
        else if (sensValue >= 795 && sensValue <= 880)
        uvVal = 7;
        else if (sensorValue >= 881 && sensorValue <= 975)
        uvVal = 8;
        else if (sensValue >= 976 && sensValue <= 1078)
        uvVal = 9;
        else if (sensValue >=1079 && sensValue <=1169)
        uvVal = 10;
        else if (sensValue >= 1170)
        uvVal = 11;

        trivial, but this can be simplified like this:

        if (sensValue <= 226)
        uvVal = 0;
        else if (sensValue <= 317)
        uvVal = 1;
        else if (sensValue <= 407)
        uvVal = 2;
        else if (sensValue <= 502)
        uvVal = 3;
        else if (sensValue <= 605)
        uvVal = 4;
        else if (sensValue <= 695)
        uvVal = 5;
        else if (sensValue <= 794)
        uvVal = 6;
        else if (sensValue <= 880)
        uvVal = 7;
        else if (sensorValue <= 975)
        uvVal = 8;
        else if (sensValue <= 1078)
        uvVal = 9;
        else if (sensValue <=1169)
        uvVal = 10;
        else
        uvVal = 11;
        
        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          Or even simpler... ;)

          int levels[11] = {226, 317, 407, ....};
          int uVal = 0;
          for (;uVal<=11;uVal++) { 
             if (uVal==11 || sensValue <= levels[uVal])
                break;
          }
          

          (untested)

          1 Reply Last reply
          0
          • skywatchS Offline
            skywatchS Offline
            skywatch
            wrote on last edited by
            #5

            @Bulldog....

            Yeah I know! - it was 19 months ago I did that and I was trying out new ideas. This was obviously the last one as it is the last version (currently) ;)

            @Hek

            som är för smart för mig ;)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            12

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular