πŸ’¬ UV Sensor


  • Admin

    This thread contains comments for the article "UV Sensor" posted on MySensors.org.



  • What type of value should we get? I thought this will be index value from 1 to 5.
    My sensor is giving decimal value from 0 to .3.

    Thanks for help.

    Patrice


  • Hardware Contributor

    @supermenteur - im getting values from 0-11.
    but now its headed to wintertime in my country and the latest week I have not been above 2.0



  • I'm based in France. Could you share you sketch to check why I'm getting decimal value and not index?
    Thanks in advance.


  • Hardware Contributor



  • What is the average distance that sensor works?
    Thanks
    Mehdi


  • Hardware Contributor

    @mreissy - this is a UV sensor, the distance?
    Do you mean the radio? Please check the datasheet for the radio you intend to use.


  • Mod

    The distance to the sun is approximately 150 million km πŸ™‚



  • Can you place the sensor in some sort of enclosure if it is to be mounted outside, or will any material that is placed between the sensor and the uv-light block the uv-rays? Tinking about see-through plastic and similar.


  • Hardware Contributor

    @Cliff-Karlsson - Yes! Plastic is fine. See my link above.



  • Hi. I'm getting values off 0.2 up to 0.6 on my UV sensor using the UVM-30A sensor. Is this normal?
    The first attemp i used a arduino pro mini on my second attemp i'm using a nano pro but i'm getting this values during the day and the other strange problem is that if the value is 0.00 for example the sensor stops sending info to the gateway.


  • Hardware Contributor

    @mrc-core - that quite depends on your location... I live in Sweden and its winter here... during last month (when the sun is seen and not clouds) i get these values as well. See picture:
    0_1488784025606_1.JPG



  • @sundberg84 I live in Portugal and today for example i have a day whit no clouds temps around the 28ΒΊ and my UV sensor is giving me 0.00 values... and off course the last data my sensor had send to my gateway was at 08:35 since that time until now i have nothing and it was me how did a reset to the sensor at that time. I really don't understant this sensor.

    I now that the arduino is working OK since i have change from a pro mini to a nano and this 2 arduinos work fine.
    One other thing i have noticed was that whitout the sensor connected i had a 3.6 value and counting... whit the sensor i have 0.00 value and no data send to the gateway.

    Using a weather station from wuntherground near my house i can see that the uv sensor off this weather station is registering 4.1 UV rigth now.


  • Hardware Contributor

    @mrc-core Then its your sensor or reading from the sensor which is wrong.
    Sending the value to the gw has nothing to do with what you read from the sensor. Depending on your code you can have a code saying not to send if the value isnt changed - and if its 0 all the time it does not send.
    Maybe you could post your code?



  • @sundberg84 Thanks for the quick repaly.
    I'm using the same code that's on the build section for the UV sensor. Have not made any changes to the code. But i can se the code when i arrived home at night and post here.

    Once again thanks.


  • Hardware Contributor

    @mrc-core - ok, if you look at this part:

    //Send value to gateway if changed, or at least every 5 minutes
        if ((uvIndex != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) {
            lastSend=currentTime;
            send(uvMsg.set(uvIndex,2));
            lastUV = uvIndex;
        }
    

    It means you will only have a send to the gateway minimum every 5 minuts or if the value has been changed.
    So if your sensor is bad and only gives you 0 if should send every 5 minutes atleast. (and that could also be a 0). If you have a controller which doesnt update the value if its not changed it will look like it was never sent as well.

    Also, do you run this on batteries and sleep the node the 5 min delay wont work and you have to remove it.



  • @sundberg84 Here's my debug data with sensor connecte to pin A0:
    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=7)
    TSM:FPAR
    TSP:MSG:SEND 7-7-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-7 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=7)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-7 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    !TSP:MSG:SEND 7-7-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=fail:2.0.0
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
    TSP:MSG:READ 0-0-7 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=11,pt=0,l=9,sg=0,ft=0,st=ok:UV Sensor
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.2
    TSP:MSG:SEND 7-7-0-0 s=0,c=0,t=11,pt=0,l=0,sg=0,ft=0,st=ok:
    Request registration...
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-7 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=7, parent=0, distance=1, registration=1
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:0.00

    And here's my debug without sensor connected to arduino A0:
    TSM:CHKID:OK (ID=7)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 7-7-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-7 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.17
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.75
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:7.90
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.07
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.79
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.84
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.38
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.49
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.25
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.80
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.36
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.11
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.61
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.18
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.43
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.97
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.95
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.36
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.52
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.46
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:8.71
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.32
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.31
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.15
    TSP:MSG:SEND 7-7-0-0 s=0,c=1,t=11,pt=7,l=5,sg=0,ft=0,st=ok:9.39

    Isn't this strange ??
    I have already remove the sleep because i'm running this sensor on batteries.


  • Hardware Contributor

    @mrc-core - can you post your code as well? It looks like the node only reads the value once in the first debug. and alof of times in the second. You are sure the node doesnt sleep?



  • @sundberg84 Hi here's the code i'm using

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 7
    
    #include <MySensors.h>
    
    
    #define UV_SENSOR_ANALOG_PIN 0
    
    #define CHILD_ID_UV 0
    
    unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
    
    MyMessage uvMsg(CHILD_ID_UV, V_UV);
    
    unsigned long lastSend =0;
    float uvIndex;
    float lastUV = -1;
    uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170};
    
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("UV Sensor", "1.2");
    
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_UV, S_UV);
    }
    
    void loop()
    {
        unsigned long currentTime = millis();
    
        uint16_t uv = analogRead(UV_SENSOR_ANALOG_PIN);// Get UV value
        if (uv>1170) {
            uv=1170;
        }
    
        //Serial.print("UV Analog reading: ");
        //Serial.println(uv);
    
        int i;
        for (i = 0; i < 12; i++) {
            if (uv <= uvIndexValue[i]) {
                uvIndex = i;
                break;
            }
        }
    
        //calculate 1 decimal if possible
        if (i>0) {
            float vRange=uvIndexValue[i]-uvIndexValue[i-1];
            float vCalc=uv-uvIndexValue[i-1];
            uvIndex+=(1.0/vRange)*vCalc-1.0;
        }
    
        //Serial.print("UVI: ");
        //Serial.println(uvIndex,2);
    
        //Send value to gateway if changed, or at least every 5 minutes
        if ((uvIndex != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) {
            lastSend=currentTime;
            send(uvMsg.set(uvIndex,2));
            lastUV = uvIndex;
        }
    
        //sleep(SLEEP_TIME);
    }```

  • Hardware Contributor

    @mrc-core - ok, so most likley its your sensor that is wrong. As i mentioned above the value is only sent every 5 minute if the value is unchanged and it probalby is just 0 all the time (and therefore not sent). When you remove it the pin is floating which causes the value to change and beeing sent all the time.

    Check the connections for your sensor and maybe another sensor (analog) if you have to try it out. If another analog sensor works its your UV sensor thats causing this. If its the same, its your hardware (arduino) which is bad.



  • Hi, I have problem in making Vera and Gateway add the UV Sensor (I used the example sketch). I have the following error after Gateway detect 1 Device: "System error: Device:496: Fail to load implementation file D_UvSensor1.xml ". I have reviewed the Luup files in Develop Apps and verified that the mentioned file does not exists only the same file name with JSON extension (don't know why it is not available neither in the Vera UI7 zip file for MySensors). I googled to find the XML file with no luck. Please, could anyone share the XML file with me or any help will be appreciated. Thanks Fernando



  • This post is deleted!


  • I'm getting low readings. The voltage at the sensor was OK. So it had to be the calculation. In my opinion the conversion of the 1023 values into a voltage is missing which can then be calculated further.

    uint16_t   uv = analogRead(UV_SENSOR_ANALOG_PIN);// Get UV value
        uv = (uv* (5 / 1023.0))*1000; 
        if (uv>1170) {
            uv=1170;
        }
    


  • This post is deleted!

Log in to reply
 

Suggested Topics

  • 3
  • 110
  • 584
  • 347
  • 2
  • 109

21
Online

11.2k
Users

11.1k
Topics

112.5k
Posts