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. Announcements
  3. πŸ’¬ UV Sensor

πŸ’¬ UV Sensor

Scheduled Pinned Locked Moved Announcements
24 Posts 9 Posters 5.2k Views 7 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.
  • mrc-coreM mrc-core

    @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.

    sundberg84S Offline
    sundberg84S Offline
    sundberg84
    Hardware Contributor
    wrote on last edited by
    #14

    @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?

    Controller: Proxmox VM - Home Assistant
    MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
    MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
    RFLink GW - Arduino Mega + RFLink Shield, 433mhz

    mrc-coreM 1 Reply Last reply
    0
    • sundberg84S sundberg84

      @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?

      mrc-coreM Offline
      mrc-coreM Offline
      mrc-core
      wrote on last edited by
      #15

      @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.

      sundberg84S 1 Reply Last reply
      0
      • mrc-coreM mrc-core

        @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.

        sundberg84S Offline
        sundberg84S Offline
        sundberg84
        Hardware Contributor
        wrote on last edited by
        #16

        @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.

        Controller: Proxmox VM - Home Assistant
        MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
        MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
        RFLink GW - Arduino Mega + RFLink Shield, 433mhz

        mrc-coreM 1 Reply Last reply
        0
        • sundberg84S sundberg84

          @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.

          mrc-coreM Offline
          mrc-coreM Offline
          mrc-core
          wrote on last edited by
          #17

          @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.

          sundberg84S 1 Reply Last reply
          0
          • mrc-coreM mrc-core

            @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.

            sundberg84S Offline
            sundberg84S Offline
            sundberg84
            Hardware Contributor
            wrote on last edited by sundberg84
            #18

            @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?

            Controller: Proxmox VM - Home Assistant
            MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
            MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
            RFLink GW - Arduino Mega + RFLink Shield, 433mhz

            mrc-coreM 1 Reply Last reply
            0
            • sundberg84S sundberg84

              @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?

              mrc-coreM Offline
              mrc-coreM Offline
              mrc-core
              wrote on last edited by
              #19

              @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);
              }```
              sundberg84S 1 Reply Last reply
              0
              • mrc-coreM mrc-core

                @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);
                }```
                sundberg84S Offline
                sundberg84S Offline
                sundberg84
                Hardware Contributor
                wrote on last edited by sundberg84
                #20

                @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.

                Controller: Proxmox VM - Home Assistant
                MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                1 Reply Last reply
                0
                • pndgt0P Offline
                  pndgt0P Offline
                  pndgt0
                  wrote on last edited by
                  #21

                  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

                  1 Reply Last reply
                  0
                  • paqorP Offline
                    paqorP Offline
                    paqor
                    wrote on last edited by
                    #22
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • paqorP Offline
                      paqorP Offline
                      paqor
                      wrote on last edited by
                      #23

                      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;
                          }
                      
                      1 Reply Last reply
                      0
                      • paqorP Offline
                        paqorP Offline
                        paqor
                        wrote on last edited by
                        #24
                        This post is deleted!
                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        17

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.0k

                        Posts


                        Copyright 2019 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