Can you calibrate DHT11?



  • Hi all,

    Does anyone know if its possible to calibrate a DHT11 humidity/temperature sensor, specifically the temperature element?

    Based on other thermostats and temperature sensors it is reading about 2 degrees C high i.e. 23 deg C instead of 21 deg C.

    Alternatively, is there a way I can factor in an adjustment to the sketch so the temperature reported in the Arduino Temp device in Vera UI15 is reported 2 degrees lower?

    I've tried amending the code in the sketch as per below but this only changes the values printed to the serial monitor and not the device in Vera.

    [code]
    
    Serial.println(temperature - 2.0); // adjusted as reading 2 degrees C higher than room thermostat
    

    [/code]

    I'm a noob when it comes to Arduino, programming and Vera so please bear with me...

    Setup:

    • Vera Lite running UI15
    • Mysensors Serial Gateway
    • Mysensors DHT11 Humidity (& temperature) sensor

    Cheers,

    stubtoe


  • Mod

    @stubtoe said:

    calibrate a DHT11 humidity/temperature sensor,

    Judging from the rest of your post you just want to lower the actual value reported by the sensor, correct?

    Don't change only the value printed to the serial port, as you do by changing the Serial.println statement.
    You should correct the value read from the sensor, e.g.:

    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        temperature = temperature - 2.0;   // Here you correct the value just read
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      } 
    
    // etc....
    


  • Yes that was correct, so your solution has worked perfectly. Thank you.

    I also understand where I went wrong now so thank you for point that out. I probably should have figured that out myself if I'd read and understood the code a bit better, but hey ho...


  • Mod

    That code will report the temperature every time, unless the new temperature is two degrees higher than last temperature.
    I guess it's not a big problem, but this is a more correct solution:

    void loop()
    {
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT");
      } else {
        temperature = temperature - 2.0;   // Here you correct the value just read
        if (temperature != lastTemp) {
    
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
      }
    // etc....
    

  • Mod

    @mfalkvidd 👍
    I personally prefer to immediately correct the value when read from the dht:

    float temperature = dht.getTemperature() - 2.0;
    

    In case the dht returns a NaN value, this value will stay NaN even when 2.0 is substracted.
    But I didn't want to complicate things 😉


 

Suggested Topics

411
Online

8.1k
Users

9.0k
Topics

95.3k
Posts