Humidity Sketch w/ DHT22: readings not reliable



  • Hi!

    When using the official temperature/humidity sketch with a 10k resistor between data and 3.3V VCC, the readings are not stable; I have lots of
    "Failed reading temperature from DHT"
    "Failed reading humidity from DHT"

    It seems that the temperature reading is successfull only every 4-5th time, while the humidity reading works every 1-2nd time.

    I'm using an 8mhz arduino pro mini 3.3V.
    Any ideas why this happens? Could a capacitor solve this problem?


  • Hardware Contributor

    maybe add gw.wait before your reading so it has enough time to sense...



  • Something like this

        Serial.print("Initializing DHT... ");
        DHT _dht;
        _dht.setup(DHT_PIN);
        delay(_dht.getMinimumSamplingPeriod());
        Serial.println("Done!");
    

    Or check the example here

    Cheers



  • guys, as written above, i'm already using the official temperature/humidity sketch.. 😃
    So there is a

    gw.wait(dht.getMinimumSamplingPeriod());
    

    before the reading.
    I tried to increase this period to static 2,5 seconds (default interval should be 2s according to datasheet), but sadly that didn't help.

    Here's what the serial monitor shows (strange, isn't it?):
    0_1454332301952_serial.png



  • Ok, lets see if I can replicate your situation

    Would you post the sketch and the log form serial?



  • @barduino said:

    Ok, lets see if I can replicate your situation

    Would you post the sketch and the log form serial?

    for the serial output, see above 🙂

    default sketch:

    /**
     * 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
     * 
     * DESCRIPTION
     * This sketch provides an example how to implement a humidity/temperature
     * sensor using DHT11/DHT-22 
     * http://www.mysensors.org/build/humidity
     */
     
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 60000; // 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);
    int node_id = 22;
    
    
    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;
    }
    
    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
    }
    
    


  • I have the same. For the temperature I always thought that there's less variation in values.
    Did you try removing the if (temperature != lastTemp) from the sketch to see if more values are registered?


  • Hero Member

    I can confirm that 3.3v in combination with some DHT22 sensors is not a stable solution. I switched to si7021/ sht21 completely (more reliable/ lower consumption/ etc.). other experiences



  • @lxz said:

    I have the same. For the temperature I always thought that there's less variation in values.

    well, i just realised that, goddammit 😄

    Since only every 10th reading or so is a failure, i can live with that I think.

    @AWI said:

    I can confirm that 3.3v in combination with some DHT22 sensors is not a stable solution. I switched to si7021/ sht21 completely (more reliable/ lower consumption/ etc.). other experiences

    thanks for the hint. I think I will switch to the si7021 in my pcb design, it seems to be almost the same price as the dht22.
    Another solution would be to power the DHT22 directly with 3.7V from my Lithium Battery instead the 3.3V from arduino's VCC.


  • Hardware Contributor

    yes, and with si7021 there is no delay, faster readings, i2c better, low power. I like it too 🙂


Log in to reply
 

Suggested Topics

49
Online

11.4k
Users

11.1k
Topics

112.6k
Posts