exit status 1 Error compiling for board Arduino/Genuino Uno DHT 11

Hi All

I am using this code for temperature reading :

#include <DHT.h>
#include <DHT_U.h>



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

}

void loop() {
 // put your main code here, to run repeatedly:
 int chk = DHT.read11(DHT11_PIN);
 Serial.print("Temperature = ");
 Serial.println(DHT.temperature);
 Serial.print("Humidity = ");
 Serial.println(DHT.humidity);
 delay(1000);
}

and I have the DHT master library installed , also several others but Arduino used this one.

but still I get the error of compiliing, how could I troubleshoot ?

exit status 1 Error compiling for board Arduino/Genuino Uno

When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages”. Click that button. Paste the error in a message here using code tags (</> button on the forum toolbar).

“Exit status 1” is just a generic error that means something went wrong. There are an infinite number of things that could cause that error. You need to scroll up the black console window at the bottom of the Arduino IDE window to see the specific error message that will tell you what’s wrong.

Thank you very much. That's true, it was the Adafruit.h file that does not exist in DHT master lib , so you should download the Adafruit library and copy and paste the .h file manually from Adafuit library to DHT library, just installing the Adafruit will not work.

now I have a new error :

Arduino: 1.8.8 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Farzadtb\Documents\Arduino\Projects\Temperature-Humidity\Temperature-Humidity.ino: In function 'void loop()':

Temperature-Humidity:13:16: error: expected primary-expression before '.' token

  int chk = DHT.read11(DHT11_PIN);

               ^

Temperature-Humidity:13:24: error: 'DHT11_PIN' was not declared in this scope

  int chk = DHT.read11(DHT11_PIN);

                       ^

Temperature-Humidity:15:21: error: expected primary-expression before '.' token

  Serial.println(DHT.temperature);

                    ^

Temperature-Humidity:17:21: error: expected primary-expression before '.' token

  Serial.println(DHT.humidity);

                    ^

Multiple libraries were found for "DHT.h"
Used: C:\Users\Farzadtb\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\Farzadtb\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
exit status 1
expected primary-expression before '.' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Ok I changed the code to this one that sounds to be more complete, but still the same error :

The Code :

#include "DHT.h"
#define dht_apin A0 // Analog Pin sensor is connected to
 
dht DHT;
 
void setup(){
 
  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor
 
}//end "setup()"
 
