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. Development
  3. DHT11 Arduino pro mini no temp readings

DHT11 Arduino pro mini no temp readings

Scheduled Pinned Locked Moved Development
13 Posts 5 Posters 4.2k Views 4 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.
  • tonnerre33T Offline
    tonnerre33T Offline
    tonnerre33
    Hardware Contributor
    wrote on last edited by tonnerre33
    #4

    Hi, which sensor do you use ?
    A DHT put on a pcb or without pcb ?
    If you haven't a DHT with pcb, you need to put a 5k resistor between pin 1 and 2 of the DHT ;)
    More information here : https://www.mysensors.org/dl/57c3ec0c4d04abe84cd93e0f/design/DHT11.pdf

    M 1 Reply Last reply
    0
    • tonnerre33T tonnerre33

      Hi, which sensor do you use ?
      A DHT put on a pcb or without pcb ?
      If you haven't a DHT with pcb, you need to put a 5k resistor between pin 1 and 2 of the DHT ;)
      More information here : https://www.mysensors.org/dl/57c3ec0c4d04abe84cd93e0f/design/DHT11.pdf

      M Offline
      M Offline
      Mr_sensor
      wrote on last edited by
      #5

      @tonnerre33 No I have one with pcb.

      M 1 Reply Last reply
      0
      • M Mr_sensor

        @tonnerre33 No I have one with pcb.

        M Offline
        M Offline
        Mr_sensor
        wrote on last edited by
        #6

        @Mr_sensor Stil get the message

        Failed reading temperature from DHT!
        Failed reading humidity from DHT

        Also tried it with an dh22 I had (included a pull-up resistor between vcc and data) but get the same result. What can I do to get this working?
        If I use the arduino pro mini for an other sensor they are working fine (tested with a magnet-reed switch).

        1 Reply Last reply
        0
        • gohanG Offline
          gohanG Offline
          gohan
          Mod
          wrote on last edited by
          #7

          have you set all the waiting/delay times and the initialization before reading the temperature (as seen in the examples)?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr_sensor
            wrote on last edited by
            #8

            This is the sketch I'm using.

            /**
             * The MySensors Arduino library handles the wireless radio link and protocol
             * between your home built sensors/actuators and HA controller of choice.
             * The sensors forms a self healing radio network with optional repeaters. Each
             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
             * network topology allowing messages to be routed to nodes.
             *
             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
             * Copyright (C) 2013-2015 Sensnology AB
             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
             *
             * Documentation: http://www.mysensors.org
             * Support Forum: http://forum.mysensors.org
             *
             * This program is free software; you can redistribute it and/or
             * modify it under the terms of the GNU General Public License
             * version 2 as published by the Free Software Foundation.
             *
             *******************************
             *
             * REVISION HISTORY
             * Version 1.0: Henrik EKblad
             * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
             * 
             * DESCRIPTION
             * This sketch provides an example of how to implement a humidity/temperature
             * sensor using a DHT11/DHT-22.
             *  
             * For more information, please visit:
             * http://www.mysensors.org/build/humidity
             * 
             */
            #define MY_NODE_ID 2
            #define MY_PARENT_NODE_ID 0
            #define MY_PARENT_NODE_IS_STATIC
            
            // Enable debug prints
            #define MY_DEBUG
            
            // Enable and select radio type attached 
            #define MY_RADIO_NRF24
            //#define MY_RADIO_RFM69
            //#define MY_RS485
             
            #include <SPI.h>
            #include <MySensors.h>  
            #include <DHT.h>
            
            
            // Set this to the pin you connected the DHT's data pin to
            #define DHT_DATA_PIN 3
            
            // Set this offset if the sensor has a permanent small offset to the real temperatures
            #define SENSOR_TEMP_OFFSET 0
            
            // Sleep time between sensor updates (in milliseconds)
            // Must be >1000ms for DHT22 and >2000ms for DHT11
            static const uint64_t UPDATE_INTERVAL = 60000;
            
            // Force sending an update of the temperature after n sensor reads, so a controller showing the
            // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
            // the value didn't change since;
            // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
            static const uint8_t FORCE_UPDATE_N_READS = 10;
            
            #define CHILD_ID_HUM 0
            #define CHILD_ID_TEMP 1
            
            float lastTemp;
            float lastHum;
            uint8_t nNoUpdatesTemp;
            uint8_t nNoUpdatesHum;
            bool metric = true;
            
            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
            DHT dht;
            
            
            void presentation()  
            { 
              // Send the sketch version information to the gateway
              sendSketchInfo("TemperatureAndHumidity", "1.1");
              
              // Register all sensors to gw (they will be created as child devices)
              present(CHILD_ID_HUM, S_HUM);
              present(CHILD_ID_TEMP, S_TEMP);
              
              metric = getControllerConfig().isMetric;
            }
            
            
            void setup()
            {
              dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
              if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
                Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
              }
              // Sleep for the time of the minimum sampling period to give the sensor time to power up
              // (otherwise, timeout errors might occure for the first reading)
              sleep(dht.getMinimumSamplingPeriod());
            }
            
            
            void loop()      
            {  
              // Force reading sensor, so it works also after sleep()
              dht.readSensor(true);
              
              // Get temperature from DHT library
              float temperature = dht.getTemperature();
              if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT!");
              } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
                // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
                lastTemp = temperature;
                if (!metric) {
                  temperature = dht.toFahrenheit(temperature);
                }
                // Reset no updates counter
                nNoUpdatesTemp = 0;
                temperature += SENSOR_TEMP_OFFSET;
                send(msgTemp.set(temperature, 1));
            
                #ifdef MY_DEBUG
                Serial.print("T: ");
                Serial.println(temperature);
                #endif
              } else {
                // Increase no update counter if the temperature stayed the same
                nNoUpdatesTemp++;
              }
            
              // Get humidity from DHT library
              float humidity = dht.getHumidity();
              if (isnan(humidity)) {
                Serial.println("Failed reading humidity from DHT");
              } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
                // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
                lastHum = humidity;
                // Reset no updates counter
                nNoUpdatesHum = 0;
                send(msgHum.set(humidity, 1));
                
                #ifdef MY_DEBUG
                Serial.print("H: ");
                Serial.println(humidity);
                #endif
              } else {
                // Increase no update counter if the humidity stayed the same
                nNoUpdatesHum++;
              }
            
              // Sleep for a while to save energy
              sleep(UPDATE_INTERVAL); 
            }
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mr_sensor
              wrote on last edited by
              #9

              since I did not get these Dht11 or Dht22 working, I decided to try an other sensor type to see if that would work better.
              So I connected a HTU21D sensor and included the library from sparkfun. Using there demo sketch I can see the sensor is working fine:

              HTU21D Example!
              Time:192 Temperature:20.8C Humidity:998.0%
              Time:1318 Temperature:20.8C Humidity:47.3%
              Time:2445 Temperature:20.7C Humidity:47.4%
              Time:3571 Temperature:20.7C Humidity:47.4%
              Time:4698 Temperature:20.7C Humidity:47.5%
              Time:5824 Temperature:20.7C Humidity:47.5%
              Time:6948 Temperature:20.7C Humidity:47.6%
              Time:8075 Temperature:20.7C Humidity:47.6%
              Time:9201 Temperature:20.7C Humidity:47.6%

              But when I include the "adapted" Mysensors sketch I found here in the forum it seems the temperatures are not read or something else is wrong?

              This is what is in the log file in a ongoing loop:

              MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
              4 TSM:INIT
              4 TSF:WUR:MS=0
              12 TSM:INIT:TSP OK
              14 TSM:INIT:STATID=2
              16 TSF:SID:OK,ID=2
              18 TSM:FPAR
              18 TSM:FPAR:STATP=0
              20 TSM:ID
              22 TSM:ID:OK
              22 TSM:UPL
              28 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
              47 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1
              53 TSF:MSG:PONG RECV,HP=1
              55 TSM:UPL:OK
              57 TSM:READY:ID=2,PAR=0,DIS=1
              63 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
              75 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
              86 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
              96 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
              2107 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
              2119 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
              2129 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
              2140 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
              2146 MCO:REG:REQ
              2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
              2220 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
              2226 MCO:PIM:NODE REG=1
              2228 MCO:BGN:INIT OK,TSP=1
              2 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
              6 TSM:INIT
              6 TSF:WUR:MS=0
              14 TSM:INIT:TSP OK
              16 TSM:INIT:STATID=2
              18 TSF:SID:OK,ID=2
              20 TSM:FPAR
              20 TSM:FPAR:STATP=0
              22 TSM:ID
              24 TSM:ID:OK
              26 TSM:UPL
              30 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
              57 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1
              63 TSF:MSG:PONG RECV,HP=1
              67 TSM:UPL:OK
              67 TSM:READY:ID=2,PAR=0,DIS=1
              73 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
              92 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
              102 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
              112 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
              2121 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
              2134 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
              2144 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
              2154 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
              2160 MCO:REG:REQ
              2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
              2234 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
              2240 MCO:PIM:NODE REG=1
              2242 MCO:BGN:INIT OK,TSP=1
              

              This is the sketch I use now I had to adopt it since it seemed to be for an older version of Mysensors. I'm no programmer so it might be messed up somehow :)

              /**
               * The MySensors Arduino library handles the wireless radio link and protocol
               * between your home built sensors/actuators and HA controller of choice.
               * The sensors forms a self healing radio network with optional repeaters. Each
               * repeater and gateway builds a routing tables in EEPROM which keeps track of the
               * network topology allowing messages to be routed to nodes.
               *
               * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
               * Copyright (C) 2013-2015 Sensnology AB
               * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
               *
               * Documentation: http://www.mysensors.org
               * Support Forum: http://forum.mysensors.org
               *
               * This program is free software; you can redistribute it and/or
               * modify it under the terms of the GNU General Public License
               * version 2 as published by the Free Software Foundation.
               *
               *******************************
               *
               * REVISION HISTORY
               * Version 1.0: Henrik EKblad
               * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
               * 
               * DESCRIPTION
               * This sketch provides an example of how to implement a humidity/temperature
               * sensor using a DHT11/DHT-22.
               *  
               * For more information, please visit:
               * http://www.mysensors.org/build/humidity
               * 
               HTU21D Humidity Sensor
               Hardware Connections (Breakoutboard to Arduino):
               -VCC = 3.3V
               -GND = GND
               -SDA = A4 (use inline 330 ohm resistor if your board is 5V)
               -SCL = A5 (use inline 330 ohm resistor if your board is 5V)
               */
              
               
              #define MY_NODE_ID 2
              #define MY_PARENT_NODE_ID 0
              #define MY_PARENT_NODE_IS_STATIC
              
              // Enable debug prints
              #define MY_DEBUG
              
              // Enable and select radio type attached 
              #define MY_RADIO_NRF24
              //#define MY_RADIO_RFM69
              //#define MY_RS485
               
              #include "SparkFunHTU21D.h"
              #include <MySensors.h>  
              #include <Wire.h>
              #include <SPI.h>
              
              // Force sending an update of the temperature after n sensor reads, so a controller showing the
              // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
              // the value didn't change since;
              // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
              //static const uint8_t FORCE_UPDATE_N_READS = 10;
              
              #define CHILD_ID_HUM 0
              #define CHILD_ID_TEMP 1
              
              float lastTemp;
              float lastHum;
              uint8_t nNoUpdatesTemp;
              uint8_t nNoUpdatesHum;
              boolean metric = true;
              
              
              void presentation()  
              { 
               // Send the Sketch Version Information to the Gateway                                                                                                                     
                sendSketchInfo("Humidity", "2.0");      
                 
               // Register all sensors to gw (they will be created as child devices)                                                                                                     
                present(CHILD_ID_HUM, S_HUM);                                                                                                                                          
                present(CHILD_ID_TEMP, S_TEMP);                                                                                                                                        
               
                //metric = getControllerConfig().isMetric;
              }
              
                                                                                                                                                                
              unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)                                                                                             
                                                                                                                                                                                      
                                                                                                                                                                             
                                                                                                                                                                                      
              //Create an instance of the object                                                                                                                                          
              HTU21D myHumidity;                                                                                                                                                         
              
                                                                                                                                                                                                                                                                                                                                           
              MyMessage msgHum(CHILD_ID_HUM, V_HUM);                                                                                                                                      
              MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                
              void loop()                                                                                                                                                                 
              {                                                                                                                                                                           
                float temperature = myHumidity.readTemperature();                                                                                                                         
                //if (!metric) {                                                                                                                                                            
                //    temperature = (temperature * 1.8) + 32.0;                                                                                                                             
                //}                                                                                                                                                                         
                send(msgTemp.set(temperature, 1));                                                                                                                                     
              
                float humidity = myHumidity.readHumidity();                                                                                                                               
                send(msgHum.set(humidity, 1));                                                                                                                                         
                                                                                                                                                                                      
                sleep(SLEEP_TIME); //sleep a bit  
                                                                                                                                                     
              }
              

              Can anyone advise me on the code and the error log so I understand what's going on and what needs to be done to get it working? Thanks a lot.

              W.

              mfalkviddM 1 Reply Last reply
              0
              • M Mr_sensor

                since I did not get these Dht11 or Dht22 working, I decided to try an other sensor type to see if that would work better.
                So I connected a HTU21D sensor and included the library from sparkfun. Using there demo sketch I can see the sensor is working fine:

                HTU21D Example!
                Time:192 Temperature:20.8C Humidity:998.0%
                Time:1318 Temperature:20.8C Humidity:47.3%
                Time:2445 Temperature:20.7C Humidity:47.4%
                Time:3571 Temperature:20.7C Humidity:47.4%
                Time:4698 Temperature:20.7C Humidity:47.5%
                Time:5824 Temperature:20.7C Humidity:47.5%
                Time:6948 Temperature:20.7C Humidity:47.6%
                Time:8075 Temperature:20.7C Humidity:47.6%
                Time:9201 Temperature:20.7C Humidity:47.6%

                But when I include the "adapted" Mysensors sketch I found here in the forum it seems the temperatures are not read or something else is wrong?

                This is what is in the log file in a ongoing loop:

                MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
                4 TSM:INIT
                4 TSF:WUR:MS=0
                12 TSM:INIT:TSP OK
                14 TSM:INIT:STATID=2
                16 TSF:SID:OK,ID=2
                18 TSM:FPAR
                18 TSM:FPAR:STATP=0
                20 TSM:ID
                22 TSM:ID:OK
                22 TSM:UPL
                28 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
                47 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1
                53 TSF:MSG:PONG RECV,HP=1
                55 TSM:UPL:OK
                57 TSM:READY:ID=2,PAR=0,DIS=1
                63 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
                75 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                86 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
                96 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
                2107 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
                2119 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
                2129 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
                2140 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
                2146 MCO:REG:REQ
                2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
                2220 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                2226 MCO:PIM:NODE REG=1
                2228 MCO:BGN:INIT OK,TSP=1
                2 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
                6 TSM:INIT
                6 TSF:WUR:MS=0
                14 TSM:INIT:TSP OK
                16 TSM:INIT:STATID=2
                18 TSF:SID:OK,ID=2
                20 TSM:FPAR
                20 TSM:FPAR:STATP=0
                22 TSM:ID
                24 TSM:ID:OK
                26 TSM:UPL
                30 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
                57 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1
                63 TSF:MSG:PONG RECV,HP=1
                67 TSM:UPL:OK
                67 TSM:READY:ID=2,PAR=0,DIS=1
                73 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
                92 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                102 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
                112 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
                2121 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
                2134 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0
                2144 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
                2154 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
                2160 MCO:REG:REQ
                2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
                2234 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                2240 MCO:PIM:NODE REG=1
                2242 MCO:BGN:INIT OK,TSP=1
                

                This is the sketch I use now I had to adopt it since it seemed to be for an older version of Mysensors. I'm no programmer so it might be messed up somehow :)

                /**
                 * The MySensors Arduino library handles the wireless radio link and protocol
                 * between your home built sensors/actuators and HA controller of choice.
                 * The sensors forms a self healing radio network with optional repeaters. Each
                 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                 * network topology allowing messages to be routed to nodes.
                 *
                 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                 * Copyright (C) 2013-2015 Sensnology AB
                 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                 *
                 * Documentation: http://www.mysensors.org
                 * Support Forum: http://forum.mysensors.org
                 *
                 * This program is free software; you can redistribute it and/or
                 * modify it under the terms of the GNU General Public License
                 * version 2 as published by the Free Software Foundation.
                 *
                 *******************************
                 *
                 * REVISION HISTORY
                 * Version 1.0: Henrik EKblad
                 * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
                 * 
                 * DESCRIPTION
                 * This sketch provides an example of how to implement a humidity/temperature
                 * sensor using a DHT11/DHT-22.
                 *  
                 * For more information, please visit:
                 * http://www.mysensors.org/build/humidity
                 * 
                 HTU21D Humidity Sensor
                 Hardware Connections (Breakoutboard to Arduino):
                 -VCC = 3.3V
                 -GND = GND
                 -SDA = A4 (use inline 330 ohm resistor if your board is 5V)
                 -SCL = A5 (use inline 330 ohm resistor if your board is 5V)
                 */
                
                 
                #define MY_NODE_ID 2
                #define MY_PARENT_NODE_ID 0
                #define MY_PARENT_NODE_IS_STATIC
                
                // Enable debug prints
                #define MY_DEBUG
                
                // Enable and select radio type attached 
                #define MY_RADIO_NRF24
                //#define MY_RADIO_RFM69
                //#define MY_RS485
                 
                #include "SparkFunHTU21D.h"
                #include <MySensors.h>  
                #include <Wire.h>
                #include <SPI.h>
                
                // Force sending an update of the temperature after n sensor reads, so a controller showing the
                // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
                // the value didn't change since;
                // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
                //static const uint8_t FORCE_UPDATE_N_READS = 10;
                
                #define CHILD_ID_HUM 0
                #define CHILD_ID_TEMP 1
                
                float lastTemp;
                float lastHum;
                uint8_t nNoUpdatesTemp;
                uint8_t nNoUpdatesHum;
                boolean metric = true;
                
                
                void presentation()  
                { 
                 // Send the Sketch Version Information to the Gateway                                                                                                                     
                  sendSketchInfo("Humidity", "2.0");      
                   
                 // Register all sensors to gw (they will be created as child devices)                                                                                                     
                  present(CHILD_ID_HUM, S_HUM);                                                                                                                                          
                  present(CHILD_ID_TEMP, S_TEMP);                                                                                                                                        
                 
                  //metric = getControllerConfig().isMetric;
                }
                
                                                                                                                                                                  
                unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)                                                                                             
                                                                                                                                                                                        
                                                                                                                                                                               
                                                                                                                                                                                        
                //Create an instance of the object                                                                                                                                          
                HTU21D myHumidity;                                                                                                                                                         
                
                                                                                                                                                                                                                                                                                                                                             
                MyMessage msgHum(CHILD_ID_HUM, V_HUM);                                                                                                                                      
                MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                  
                void loop()                                                                                                                                                                 
                {                                                                                                                                                                           
                  float temperature = myHumidity.readTemperature();                                                                                                                         
                  //if (!metric) {                                                                                                                                                            
                  //    temperature = (temperature * 1.8) + 32.0;                                                                                                                             
                  //}                                                                                                                                                                         
                  send(msgTemp.set(temperature, 1));                                                                                                                                     
                
                  float humidity = myHumidity.readHumidity();                                                                                                                               
                  send(msgHum.set(humidity, 1));                                                                                                                                         
                                                                                                                                                                                        
                  sleep(SLEEP_TIME); //sleep a bit  
                                                                                                                                                       
                }
                

                Can anyone advise me on the code and the error log so I understand what's going on and what needs to be done to get it working? Thanks a lot.

                W.

                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by mfalkvidd
                #10

                @Mr_sensor I think you need to add

                void setup() {
                    myHumidity.begin();
                }
                

                Without that, the sensor/sensor library is not initialized.

                (I looked at sparkfun's example sketch)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mr_sensor
                  wrote on last edited by Mr_sensor
                  #11

                  :) Great! That helped a lot. I Kicked that out when reading the Converting a sketch from 1.5 to 2.x article.

                  4911 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.4
                  4954 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:50.2
                  4962 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255
                  4968 MCO:SLP:TPD
                  

                  Now I only have to find out what to use for mqtt to read this sensor values. Thats still not very clear to me:
                  Guess it would be something like:
                  mygateway1-out/2/2/0/0/ or 2/2/0/0/1 ?

                  Would it be possible to have something like this:

                  mygateway-out/2/2/Temperature ?

                  1 Reply Last reply
                  1
                  • M Offline
                    M Offline
                    Mr_sensor
                    wrote on last edited by
                    #12

                    Ok found out what topic is send to mqtt turned out to be:
                    mygateway1-out/2/1/1/0/1 or mygateway1-out/2/0/1/0/1

                    How to get an % and "C" to this topic value?

                    1 Reply Last reply
                    0
                    • gohanG Offline
                      gohanG Offline
                      gohan
                      Mod
                      wrote on last edited by
                      #13

                      Just use any mqtt client and subscribe to topic # , you will be able to see all messages and pick the one you are looking for

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


                      6

                      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