issue with DHT library or issue with my code?

so im making an automated system to take care3 of my old mans green house. it has all the normal stuff, light sensors, water pumps, 12v solonoids and all that jazz. the issue im having is with the DHT sensor, i downloaded the code rght from the Arduino IDE “manage library” selection and it seems to work fine on its own but, not so much if i add it with anything els. this is the code i am using…

#include <LiquidCrystal.h>

#include <DHT.h>

#define dht_dpin A1
#define LUX A0
LiquidCrystal lcd(2,3,4,5,6,7);

dht DHT;

#define light 10
#define fan 8
#define spray 11
#define motor 12
#define soil 9

int temperature, humidity, temp,Temp;
int check;
int test,test1,test2,test3;
float volt,lux,value;

byte degree[8] =
              {
                0b00011,
                0b00011,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000
              };

void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
 
  pinMode(soil, INPUT);
  pinMode(light, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(spray, OUTPUT);
  pinMode(motor, OUTPUT);
 
  lcd.createChar(1, degree);
  lcd.setCursor(0,0);
  lcd.print("Green House   ");
  lcd.setCursor(0,1);
  lcd.print("  Monitering");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("By Saddam Khan");
  lcd.setCursor(0,1);
  lcd.print("ENGINEERS GARAGE");
  delay(2000);
  lcd.clear();
}

void loop()
{
  /*-----Light Intensity------*/
 
  DHT.read11(dht_dpin);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" humidity=");
  lcd.print(humidity=DHT.humidity);
  lcd.print(" % ");
// lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("temperature=");
  lcd.print(temperature=DHT.temperature);
  lcd.write(1);
  lcd.print("C ");
  delay(2000);
  lcd.clear();
 
   value=analogRead(LUX);
   volt=(value/1023.0)*5;
   lux=((2500/volt)-500)/3.3;
   delay(10);
  
   if(lux<100)
   {
     digitalWrite(light, HIGH);
     Serial.println("AT+CMGF=1");\
     Serial.println("AT+CMGS=\"9784398922\"");
     Serial.println("LOW LIGHT ");
     Serial.println("LIGHT TURNED ON");
     Serial.print("Light Intensity: ");
     Serial.print(lux);
     Serial.println(" LUX");
     Serial.print("Temperature: ");
     Serial.print(temperature);
     Serial.println(" Degree Celsius");
     Serial.print("Humidity: ");
     Serial.print(humidity);
     Serial.println(" %");
     Serial.write(26);
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Low light ");
     lcd.print(lux);
     lcd.print(" LUX");
     lcd.setCursor(0,1);
     lcd.print("Lights turned ON");
     check=1;
     test=1;
     delay(2000);
   }
   else
   {
    if(check==1)
    {
    
     Serial.println("AT+CMGF=1");\
     Serial.println("AT+CMGS=\"9784398922\"");
     Serial.print("LIGHT TURNED OFF");
     Serial.print("Light Intensity: ");
     Serial.print(lux);
     Serial.println(" LUX");
     Serial.print("Temperature: ");
     Serial.print(temperature);
     Serial.println(" degree Celsius");
     Serial.print("Humidity: ");
     Serial.print(humidity);
     Serial.println(" %");
     Serial.write(26);
     check=0;
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("light int: ");
     lcd.print(lux);
     lcd.print(" LUX");
     lcd.setCursor(0,1);
     lcd.print("Lights turned OFF");
    }
     digitalWrite(light, LOW);
     test=0;
     delay(2000);
   }
  
 
 
  if(temperature > 40)
  {
    digitalWrite(fan, HIGH);
     Serial.println("AT+CMGF=1");\
     Serial.println("AT+CMGS=\"9784398922\"");
     Serial.println("TEMPERATURE INCREASES FROM CRITICAL LEVEL");
     Serial.println("FAN TURNED ON");
     Serial.print("Light Intensity: ");
     Serial.print(lux);
     Serial.println(" LUX");
     Serial.print("Temperature: ");
     Serial.print(temperature);
     Serial.println(" degree Celsius");
     Serial.print("Humidity: ");
     Serial.print(humidity);
     Serial.println(" %");
}

i am having problems on line 6 where it states “dht DHT;” the error i am getting is as follows…

Arduino: 1.8.1 (Windows 10), Board: “Arduino/Genuino Uno”

sketch_mar27c:9: error: ‘dht’ does not name a type

dht DHT;

^