void loop(){
  //Start of Program 
 
    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop()

The error :

Arduino: 1.8.8 (Windows 7), Board: "Arduino/Genuino Uno"

Temperature-Humidity:4:1: error: 'dht' does not name a type

dht DHT;

^

C:\Users\Farzadtb\Documents\Arduino\Projects\Temperature-Humidity\Temperature-Humidity.ino: In function 'void loop()':

Temperature-Humidity:18:8: error: expected unqualified-id before '.' token

    DHT.read11(dht_apin);

       ^

Temperature-Humidity:21:21: error: expected primary-expression before '.' token

    Serial.print(DHT.humidity);

                    ^

Temperature-Humidity:24:21: error: expected primary-expression before '.' token

    Serial.print(DHT.temperature); 

                    ^

Multiple libraries were found for "DHT.h"
Used: C:\Users\Farzadtb\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\Farzadtb\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
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.

pert:
When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages”. Click that button. Paste the error in a message here using code tags (</> button on the forum toolbar).

“Exit status 1” is just a generic error that means something went wrong. There are an infinite number of things that could cause that error. You need to scroll up the black console window at the bottom of the Arduino IDE window to see the specific error message that will tell you what’s wrong.

I put the whole error, Is it clarified with this message or I still need more information ?

One thing I am afraid to be the problem is the case sensitiveness in Arduino , since in some tutorials I see
Include dht while my library has DHT, so everything might get reverse

I think you're getting confused about how to use the library.

First you have to instantiate a DHT object with a line something like

DHT mySensor(DHTPIN, DHTTYPE);

This gives you a DHT object named mySensor.

then you start it up with something like

mySensor.begin();

and then you can read it with mySensor.humidity or mySensor.temperature or something similar.

The case sensitivity confusion you refer to is because the example code names the object dht, of type DHT. Yes, you're right, it's confusing.

The exact format of these commands needs to be right based on the library you're using in your sketch. A good way to discover the exact format is to read the example code that came with the sensor.

GypsumFantastic:
I think you're getting confused about how to use the library.

First you have to instantiate a DHT object with a line something like

DHT mySensor(DHTPIN, DHTTYPE);

This gives you a DHT object named mySensor.

then you start it up with something like

mySensor.begin();

and then you can read it with mySensor.humidity or mySensor.temperature or something similar.

The case sensitivity confusion you refer to is because the example code names the object dht, of type DHT. Yes, you're right, it's confusing.

The exact format of these commands needs to be right based on the library you're using in your sketch. A good way to discover the exact format is to read the example code that came with the sensor.

Thank you so much ! shall you please help me a bit more, it's still unclear for me

Farzadtb:
Thank you so much ! shall you please help me a bit more, it's still unclear for me

Start by examining the example sketches from the DHT library.

Farzadtb:
it was the Adafruit.h file that does not exist in DHT master lib , so you should download the Adafruit library and copy and paste the .h file manually from Adafuit library to DHT library, just installing the Adafruit will not work.

That's almost certainly incorrect. I can't imagine any possible circumstances where you sould need to copy and paste a .h file from one library to another, rather than just installing that library.

Post a link to where you got the DHT library from. Please use the chain links icon on the forum toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

pert:
That's almost certainly incorrect. I can't imagine any possible circumstances where you sould need to copy and paste a .h file from one library to another, rather than just installing that library.

Post a link to where you got the DHT library from. Please use the chain links icon on the forum toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Thank you

One is linked Here

http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

and the other

Farzadtb:
One is linked Here


and the other

Which one are you using? That’s the one you need to concentrate on.

This is the list of DHT libraries I installed

DHT_sensor_library_for_ESPx

DHT-sensor-library-master

Grove_Temperature_And_Humidity_Sensor

SimpleDHT

TroykaDHT

I am using

DHT-sensor-library-master

Great. And what do the example sketches do to instantiate the object and get it started?

Farzadtb:
One is linked Here

http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

That one is not being used because its header filename is dht.h and your #include directive is for DHT.h.

Farzadtb:
and the other

GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sen

This is the one being used. There is absolutely nothing about a "Adafruit.h" in this library. Maybe you meant "Adafruit_Sensor.h"? From the readme:

This library also includes an optional class for the DHT humidity and temperature sensor which is designed to work with the Adafruit unified sensor library.

You must have the following Arduino libraries installed to use this class:

You only need to do a standard installation of that library. Adafruit would never require you to do something screwy like copy and paste a header file into their library just so you can use it.

Study the example sketches under File > Examples > DHT sensor library in the Arduino IDE to learn how to use the library. Adafruit also provides a tutorial:

Farzadtb:
This is the list of DHT libraries I installed

DHT_sensor_library_for_ESPx

DHT-sensor-library-master

Grove_Temperature_And_Humidity_Sensor

SimpleDHT

TroykaDHT





I am using 

DHT-sensor-library-master

The shotgun installation method is a very bad idea. Do some research to determine which library seems the best suited to your project and then stick with that one library. Installing a ton of different random libraries is only going to cause you a lot of confusion and frustration.

GypsumFantastic:
Great. And what do the example sketches do to instantiate the object and get it started?

It exactly did that parameter definition, DHT dht(DHTPIN, DHTTYPE);

Thank you very much, yet I have reading error from sensor, I mean it compiles but does not read data from sensor

Is there also a dht.begin() command in the example sketch? In setup()?

Did you put one in your sketch?

Dear Shannon! Thank you very much for your comprehensive answer, So I will remove the other liraries , and hope it will work fine

True: shotgun installation is a good new term, well I had to do this , cause I had a short time to learn it

Fantastic : This is the code I am using now , and has reading error from sensor:

Yes it has the begin in the example code, but still it fails to read from the sensor

// 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.
DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // 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!");
    return;
  }

  // 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(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

Are you using a DHT22? Or a DHT11?

I believe DHT 11 , how can I check ?

I uncommented the DHT11 and commented the other, still the same error

I think now it resolved, just the wrong digital pin ! thank you very much for your help