DHT 22 Library difficulty

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

DHT 22 Library difficulty

Post by scottlit »

I am new to using this forum and coding with the Arduino IDE, so thanks in advance for your patience. When using the code(example code found in the library) that Adafruit has posted on Github, I have been receiving a compiler error ('DHT does not name a type') when verifying in the IDE. Error is referring to the line as follows: DHT dht(DHTPIN, DHTTYPE);
If it helps I have the most recent version of the Arduino IDE. I'm not familiar with using the #define function, and I am assuming that there are no differences in the current IDE and the version that was current at the time this library was written.
Listed below is the code. Any help is very much appreciated



Code: Select all

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +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

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 
  dht.begin();
}

void loop() {
  // 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();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }
}
Last edited by adafruit_support_bill on Fri Feb 07, 2014 9:30 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Library difficulty

Post by adafruit_support_bill »

DHT does not name a type'
This means that the compiler was not able to find the DHT library in the expected location. Make sure that the library is installed as described in this guide: http://learn.adafruit.com/adafruit-all- ... nstall-use

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Library difficulty

Post by scottlit »

Thanks. That definitely worked.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”