C:\Users\cenright\Documents\Arduino\sketch_mar27c\sketch_mar27c.ino: In function ‘void loop()’:

sketch_mar27c:64: error: expected unqualified-id before ‘.’ token

DHT.read11(dht_dpin);

^

sketch_mar27c:68: error: expected primary-expression before ‘.’ token

lcd.print(humidity=DHT.humidity);

^

sketch_mar27c:73: error: expected primary-expression before ‘.’ token

lcd.print(temperature=DHT.temperature);

^

exit status 1
‘dht’ does not name a type

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

any and all help is much appreciated!.

it seems to work fine on its own

Post an example of "it working fine on its own".

There are several DHT libraries. Some have a class named dht. Others have a class named DHT.

Which one does yours have?

PaulS:
Post an example of “it working fine on its own”.

There are several DHT libraries. Some have a class named dht. Others have a class named DHT.

Which one does yours have?

here is the library that works fine on its own.

 #include <DHT.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

here is the library that works fine on its own.

That is not "working fine". You haven't created an instance of the class defined in the DHT.h file, nor have you tried to do anything with that instance.

PaulS: That is not "working fine". You haven't created an instance of the class defined in the DHT.h file, nor have you tried to do anything with that instance.

oh no no no. that isnt a sketch i used i just opened up a new page and added the library so you could see which one i am using. im aware what i just posted in my last reply is as good as blank but my purpose was to simply show you what library i am using.

my purpose was to simply show you what library i am using.

Your first post showed that you were using a library with a header file named DHT.h. Your last post shows the same thing.

What you have not shown is the contents of the DHT.h file.

im not sure how to show you what is in the DHT file. when i open it in my documents section outside of the IDE i see a CPP file and an H file. is that the info you are looking for? i appreciate the help by the way. thank you.

is that the info you are looking for?

Yes. Open the .h file in a text editor. Copy the contents, and paste them here.

PaulS: Yes. Open the .h file in a text editor. Copy the contents, and paste them here.

here you go my good man.

/* DHT library

MIT license written by Adafruit Industries */

ifndef DHT_H

define DHT_H

if ARDUINO >= 100

include "Arduino.h"

else

include "WProgram.h"

endif

// Uncomment to enable printing out nice debug messages. //#define DHT_DEBUG

// Define where debug output will be printed.

define DEBUG_PRINTER Serial

// Setup debug printing macros.

ifdef DHT_DEBUG

define DEBUG_PRINT(...) { DEBUG_PRINTER.print(VA_ARGS); }

define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(VA_ARGS); }

else

define DEBUG_PRINT(...) {}

define DEBUG_PRINTLN(...) {}

endif

// Define types of sensors.

define DHT11 11

define DHT22 22

define DHT21 21

define AM2301 21

class DHT { public: DHT(uint8_t pin, uint8_t type, uint8_t count=6); void begin(void); float readTemperature(bool S=false); float convertCtoF(float); float convertFtoC(float); float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); float readHumidity(void); boolean read(void);

private: uint8_t data[6]; uint8_t _pin, _type; uint32_t _lastreadtime; bool _firstreading; bool _lastresult;

uint32_t expectPulse(bool level);

};

endif

class DHT {

So, there is a class called DHT.

dht DHT;

That is NOT how to create an instance of the class called DHT. The type (DHT) goes before the instance name.

ok I'm not quite understanding what your saying. I don't have all the phrases and Arduino lingo down yet. what do you recommend I do to resolve this?

what do you recommend I do to resolve this?

How do you create an instance of the Servo class?

   Servo myServo;

or

   myServo Servo?

The name of the class goes first. The name of the instance does NOT need to be the same as the name of the class but with a different case.

Change your instance name to myThermometer, and the order of the names (class and instance) will be a lot clearer.

hold on im lost. how did we get to talking about servos? im trying to get a DHT11 humidity/temp. sensor working? not a servo motor.

so would i write ......

DHT myServo;?

or

myServo DHT;?

or do you recomend i download a differant DHT library? and if so which one?

Hi,
You need to define which sensor your using. try as below typed.

#include <DHT.h>

//Uncomment to use this one
#define DHTTYPE DHT22 // sensor type DHT11 DHT22
#define DHTPIN A0 // input pin
DHT DHT(DHTPIN,DHTTYPE);

void setup(){

DHT.begin();

try as below typed.

No, don't. Only id10ts name an instance of the class the same as the class.

OP:

     DHT myThing;

Then, in the rest of your code, whenever you want data from your thing, use myThing., not DHT..