Error verifying DhtTemperatureAndHumiditySensor Script wont compile

  • I'm trying to setup a mysensor with DHT22 sensor. Following the script on the website and additional example scripts on Github.

    However the code wont verify / compile without an error saying it's missing DHT::Class().

    I'm using the Arduino IDE 1.8.5, the MySensors library installed through IDE, MySensors Library 2.1.1.

    I'm trying to verify the code to finall upload to an Arduino Pro Mini at 8mhz using an FTDI programmer over USB. But I don't think that should matter.

    Here's the error:

    DhtTemperatureAndHumiditySensor:73: error: no matching function for call to 'DHT::DHT()'
     DHT dht;
    /Users/enwhat/Desktop/DhtTemperatureAndHumiditySensor/DhtTemperatureAndHumiditySensor.ino:73:5: note: candidates are:
    In file included from /Users/enwhat/Desktop/DhtTemperatureAndHumiditySensor/DhtTemperatureAndHumiditySensor.ino:44:0:
    /Volumes/Data/Users/enwhat/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);
    /Volumes/Data/Users/enwhat/Documents/Arduino/libraries/DHT-sensor-library-master/DHT.h:40:4: note:   candidate expects 3 arguments, 0 provided
    /Volumes/Data/Users/enwhat/Documents/Arduino/libraries/DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(const DHT&)
     class DHT {
    /Volumes/Data/Users/enwhat/Documents/Arduino/libraries/DHT-sensor-library-master/DHT.h:38:7: note:   candidate expects 1 argument, 0 provided
    /Volumes/Data/Users/enwhat/Documents/Arduino/libraries/DHT-sensor-library-master/DHT.h:38:7: note: constexpr DHT::DHT(DHT&&)
    /Volumes/Data/Users/enwhat/Documents/Arduino/libraries/DHT-sensor-library-master/DHT.h:38:7: note:   candidate expects 1 argument, 0 provided
    /Users/enwhat/Desktop/DhtTemperatureAndHumiditySensor/DhtTemperatureAndHumiditySensor.ino: In function 'void setup()':
    DhtTemperatureAndHumiditySensor:91: error: 'class DHT' has no member named 'setup'
       dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
    DhtTemperatureAndHumiditySensor:92: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
       if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
    DhtTemperatureAndHumiditySensor:97: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
    /Users/enwhat/Desktop/DhtTemperatureAndHumiditySensor/DhtTemperatureAndHumiditySensor.ino: In function 'void loop()':
    DhtTemperatureAndHumiditySensor:104: error: 'class DHT' has no member named 'readSensor'
    DhtTemperatureAndHumiditySensor:107: error: 'class DHT' has no member named 'getTemperature'
       float temperature = dht.getTemperature();
    DhtTemperatureAndHumiditySensor:114: error: 'class DHT' has no member named 'toFahrenheit'
           temperature = dht.toFahrenheit(temperature);
    DhtTemperatureAndHumiditySensor:131: error: 'class DHT' has no member named 'getHumidity'
       float humidity = dht.getHumidity();
    exit status 1
    no matching function for call to 'DHT::DHT()'
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    Note: there's an additional script in File>Examples> that I can compile / verify without any errors. It appears to reference a DHT library without any issues.

    Here's the full DHTtester script:

    // Example testing sketch for various DHT humidity/temperature sensors
    // Written by ladyada, public domain
    #include "DHT.h"
    #define DHTPIN 2     // what digital pin we're connected to
    // Uncomment whatever type you're using!
    //#define DHTTYPE DHT11   // DHT 11
    #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
    //#define DHTTYPE DHT21   // DHT 21 (AM2301)
    // Connect pin 1 (on the left) of the sensor to +5V
    // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
    // to 3.3V instead of 5V!
    // Connect pin 2 of the sensor to whatever your DHTPIN is
    // Connect pin 4 (on the right) of the sensor to GROUND
    // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
    // Initialize DHT sensor.
    // Note that older versions of this library took an optional third parameter to
    // tweak the timings for faster processors.  This parameter is no longer needed
    // as the current DHT reading algorithm adjusts itself to work on faster procs.
    void setup() {
      Serial.println("DHTxx test!");
    void loop() {
      // Wait a few seconds between measurements.
      // Reading temperature or humidity takes about 250 milliseconds!
      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      float h = dht.readHumidity();
      // Read temperature as Celsius (the default)
      float t = dht.readTemperature();
      // Read temperature as Fahrenheit (isFahrenheit = true)
      float f = dht.readTemperature(true);
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
      // Compute heat index in Fahrenheit (the default)
      float hif = dht.computeHeatIndex(f, h);
      // Compute heat index in Celsius (isFahreheit = false)
      float hic = dht.computeHeatIndex(t, h, false);
      Serial.print("Humidity: ");
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(" *C ");
      Serial.print(" *F\t");
      Serial.print("Heat index: ");
      Serial.print(" *C ");
      Serial.println(" *F");

  • Mod

    Welcome to the MySensors community, @sentur !

    Could you post the full sketch that is causing the error?

  • Sure here's the sketch that wont compile.

     * 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 <>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list:
     * Documentation:
     * Support Forum:
     * 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.
     * Version 1.0: Henrik EKblad
     * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
     * This sketch provides an example of how to implement a humidity/temperature
     * sensor using a DHT11/DHT-22.
     * For more information, please visit:
    // 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)
    void loop()      
      // Force reading sensor, so it works also after sleep()
      // 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: ");
      } else {
        // Increase no update counter if the temperature stayed the same
      // 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: ");
      } else {
        // Increase no update counter if the humidity stayed the same
      // Sleep for a while to save energy

  • Mod

    @sentur thanks.

    It seems like you have installed a DHT library that is very different from the DHT library used by MySensors.

    The DHTester script seems to be built for Adafriut's DHT library. When I try to compile that with the DHT library used by MySensors, I get a lot of errors:

    sketch_nov11b:10: error: 'DHT22' was not declared in this scope
     #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
    C:\Users\Micke\AppData\Local\Temp\arduino_modified_sketch_594104\sketch_nov11b.ino:24:17: note: in expansion of macro 'DHTTYPE'
    C:\Users\Micke\AppData\Local\Temp\arduino_modified_sketch_594104\sketch_nov11b.ino: In function 'void setup()':
    sketch_nov11b:30: error: 'class DHT' has no member named 'begin'
    C:\Users\Micke\AppData\Local\Temp\arduino_modified_sketch_594104\sketch_nov11b.ino: In function 'void loop()':
    sketch_nov11b:39: error: 'class DHT' has no member named 'readHumidity'
       float h = dht.readHumidity();
    sketch_nov11b:41: error: 'class DHT' has no member named 'readTemperature'
       float t = dht.readTemperature();
    sketch_nov11b:43: error: 'class DHT' has no member named 'readTemperature'
       float f = dht.readTemperature(true);
    sketch_nov11b:52: error: 'class DHT' has no member named 'computeHeatIndex'
       float hif = dht.computeHeatIndex(f, h);
    sketch_nov11b:54: error: 'class DHT' has no member named 'computeHeatIndex'
       float hic = dht.computeHeatIndex(t, h, false);
    Using library DHT in folder: R:\Documents\Arduino\libraries\DHT (legacy)
    exit status 1
    'DHT22' was not declared in this scope

    Since you don't get those errors, you probably have the Adafruit DHT library installed.

    You'll need to either convert your sketch to use the Adafruit library, or remove the Adafruit library and install the one used by MySensors instead.

    If you have already installed the MySensors DHT library, you should have gotten a message like this:

    Multiple libraries were found for "DHT.h"
     Used: R:\Documents\Arduino\libraries\DHT
     Not used: R:\Documents\Arduino\libraries\arduino_702005

    If I install the Adafruit DHT library, the DHTTest sketch compiles fine but I get the Multiple libraries error and the MySensors DHT example can no longer be compiled.

  • All sorted. I removed all my libraries and started a fresh and the issue has resolved itself. Definitely to do with some sort of library conflict as mentioned by @mfalkvidd

  • Mod

    @sentur great that you found a solution. Thanks for reporting back.

Log in to reply

Suggested Topics

  • 3
  • 2
  • 4
  • 2
  • 24
  • 10