πŸ’¬ Air Humidity Sensor - DHT


  • Admin

    This thread contains comments for the article "Air Humidity Sensor - DHT" posted on MySensors.org.



  • bonjour , quel library DHT utilisez vous ? j'ai un probleme de compilation

    Arduino:1.6.10 (Windows 10), Carte : "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"

    ATTENTION . DΓ©finition sur : 'Uncategorized'
    air_temp:73: error: no matching function for call to 'DHT::DHT()'
    
     DHT dht;
    
         ^
    
    C:\Users\rsalmon\Documents\Arduino\air_temp\air_temp.ino:73:5: note: candidates are:
    
    In file included from C:\Users\rsalmon\Documents\Arduino\air_temp\air_temp.ino:44:0:
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:40:4: note: DHT::DHT(uint8_t, uint8_t, uint8_t)
    
        DHT(uint8_t pin, uint8_t type, uint8_t count=6);
    
        ^
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:40:4: note:   candidate expects 3 arguments, 0 provided
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(const DHT&)
    
     class DHT {
    
           ^
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note:   candidate expects 1 argument, 0 provided
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(DHT&&)
    
    C:\Users\rsalmon\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:38:7: note:   candidate expects 1 argument, 0 provided
    
    C:\Users\rsalmon\Documents\Arduino\air_temp\air_temp.ino: In function 'void setup()':
    
    air_temp:91: error: 'class DHT' has no member named 'setup'
    
       dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
    
           ^
    
    air_temp:92: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
    
       if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
    
                                  ^
    
    air_temp:97: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
    
       sleep(dht.getMinimumSamplingPeriod());
    
                 ^
    
    C:\Users\rsalmon\Documents\Arduino\air_temp\air_temp.ino: In function 'void loop()':
    
    air_temp:104: error: 'class DHT' has no member named 'readSensor'
    
       dht.readSensor(true);
    
           ^
    
    air_temp:107: error: 'class DHT' has no member named 'getTemperature'
    
       float temperature = dht.getTemperature();
    
                               ^
    
    air_temp:114: error: 'class DHT' has no member named 'toFahrenheit'
    
           temperature = dht.toFahrenheit(temperature);
    
                             ^
    
    air_temp:131: error: 'class DHT' has no member named 'getHumidity'
    
       float humidity = dht.getHumidity();
    
                            ^
    
    no matching function for call to 'DHT::DHT()'
    

  • Mod

    Welcome to the MySensors community, @rsalmon

    You need to use the DHT library included in the MySensors examples. See https://forum.mysensors.org/topic/4672/dht-sketch-version-2-0-0-error-solved/

    Please use english when contributing in the foums, see https://forum.mysensors.org/topic/610/forum-user-guidelines



  • has any one been able to fix this error?


  • Mod

    @phillip yes, by following the instructions given in my post above.



  • I was looking for examples on mysensors 2.0 having several sensors in the same node and this sketch looks very iteresting.
    Thanks



  • Hi everybody,

    I try to uploaded the sketch on my arduino nano and I have an error with this line :dht.readSensor(true);

    When I delete this line I have no error on the upload but the senosr has no refresh...



  • @thomas-schneider
    Did you see the comments from Mikael?. Do you have the DHT library?.
    What does the error say?



  • Yes I saw the comments of Mickael. But sorry, I didn't understand how to download the library. Now all is done and ok ! We need to come back and download the entire folder. Why this library is not in mysensors library ? It's not easy for a newbie.

    Thanks for the support and congratulations for the website.



  • Can anyone please show how to connect more than one DHT with this sketch? What needs changing in the code? (I am OK with the hardware side of things).

    Once I have an example I can work the rest out but at the moment this bit baffles me! πŸ˜‰

    Thank you πŸ™‚



  • @skywatch
    I know what you mean, I was having the very same trouble with relay actuators, and that's where your solution lies. There is a sketch that allows you to name the number of relays, and then the sketch automatically names the children, you should be able to modify that, (or at least get an idea of how you have multiples of the same sensor on the same board) to add as many dht's as you have spare digital pins on your arduino. Good luck, hours of fun lies ahead πŸ˜‰



  • Is exist some way to calibrate DHT sensors? today i make a experiment assemble 5 nodes with 5 DHT11 sensors put all nodes on one table and leave them for some hours, and the result is the every sensor give different values about temperature and humidity + - MAX 5 degree Celsius around the real temperature in the room. Hardware used Arduino Nano X 5pc., HDT11 X 5pc., the power supply is 12V 2,2A enough to power all of the arduinos.



  • @tiana well you could simply calibrate the value you get in your sketch for every DHT on it's own. But you have to do a calibraton, meaning measure all of them at multiple temperatures and humidities.
    If it's only a offset you can also use

    // Set this offset if the sensor has a permanent small offset to the real temperatures
    #define SENSOR_TEMP_OFFSET 0
    

    to correct for this, otherwise you have to implement your calibration function on your own.



  • For some sensors is possible to make with offset, but some of the sensors changing their values 2 times in minute with + - 2 degree Celsius some times show more sometimes show less.



  • well I think this kind of noise can not be calibrated. I thought they all have different values, but with offset, linear oder squared function for deviation.



  • I read datasheet for DHT11 and 2 degree deviation is ok for them. Now i playing with DHT22 I try this #define SENSOR_TEMP_OFFSET -1.3, but nothing is changed the sensor still give me same value.


  • Mod

    @tiana try setting SENSOR_TEMP_OFFSET to a really big value, for example -30.8 to make sure that the change is large enough to be noticeable.



  • Where i can found good DHT library for this sketch ?


  • Mod

    @pepson how about the library linked from the build page?



  • sorry i found



  • Using library linked above
    Getting: no matching function for call to 'DHT::readSensor(bool)'



  • @hek
    hi, how do I change the readings from C to F?
    My sensor works fine, by I get the readings I celsius



  • @ramoncarranza
    Change the line in the sketch:

    temperature = dht.toFahrenheit(temperature);

    to

    temperature = dht.toCelsius(temperature);

    probably? I haven't checked it, just looked at the DHT library. You may need to comment the isMetric line earlier in the sketch too. But I think that's how you do it.



  • @mikeS Thanks so much for your reply, it's working perfectly now.



  • @Jim Danforth
    Getting the same, have tried a number of different DHT libraries and cant get it to compile.



  • @meanmrgreen The only DHT library that will work is the one from the link before the sketch. If you have used others chances are you need to move or rename those other DHT libraries as that is why the sketch cannot call that function.



  • @mikeS

    Ive tried to reinstall and start frΓ₯n scratch but i guess i Missed something.



  • @meanmrgreen sometimes windows puts libraries in your documents folder, so they may be located in 2 or more places. Use windows search to find them all. I have 3 DHT libraries, the mysensors one, the adafruit(I think) and another that came with an MQTT based sketch for an ESP board. I just rename them. Incidentally the mysensors DHT library gives me the most accurate results, as much as 2 degrees and 10% out on the same sensor using a different library.
    Also don't update the DHT library if you are told there is an update!
    As you can tell I had a few problems myself before I got this working, it almost made me disregard the whole project. Keep trying , it's worth it.



  • @mikeS thanks alot!
    I'll keep that in mind. Should be getting my "starter kit" order soon from eBay so we'll see how it goes πŸ˜‰



  • Finaly got it to compile.
    I tried the library link above but no go, cleared out everything about ardouino on the pc, no go.

    I finaly stubled onto this:
    https://github.com/mysensors/MySensorsArduinoExamples
    Downloaded all the expample libraries, loaded the scetch and it worked!

    Something is up with the linked library on this page i think


  • Mod

    @meanmrgreen the link pointed to a folder on GitHub. If that folder is downloaded, you get the MySensorsExamples. But in that folder, there is also a link to the original DHT library. If that link is followed, the wrong library will be downloaded.

    Several people have been bitten by this so I have now changed the link to point directly to the MySensorsExamples zip file.



  • Could someone explain me why "Must be >1000ms for DHT22 and >2000ms for DHT11" when sampling rate is once per sec for DHT11 (once per 1000ms) and twice per sec for DHT22 (once per 500ms)?



  • In Wiring Things Up and screen are used DATA_PIN 3, but in example is wrote #define DHT_DATA_PIN 2 πŸ™‚ ...please correct it.


  • Admin

    @Amput,

    Thanks, updated.



  • @hek

    No it is not fixed!



  • @hek how do I change fro C to F?


  • Mod

    @hek I think @skywatch meant that the text is updated, but not the picture. The picture is still using pin 3.


  • Mod

    @ramoncarranza set your controller to use non-metric.


  • Admin

    Yes, didn't see that one @mfalkvidd. Hmm.. Not sure I have the source photoshop psd available any more.


  • Mod

    @hek you mean you delete files? 😨


  • Admin

    Ha, probably not, just a matter of find it. πŸ˜“



  • What @Skywatch meant was that "#define DHT_DATA_PIN 2" is STILL in the example code on this page. Anyone who even gets as far as working it all out and wiring it all up and it still it won't work like that! - Not when it needs to be connected to PIN 3 instead (esp if the NRF is using pin 2, which is likely).
    Happy New Year to you all! πŸ™‚



  • Just a note, tried following this for adding a DHT11 to the ESP8266 MQTT gateway. The MySensors example lib does not work with esp8266 (temperatures around 17000+). However the adafruit DHT library 1.3.0 works just fine.Any reason that couldn't be used here?


  • Admin

    Nope. Most of the examples were only verified using Atmega. If you find a better lib working on both platforms, please create a pull request including the updated example and library.



  • Ok! I just have to verify it on Atmega first. I'll be back..



  • DHT sketch version 2.1.0 no data i IDE seiel

    And if i use DHT example sketch then I get data temp / hum

    Did not have permission to post in the forum



  • @hek @mfalkvidd I read that you discussed about PIN 2 and 3.

    Code say PIN 2, Wiring things up say PIN 2 and picture shows PIN 3.

    It can't use PIN 2 or can it, PIN 2 is used by the radio, or am I to tired :)?



  • @flopp

    thats the irq pin in the radio post.
    Not used by the radio



  • @meanmrgreen said:

    @flopp

    thats the irq pin in the radio post.
    Not used by the radio

    I must have missed something or forgot. Is PIN 2 only used on Gateways?
    Is it different between MyS version 1.x and 2.x?


  • Admin

    Tried to follow the history on the humidity file back in time on github.
    At some point (2.0 release) the example was switched from HumiditySensor.ino (using pin 3) to DhtTemperatureAndHumiditySensor.ino (pin 2) created by @mozzbozz.

    Not sure why the pin was switched, but you can run without the radio/IRQ-pin connection as long as not activating the MY_RX_MESSAGE_BUFFER_FEATURE.



  • @hek
    All other examples are using PIN 3. Wouldn't it be easier to use PIN 3 for all examples? Maybe we shall wait and see if mozzbozz know why he changed to PIN 2.


  • Admin

    Ok, updated the example on github and instructions on the page back to pin 3.



  • Hurrah! πŸ™‚

    Now I can sleep at night again πŸ˜‰

    Good job!


  • Admin

    @skywatch said:

    Now I can sleep at night again

    Haha, yeah, good to hear you will get a good nights sleep again.



  • @skywatch said:

    Hurrah! πŸ™‚

    Now I can sleep at night again πŸ˜‰

    Good job!

    haha, me too πŸ™‚



  • Hello. Maybe someone could help πŸ™‚ hopefully..
    I have arduino1 with 1 DHT22, which is over arduinoGW connected to RSPi with latest domoticz.
    when i connect stuff up, after some time i see some strange childids, not related to this arduino1 in no way.
    Lots of unknown!, with V_TEMP values, with V_HUM values, even V_FORECAST, V_PRESSURE and etc. which arduino1 should not send (or no other arduino on my area).

    Illustration:
    <img href="http://www.lstudio.lt/wp-content/uploads/dht22problem.png">
    http://www.lstudio.lt/wp-content/uploads/dht22problem.png

    my code is quite simple (for ex only temperature is shown)

    #define CHILD_DESCR "TEMP3"
    #undef CHILD_ID
    #define CHILD_ID 31
    present(CHILD_ID, S_TEMP, CHILD_DESCR);
    delay(250) ;
    
    loop:
    
      temp3=dht3.readTemperature();
    
    if (temp3 >= 120) {temp3 = lasttemp3;}
    if (temp3 <= -50) {temp3 = lasttemp3;}
    MyMessage msg31(CHILD_ID,V_TEMP);
    send(msg31.set(temp3,1));
    

    so.. that is basically all



  • @Pavel-Larkin

    I have also seen this, I noticed it last week. Some of my Nodes have those Unknown-child, but it is working correctly anyway.
    DZ 3.5877, MyS 1.5.1, RPi 2



  • Hello,
    i have a problem with this sketch.
    After downloading DTH.h froom Mysensors Examples, i have this error :
    DhtTemperatureAndHumiditySensor:85: error: 'getConfig' was not declared in this scope

    metric = getConfig().isMetric;

    Any Idea of my mistake ?...


  • Admin

    It isn't your mistake, it's ours. The examples hasn't been updated correctly to reflect the most recent change in the api.

    It should say getControllerConfig().isMetric



  • I have the dht22 sensor hooked up and working on a pro mini on pin 3 I get a normal temp reading but the humidity always stays at 1.0 does not read.


  • Mod



  • Hello everybody,
    hope, someone could help a newby πŸ™‚
    I've installed the MQTT - GW and would use the Air/Humidity - sensor. But it doesn't work properly.
    The Connection to the Gateway seems to be okay. But I get no Air/Humidity - Information.
    The sensor does not measure anything.
    I've tried to change the data - pin, I've tried the DHT11 and DHT22 - sensor. No choice.
    I'm getting mad πŸ™‚

    Thanks a lot.


  • Mod

    Have you tried the basic arduino sketch that prints data to serial port?



  • Hello,
    thanks a lot for your answer.
    Yes, I did. It produced the Messages as excepted.


  • Mod

    So you'd better post your code so we can take a look at what is wrong with it.



  • ...sorry, Typo.
    As expected πŸ™‚



  • ...no Problem:

    /**
     * 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
     * 
     */
    
    // 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 2
    
    // 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 = 30000;
    
    // 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
      Serial.println("Presentation");
      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 = getConfig().isMetric;
    }
    
    
    void setup()
    {
      Serial.println("vor Presentation");
      
      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()      
    {  
    
      Serial.println("loop Anfang");
      
      // 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); 
    }
    


  • I am using dht22 outside. Does any one know how to change to whole number not decimal. The temperature outside change a lot. Let say temp 20.2 changed to 20.4 and still sends to getaway . If I do "send(msgTemp.set(temperature, 0));" and still receive both times 20 and 20, and I want only if change to 21 or 19.


  • Mod

    @Arnold-Ε lepetis change

    float lastTemp;
    

    to

    signed int lastTemp;
    

    and

    float temperature = dht.getTemperature();
    

    to

    signed int temperature = dht.getTemperature() + 0.5; // Add 0.5 to get correct rounding
    

    and

    temperature = dht.toFahrenheit(temperature);
    

    to

    temperature = dht.toFahrenheit(temperature) + 0.5;
    

    and

    send(msgTemp.set(temperature, 1));
    

    to

    send(msgTemp.set(temperature));
    

    You might also have to handle the isnan test.



  • @mfalkvidd Thanks. It works like a charm



  • I've made a bit of an unusual observation in relationship to this script. I am running a fairly stripped-down version of it, but with the "standard" (not MySensors-customized) DHT library and its associated functions.

    Here is the code:

    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached 
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #define MY_NODE_ID 47
    
    #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 5
    
    // 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 = 10000;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht(DHT_DATA_PIN, DHT22);
    float temperature;
    float humidity;
    
    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()
    {
      delay(100);
    }
    
    
    void loop()      
    {  
      
      // Get temperature from DHT library
      temperature = dht.readTemperature();
      if (isnan(temperature))
      {
        Serial.println("Failed reading temperature from DHT!");
      }
        
      else
      {
        send(msgTemp.set(temperature,0));
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      }  
    
      // Get humidity from DHT library
      
      humidity = dht.readHumidity();
      if (isnan(humidity))
      {
        Serial.println("Failed reading humidity from DHT!");
      }
        
      else 
      {
        send(msgHum.set(humidity,1));
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      }
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL); 
    }
    

    I find that if I leave the last line as
    sleep(UPDATE_INTERVAL);
    then the sensor node ends up sending the same temperature and humidity values, over and over again, even if the actual humidity and temperature change.

    However, if I change the last line to
    delay(UPDATE_INTERVAL);
    then everything works as expected.

    This is with known good DHT22 units, so I suspect there is something funny about the sleep() function and the operation of the standard (not customized) DHT library.

    It took a lot of poking around to discover this, but is this in fact the reason why the MySensors customized DHT library is required for this script? Is that library necessary to make sleep() and DHT temperature measurements play nicely together?


  • Mod

    What libraries versions are you using?


  • Mod

    @jwosnick the example sketch has this:

      // Force reading sensor, so it works also after sleep()
    dht.readSensor(true);
    

    which is missing in your sketch. The comment suggests that it might be relevant.



  • @mfalkvidd

    Yes, absolutely. But it appears that the dht.readSensor() function is not actually part of the standard DHT library, but rather something that only appears in the MySensors-customized version of it. I'm trying to get a handle on why there is a need for a customized library.


  • Mod

    @jwosnick seems like the most recent version of the original library calls readSensor when getTemperature is called.

    Maybe the most recent version can be used if the MySensors example sketch is rewritten to just use getTemperature? Would it be possible for you to test this? It would be great if we could get rid of the MySensors-custimized version of the library and just let people install the standard DHT library.



  • @mfalkvidd said in πŸ’¬ Air Humidity Sensor:

    @jwosnick seems like the most recent version of the original library calls readSensor when getTemperature is called.

    Yes, it does... but somehow that function is not "exposed" to the outside world. With a standard DHT test sketch (nothing to do with MySensors) calling readSensor throws an error.


  • Mod

    @jwosnick yes. But since readSensor is called inside getTemperature, there should be no need to call it manually.



  • @jwosnick

    As your set sensor model

    DHT dht(DHT_DATA_PIN, DHT22);
    

    it looks like you use "Adafruit DHT-sensor-library".
    It's need dht.begin(); in setup(){ } which is missing in your sketch



  • @avgays
    Good catch -- thanks. Yes, that is the library I am using.

    Despite omitting that line, the script above works fine as long as the last line is a delay() function and not sleep(). If I use sleep(), it in fact appears to work, but sends the same temperature and humidity over and over again. So it is something about the sleep() function.

    I will add in the dht.begin() and then put sleep() back in and see what happens.



  • @avgays Confirmed that even with dht.begin(); the script still sends the same temp and humidity info, over and over again, as long as the sleep() function is in there. As soon as sleep() is replaced by delay() it all works properly.

    So I conclude from this that the MySensors-customized version of the DHT library must have something in it to make sleep() play nicely with the DHT unit. I wish I knew what that was. It would be ideal if this sensor (and the Dallas Semiconductor one) could be used with the MySensors system with their standard libraries.



  • @jwosnick
    Very strange as in my case this library work well with sleep() on battery-powered node.

    Look like it's nessesary to add delay(2000); before or after sleep() as sleep mode stops all timers, so
    currenttime - _lastreadtime =0
    and function returns with no new measurements.



  • Hi,
    I would like to use this example and reduce power consumtion by removing the regulator on the mini Pro and the power led.
    If we remove the regulator, we can power the board with 3V on Vcc. It will be OK for the mini pro and the NRF but the DHT22 needs 3.3V minimum. The solution will consist to use a step up boost module. What is the current consumtion of the step up boost?


  • Mod

    I don't know about DHT22, but NRF24 can work down to 1.8 or 1.9V so you can connect it directly to battery (take a look ad EasyPCB)


  • Hero Member

    @Digdogger it's better to get rid of the DHT and use something more reliable and operating at lower voltages. Like si7021, sht21 or Bme280



  • Thanx for your answers. @AWI, the BME280 looks great and not expansive i will replace the DHT by this one. Thank you.



  • @Digdogger
    Out of curiosity, do you expect there to be a big savings in power consumption by removing the regulator and power LED? I've never used the Mini Pro (the smallest I get to is the Nano) but I understand it already is very efficient with power usage.



  • @jwosnick: please take a look here: http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/.
    You'll see that the current saving is significant (almost 40% saving)


  • Mod

    @jwosnick
    Arduino is efficient for a live node, but for a battery powered sleeping node voltage regulators have a small drain on battery; led also consumes some power. The Nano has also the usb chip that is powered but not used that also increases battery drain. So, as rule of thumb, everything that is not really used/necessary will drain some battery over time.


  • Mod

    @jwosnick with the led and regulator, battery life on 2xAA is about three weeks. Removing them will usually give you 2-5 years.



  • @mfalkvidd

    Thank you. I didn't realize the differences were so stark.

    I have some Pro Mini 3.3V units on order and hope to convert my sensors to that platform, when they arrive.



  • hello I ran it but i didnt see anthing except the garbage in com monitor


  • Hardware Contributor

    @hashem25 said in πŸ’¬ Air Humidity Sensor:

    hello I ran it but i didnt see anthing except the garbage in com monitor

    Hello, you need to change the baud rate at the bottom right of the Arduino serial monitor window until you see clear text.



  • thanks it works



  • How do i get 2 dht22's working in the code?


  • Mod

    If you already have one, it is a matter of just repeating your code for the first sensor and just change the pin number where you connected the second one



  • This example doesn't seem to be included in the latest library version - am I being blind or is this deliberate?


  • Mod

    @ianatkin that is correct. Follow the instructions under the "Example" headline on the build page.



  • @mfalkvidd Thanks πŸ™‚


  • Mod

    @ianatkin you're welcome. Great to see a new forum member πŸ™‚



  • Is it the same code that i will burn to the controller circuit. Can someone help me with a little explanation on the code for the controller circuit so as to be receiving the temperature values


Log in to reply
 

Suggested Topics

  • 3
  • 109
  • 347
  • 10
  • 584
  • 164

61
Online

11.4k
Users

11.1k
Topics

112.6k
Posts