0

when I am compiling this code, i got the error "dht does not name a type"

 #include <DHT.h>

 #include <DHT22.h>


  dht DHT;


  #define DHT22_PIN 5

 void setup()
{
    Serial.begin(9600);
    Serial.println("DHT TEST PROGRAM ");
    Serial.print("LIBRARY VERSION: ");
    Serial.println(DHT_LIB_VERSION);
    Serial.println();
    Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

 void loop()
{
     // READ DATA
     Serial.print("DHT22, \t");
     int chk = DHT.read22(DHT22_PIN);
     switch (chk)
    {
         case DHTLIB_OK:
             Serial.print("OK,\t");
              break;
        case DHTLIB_ERROR_CHECKSUM:
              Serial.print("Checksum error,\t");
              break;
        case DHTLIB_ERROR_TIMEOUT:
              Serial.print("Time out error,\t");
              break;
         default:
             Serial.print("Unknown error,\t");
            break;
      }
       // DISPLAY DATA
         Serial.print(DHT.humidity, 1);
        Serial.print(",\t");
         Serial.println(DHT.temperature, 1);
       delay(1000);

      }

i am using dht22 temp and humidity sensor, my libraries are in correct folder.

can any one help me removing this type of error..??

thanks in advance.

2 Answers2

2

I just dealt with this same problem for the past few hours and finally figured out what the issue was. I was copying and pasting the library files off of a webpage, and then trying to save them from within a sketch, so every time I saved my ".h" and ".cpp" files, I was actually saving them as ".h.ino" and ".cpp.ino" files, which will of course not be recognized during compile. I rectified this by copying the library code into a text document, then "Save As..." and changing the file type to be "All Files" and they saved as the correct file types. Stick those two files into a named folder in your Arduino Library file, and you should be good to go. This took my far too long to figure out; I am somewhat ashamed.

Hope this isn't way too late and it helps somebody! All the best

Flash
  • 21
  • 2
1

Here is what I use, before the setup section.:

#include <DHT.h>

#define DHTPIN 2

#define DHTTYPE DHT11

DHT dht(DHTPIN,DHTTYPE);

int chk;

float temp;

float hum;
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
SDsolar
  • 2,485
  • 3
  • 22
  • 32