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. DHT11 and a RELAY combinaison problem

DHT11 and a RELAY combinaison problem

Scheduled Pinned Locked Moved Troubleshooting
4 Posts 2 Posters 2.0k 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.
  • mikeadresseM Offline
    mikeadresseM Offline
    mikeadresse
    wrote on last edited by
    #1

    Hi,
    I need a good kick , i try to make working a DHT 11 with a Relay.
    I have veraedge with ethernet gateway working for ''simple'' sensor,
    No problem with 1X sensor...
    but when i try to put 2 togethers no succes...
    Could somebody ''educate'' me please!
    this my code:
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    #include <DHT.h>

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1 // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay

    // NRFRF24L01 radio driver (set low transmit power by default)
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    MyHwATMega328 hw;
    // Construct MySensors library
    MySensor gw(radio, hw);

    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

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

    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("Humidity", "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);
    metric = gw.getConfig().isMetric;

    // Initialize library and add callback for incoming messages
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    // gw.sendSketchInfo("Relay", "1.0");

    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay
    digitalWrite(pin,HIGH);
    }
    }

    void loop()
    {
    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); //sleep a bit
    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }

    HERE THE DEBUG CODE:
    send: 13-13-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 13-13-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 13-13-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-13 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=13, parent=0, distance=1
    send: 13-13-0-0 s=255,c=3,t=11,pt=0,l=8,sg=0,st=ok:Humidity
    send: 13-13-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 13-13-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 13-13-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 13-13-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    repeater started, id=13, parent=0, distance=1
    send: 13-13-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 13-13-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=ok:23.0
    T: 23.00
    send: 13-13-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:35.0
    H: 35.00

    I have tried with: // gw.sendSketchInfo("Relay", "1.0"); (activated and not)
    Like i said everything is ok with one sensor... Thanks Mike

    1 Reply Last reply
    0
    • mikeadresseM Offline
      mikeadresseM Offline
      mikeadresse
      wrote on last edited by
      #2

      Hi, again,
      -Before posting i went threw all the forum and also the debug FAQ
      -Spent many hourssss before asking....
      -Got serialgateway+ethernetgateway+onewire+dht11+relay+motion sensor :Working!
      -i have relay + sensor problem, small lack of knowledge here ...
      -Problem is my Veraedge with 1.5 release dont find the Relay...
      -I have tried to ''restore'' my library, but like i wrote 1X sensor is working but not both...
      -Radio have an electrolytic capacitor and working good.
      -supply for the radio is ok too... not coming from the nano...
      -and sketch upload as unique sensor is working for both relay and dht11 when alone...

      I have a problem in the ''setup'' for sure,
      i need a kick in my...
      Tried a lot of different things with the same issue: Veraedge dont find one part of the sensor : Could be temperature or relay...But always find Humidity...
      Please a clue ...
      Mike

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nuubi
        wrote on last edited by
        #3

        I think this is the way to go and learn:
        http://forum.mysensors.org/topic/2597/combining-mysensors-examples

        1 Reply Last reply
        0
        • mikeadresseM Offline
          mikeadresseM Offline
          mikeadresse
          wrote on last edited by
          #4

          Thanks Nuubi ! For pointing this link! :smiley: :+1:
          '''Cent fois sur le métier remettez votre ouvrage!''' :sweat:
          Because you pointed it to me, i had to go back in this thread, again...
          Trying to find what was different from the 100 sketchs i tried...

          EUREKA :exclamation: ''development branch of MySensors Arduino package''
          ''https://github.com/mysensors/Arduino/archive/development.zip''

          I was not using the proper library...
          Now my Veraedge find everything ! :relaxed:
          Thanks again ! And also Thanks to Hek for ''Combining MySensors examples'' :clap:
          Mike

          1 Reply Last reply
          2

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          9

          Online

          12.0k

          Users

          11.2k

          Topics

          113.4k

          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