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. Hum temp rain sensor help

Hum temp rain sensor help

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 3 Posters 2.4k 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.
  • F Offline
    F Offline
    floris
    wrote on last edited by
    #1

    Hi,

    i merged 2 sketches and hoped that it would work. but not. the node sends only the temp when there is a change at the rain-sensor. and i want the temp/hum be send each couple of minutes. can anyone help? here is my sketch;.

    [code]
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RAIN 3

    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    #define DIGITAL_INPUT_SOIL_SENSOR_PIN 4
    #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msg(CHILD_ID_RAIN, V_TRIPPED);
    int lastSoilValue = -1;

    void setup()
    { 
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Floris Multi Rain+Hum", "1.0");

    // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);

    pinMode(DIGITAL_INPUT_SOIL_SENSOR_PIN, INPUT); // sets the motion sensor digital pin as input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_RAIN, S_MOTION);
      
     metric = gw.getConfig().isMetric; 
    }

    void loop()
    {

    // Read digital soil value
      int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR_PIN); // 1 = Not triggered, 0 = In soil with water
      if (soilValue != lastSoilValue) {
        Serial.println(soilValue);
        gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil
        lastSoilValue = soilValue;

    delay(dht.getMinimumSamplingPeriod());

    float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
      
      gw.sleep(SLEEP_TIME);
    }
    }

    [/code]

    TotcheT DwaltD 2 Replies Last reply
    0
    • F floris

      Hi,

      i merged 2 sketches and hoped that it would work. but not. the node sends only the temp when there is a change at the rain-sensor. and i want the temp/hum be send each couple of minutes. can anyone help? here is my sketch;.

      [code]
      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>

      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_RAIN 3

      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      #define DIGITAL_INPUT_SOIL_SENSOR_PIN 4
      #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

      MySensor gw;
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true;
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msg(CHILD_ID_RAIN, V_TRIPPED);
      int lastSoilValue = -1;

      void setup()
      { 
        gw.begin();
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

      // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Floris Multi Rain+Hum", "1.0");

      // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);

      pinMode(DIGITAL_INPUT_SOIL_SENSOR_PIN, INPUT); // sets the motion sensor digital pin as input
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_RAIN, S_MOTION);
        
       metric = gw.getConfig().isMetric; 
      }

      void loop()
      {

      // Read digital soil value
        int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR_PIN); // 1 = Not triggered, 0 = In soil with water
        if (soilValue != lastSoilValue) {
          Serial.println(soilValue);
          gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil
          lastSoilValue = soilValue;

      delay(dht.getMinimumSamplingPeriod());

      float temperature = dht.getTemperature();
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
            Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
            Serial.print("H: ");
            Serial.println(humidity);
        }
        
        gw.sleep(SLEEP_TIME);
      }
      }

      [/code]

      TotcheT Offline
      TotcheT Offline
      Totche
      wrote on last edited by
      #2

      @floris said:

      > Serial.println("Failed reading humidity from DHT");
      > } else if (humidity != lastHum) {
      > lastHum = humidity;
      > gw.send(msgHum.set(humidity, 1));
      > Serial.print("H: ");
      > Serial.println(humidity);
      
      

      Hello, have you a message on the serial print ? Failed reading humidity from DHT or the value ?

      If you want to send every 2 mns, you have to "sleep" 2601000 milllseconds - the processing time for your code (near 0 compared to 2 mns)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        floris
        wrote on last edited by
        #3

        Hi Totche, thanks for reaction.

        this is the serial print;
        sensor started, id 11
        send: 11-11-20-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=255,c=3,t=6,pt=1,l=1,st=ok:20
        send: 11-11-20-0 s=255,c=3,t=11,pt=0,l=21,st=ok:Floris Multi Rain+Hum
        send: 11-11-20-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
        send: 11-11-20-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=3,c=0,t=1,pt=0,l=5,st=ok:1.4.1
        1
        send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
        send: 11-11-20-0 s=1,c=1,t=0,pt=7,l=5,st=ok:22.3
        T: 22.30
        send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.0
        H: 59.00

        and after using the rain sensor:

        sensor started, id 11
        send: 11-11-20-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=255,c=3,t=6,pt=1,l=1,st=ok:20
        send: 11-11-20-0 s=255,c=3,t=11,pt=0,l=21,st=ok:Floris Multi Rain+Hum
        send: 11-11-20-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
        send: 11-11-20-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
        send: 11-11-20-0 s=3,c=0,t=1,pt=0,l=5,st=ok:1.4.1
        1
        send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
        send: 11-11-20-0 s=1,c=1,t=0,pt=7,l=5,st=ok:22.3
        T: 22.30
        send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.0
        H: 59.00
        0
        send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:1
        send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.1
        H: 59.10
        1
        send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
        send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.4
        H: 59.40

        Then i get a update from my hum/sensor....(so after activity from the rainsensor, there is an update for hum/rain, and not automagicly). For the moment i want to keep it to 30 seconds, for testing.
        i changed the gw.sleep;
        gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
        but no luck so far.

        1 Reply Last reply
        0
        • F floris

          Hi,

          i merged 2 sketches and hoped that it would work. but not. the node sends only the temp when there is a change at the rain-sensor. and i want the temp/hum be send each couple of minutes. can anyone help? here is my sketch;.

          [code]
          #include <SPI.h>
          #include <MySensor.h>  
          #include <DHT.h>

          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define CHILD_ID_RAIN 3

          #define HUMIDITY_SENSOR_DIGITAL_PIN 3
          #define DIGITAL_INPUT_SOIL_SENSOR_PIN 4
          #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

          unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

          MySensor gw;
          DHT dht;
          float lastTemp;
          float lastHum;
          boolean metric = true;
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          MyMessage msg(CHILD_ID_RAIN, V_TRIPPED);
          int lastSoilValue = -1;

          void setup()
          { 
            gw.begin();
            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

          // Send the Sketch Version Information to the Gateway
            gw.sendSketchInfo("Floris Multi Rain+Hum", "1.0");

          // Register all sensors to gw (they will be created as child devices)
            gw.present(CHILD_ID_HUM, S_HUM);
            gw.present(CHILD_ID_TEMP, S_TEMP);

          pinMode(DIGITAL_INPUT_SOIL_SENSOR_PIN, INPUT); // sets the motion sensor digital pin as input
            // Register all sensors to gw (they will be created as child devices)
            gw.present(CHILD_ID_RAIN, S_MOTION);
            
           metric = gw.getConfig().isMetric; 
          }

          void loop()
          {

          // Read digital soil value
            int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR_PIN); // 1 = Not triggered, 0 = In soil with water
            if (soilValue != lastSoilValue) {
              Serial.println(soilValue);
              gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil
              lastSoilValue = soilValue;

          delay(dht.getMinimumSamplingPeriod());

          float temperature = dht.getTemperature();
            if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT");
            } else if (temperature != lastTemp) {
              lastTemp = temperature;
              if (!metric) {
                temperature = dht.toFahrenheit(temperature);
              }
              gw.send(msgTemp.set(temperature, 1));
              Serial.print("T: ");
              Serial.println(temperature);
            }
            
            float humidity = dht.getHumidity();
            if (isnan(humidity)) {
                Serial.println("Failed reading humidity from DHT");
            } else if (humidity != lastHum) {
                lastHum = humidity;
                gw.send(msgHum.set(humidity, 1));
                Serial.print("H: ");
                Serial.println(humidity);
            }
            
            gw.sleep(SLEEP_TIME);
          }
          }

          [/code]

          DwaltD Offline
          DwaltD Offline
          Dwalt
          wrote on last edited by Dwalt
          #4

          @floris I think it may have to do with the brackets { } in your loop. You have a open bracket { for your first " if" statement to check the rain and it does not appear to close } until after your "sleep" function at the bottom of the entire loop. This would cause the hum and temp readings (and sleep) to be skipped until the "if" statement is satisfied.

          Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

          F 1 Reply Last reply
          1
          • DwaltD Dwalt

            @floris I think it may have to do with the brackets { } in your loop. You have a open bracket { for your first " if" statement to check the rain and it does not appear to close } until after your "sleep" function at the bottom of the entire loop. This would cause the hum and temp readings (and sleep) to be skipped until the "if" statement is satisfied.

            F Offline
            F Offline
            floris
            wrote on last edited by
            #5

            @Dwalt thanks, that did the trick. now it's working! thanks!

            Floris

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


            9

            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