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. General Discussion
  3. Can't compile Humidity sketch 2.0 .. What DHT library do I need?

Can't compile Humidity sketch 2.0 .. What DHT library do I need?

Scheduled Pinned Locked Moved General Discussion
19 Posts 9 Posters 18.3k Views 7 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.
  • C Offline
    C Offline
    chuckconnors
    wrote on last edited by
    #1

    I'm trying to compile the Humidity sketch 2.0 and am getting an error. Here's the sketch I'm using:

    https://raw.githubusercontent.com/mysensors/MySensorsArduinoExamples/master/examples/HumiditySensor/HumiditySensor.ino

    /**
     * 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
     */
     
    // Enable debug prints
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()  
    { 
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      metric = getConfig().isMetric;
    }
    
    void presentation()  
    { 
      // Send the Sketch Version Information to the Gateway
      sendSketchInfo("Humidity", "1.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);
    }
    
    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
     
      // Fetch temperatures from DHT sensor
      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);
        }
        send(msgTemp.set(temperature, 1));
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      }
      
      // Fetch humidity from DHT sensor
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          send(msgHum.set(humidity, 1));
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
      }
      
      sleep(SLEEP_TIME); //sleep a bit
    }
    

    The error I'm getting is this:

    
    Arduino: 1.6.6 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino:39:19: fatal error: DHT.h: No such file or directory
    
     #include <DHT.h>  
    
                       ^
    
    compilation terminated.
    
    exit status 1
    Error compiling.
    
    

    I noticed a case sensitive issue so I changed DHT.h to dht.h and I get a bit further but then hit an error on line:

    DHT dht;
    
    

    I changed that to dht dht; and get a bit further still:

    Arduino: 1.6.6 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino: In function 'void setup()':
    
    sketch_jul17e:55: error: 'class dht' has no member named 'setup'
    
       dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
           ^
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino: In function 'void loop()':
    
    sketch_jul17e:72: error: 'class dht' has no member named 'getMinimumSamplingPeriod'
    
       delay(dht.getMinimumSamplingPeriod());
    
                 ^
    
    sketch_jul17e:75: error: 'class dht' has no member named 'getTemperature'
    
       float temperature = dht.getTemperature();
    
                               ^
    
    sketch_jul17e:81: error: 'class dht' has no member named 'toFahrenheit'
    
           temperature = dht.toFahrenheit(temperature);
    
                             ^
    
    sketch_jul17e:91: error: 'class dht' has no member named 'getHumidity'
    
       float humidity = dht.getHumidity();
    
                            ^
    
    exit status 1
    'class dht' has no member named 'setup'
    
    

    As you've probably guessed, I'm just trying things to see if I can get it to work. I'm guessing it's a library thing and could use some guidance as to what library I should be using. Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chuckconnors
      wrote on last edited by
      #2

      Can someone please look at their libraries and tell me which one I need to use? Apparently installing Arduino IDE does not install this library by default and all the ones I've tried have failed. I don't see any documentation on which one to use.

      I've got a handful of sensors built but I can't program them until I get this resolved. I really appreciate your time and help. Thanks!

      AWIA 1 Reply Last reply
      0
      • C chuckconnors

        Can someone please look at their libraries and tell me which one I need to use? Apparently installing Arduino IDE does not install this library by default and all the ones I've tried have failed. I don't see any documentation on which one to use.

        I've got a handful of sensors built but I can't program them until I get this resolved. I really appreciate your time and help. Thanks!

        AWIA Offline
        AWIA Offline
        AWI
        Hero Member
        wrote on last edited by AWI
        #3

        @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

        Installation
        ------------
        
        Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
        
        [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
        [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
        [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```
        sundberg84S C 2 Replies Last reply
        1
        • AWIA AWI

          @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

          Installation
          ------------
          
          Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
          
          [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
          [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
          [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```
          sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by sundberg84
          #4

          @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          AWIA C 2 Replies Last reply
          0
          • sundberg84S sundberg84

            @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.

            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by
            #5

            @sundberg84 Do I hear volunteering for a revised build example? :) Or better a joint initiative?

            1 Reply Last reply
            2
            • AWIA AWI

              @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

              Installation
              ------------
              
              Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
              
              [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
              [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
              [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```
              C Offline
              C Offline
              chuckconnors
              wrote on last edited by
              #6

              @AWI said:

              @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

              Installation
              ------------
              
              Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
              
              [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
              [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
              [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```
              

              Thanks for the reply. I'm pretty sure that's one of the ones I tried. I ended up finding an old install I had and copied the library from there and it's working now.

              1 Reply Last reply
              0
              • tbowmoT Offline
                tbowmoT Offline
                tbowmo
                Admin
                wrote on last edited by
                #7

                @chuckconnors

                if you look at the "examples" repository, it both examples folder, and libraries that should work with the enclosed examples. Copy the library, that you want to use, to Arduino/libraries/... and the example to Arduino/... and try to compile them.

                C 1 Reply Last reply
                2
                • tbowmoT tbowmo

                  @chuckconnors

                  if you look at the "examples" repository, it both examples folder, and libraries that should work with the enclosed examples. Copy the library, that you want to use, to Arduino/libraries/... and the example to Arduino/... and try to compile them.

                  C Offline
                  C Offline
                  chuckconnors
                  wrote on last edited by
                  #8

                  @tbowmo said:

                  @chuckconnors

                  if you look at the "examples" repository, it both examples folder, and libraries that should work with the enclosed examples. Copy the library, that you want to use, to Arduino/libraries/... and the example to Arduino/... and try to compile them.

                  HOLY SMOKES! I totally missed the libraries directory. Thank you and sorry for the troubles.

                  1 Reply Last reply
                  0
                  • sundberg84S sundberg84

                    @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.

                    C Offline
                    C Offline
                    chuckconnors
                    wrote on last edited by
                    #9

                    @sundberg84 said:

                    @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.

                    Can you tell me what better sensors are out there? These DHT11's I have vary wildly with regards to relative humidity.

                    1 Reply Last reply
                    0
                    • sundberg84S Offline
                      sundberg84S Offline
                      sundberg84
                      Hardware Contributor
                      wrote on last edited by
                      #10

                      @chuckconnors - BMP180 or Bmp280 for example.

                      Controller: Proxmox VM - Home Assistant
                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                      C 1 Reply Last reply
                      0
                      • sundberg84S sundberg84

                        @chuckconnors - BMP180 or Bmp280 for example.

                        C Offline
                        C Offline
                        chuckconnors
                        wrote on last edited by
                        #11

                        @sundberg84 said:

                        @chuckconnors - BMP180 or Bmp280 for example.

                        Those appear to be atmospheric pressure sensors. Looking for humidity sensors other than the DHT11/DHT22.

                        1 Reply Last reply
                        0
                        • Nca78N Offline
                          Nca78N Offline
                          Nca78
                          Hardware Contributor
                          wrote on last edited by Nca78
                          #12

                          Hello,

                          DHT22 is already much better than DHT11 which I think is complete garbage: wild variations in both temp and humidity between sensors, too unprecise and it's getting worse with time.
                          I heave read somewhere (sorry don't remember where but it was a guy testing a lot of temp/humidity sensors) that the best one for humidity is BME280. It has also atmospheric pressure and temperature (but is not really good for temp) like BMP180/280.
                          The Si7020 like on the sensebender micro seems pretty good too.

                          Just don't expect the same price level :D

                          AWIA 1 Reply Last reply
                          0
                          • Nca78N Nca78

                            Hello,

                            DHT22 is already much better than DHT11 which I think is complete garbage: wild variations in both temp and humidity between sensors, too unprecise and it's getting worse with time.
                            I heave read somewhere (sorry don't remember where but it was a guy testing a lot of temp/humidity sensors) that the best one for humidity is BME280. It has also atmospheric pressure and temperature (but is not really good for temp) like BMP180/280.
                            The Si7020 like on the sensebender micro seems pretty good too.

                            Just don't expect the same price level :D

                            AWIA Offline
                            AWIA Offline
                            AWI
                            Hero Member
                            wrote on last edited by AWI
                            #13

                            @Nca78 said:

                            Just don't expect the same price level

                            :confused: Si7021 can be found for €2.65 (DHT22 €2.43) on ali-express. BME280 €4.07 including barometeric pressure.
                            A link to a comparison in this post

                            1 Reply Last reply
                            2
                            • karl261K Offline
                              karl261K Offline
                              karl261
                              wrote on last edited by
                              #14

                              Yes, BME280 seems pretty good for T, P, H. I did not have much luck with DHT22 and SI7021.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                r-nox
                                wrote on last edited by
                                #15

                                I'm dead in the water with the same issue. Downloading the lib from the location above yielded the same result.

                                mfalkviddM 1 Reply Last reply
                                0
                                • R r-nox

                                  I'm dead in the water with the same issue. Downloading the lib from the location above yielded the same result.

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

                                  @r-nox did you download the library from MySensors or did you follow the link in the readme and download the upstream version of the library? Only the former will work.

                                  R 1 Reply Last reply
                                  0
                                  • mfalkviddM mfalkvidd

                                    @r-nox did you download the library from MySensors or did you follow the link in the readme and download the upstream version of the library? Only the former will work.

                                    R Offline
                                    R Offline
                                    r-nox
                                    wrote on last edited by
                                    #17

                                    @mfalkvidd

                                    I can't tell what I'm using anymore. Been at it all afternoon installing and un installing. I think I'm using these now (https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/DHT).

                                    Where do I start please?

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      r-nox
                                      wrote on last edited by
                                      #18

                                      https://github.com/markruys/arduino-DHT/

                                      This one worked for me.

                                      What a frustrating time that was.

                                      1 Reply Last reply
                                      0
                                      • joaoabsJ Offline
                                        joaoabsJ Offline
                                        joaoabs
                                        wrote on last edited by joaoabs
                                        #19

                                        I really like mysensors.org, but I've always had difficulties with the site organization. In my opinion, is not intuitive at all, although it has a great and appealing theme.

                                        Well, maybe it shouldn't, but this sets me back when trying to build anything... I know this excellent initiative for a couple of years now, and from time to time I try to do something but I end up de-motivated because it takes too long to find simple answers/solutions. At the moment, I have nothing built although I have all the equipment I need, including SenserBenders. Yes, frustrating like r-nox commented 2 years ago.

                                        Anyway, my point is: For the ones looking for a library that makes this DHT sketch work, mysensors have compiled a set of libraries that include this DHT.h and many others. Just go to https://www.mysensors.org/about/arduino#optional---install-external-mysensors-examples (yes, the name is not intuitive, maybe the keyword library would make it more obvious?), or jump directly to here and follow the standard library instructions. It took me two hours to find this, hope it saves time for future followers of mysensors like myself.

                                        Good luck!

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


                                        22

                                        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