'DHT_OK' was not declared in this scope

My code:
#include <SFE_BMP180.h>
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

#define ALTITUDE 18.0 // Altitude of Karwan bazar in meters
DHT dht(DHTPIN, DHT11);

void setup()
{
Serial.begin(9600);
Serial.println("REBOOT");
lcd.begin(20, 4);

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// something went wrong, this is usually a connection problem,

Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever.

}
}

void loop()
{
char status;
double T,P,p0,a;

Serial.println();

status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("T: ");
Serial.print(T,2);
lcd.setCursor(0, 0);
lcd.print("T=");
lcd.setCursor(2, 0);
lcd.print(T,2);
lcd.setCursor(6, 0);
lcd.print(" deg C ");
Serial.print(" deg C, ");
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print("P: ");
Serial.print(P/10,2);
Serial.println(" kPa");
lcd.setCursor(0, 1);
lcd.print("P= ");
lcd.setCursor(2, 1);
lcd.print(P/10,2);
lcd.setCursor(9, 1);
lcd.print("kPa");
p0 = pressure.sealevel(P,ALTITUDE);
Serial.print("P(Sea-level): ");
Serial.print(p0/10,2);
Serial.println(" kPa");
lcd.setCursor(0, 2);
lcd.print("P0= ");
lcd.setCursor(3, 2);
lcd.print(p0/10,2);
lcd.setCursor(9, 2);
lcd.print("kPa");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");

int sensorValue = analogRead(A0);
float outvoltage = sensorValue * (5.0 / 1023.0);
int Level = 6*outvoltage;//The level of wind speed is proportional to the output voltage.
Serial.print("V= ");
Serial.print(Level);
Serial.println(" m/s");
Serial.println();
lcd.setCursor(0, 3);
lcd.print("V= ");
lcd.setCursor(2, 3);
lcd.print(Level);
lcd.setCursor(4,3);
lcd.print("m/s");
switch(dht.read())
{
case DHT_OK:
lcd.setCursor(9,3);
lcd.print("Hum=");
lcd.print(dht.humidity);
lcd.print("%");
break;
case DHT_ERR_CHECK:
lcd.clear();
lcd.setCursor(9,3);
lcd.print("Error");
break;
case DHT_ERR_TIMEOUT:
lcd.clear();
lcd.setCursor(9,3);
lcd.print("Error");
break;
}

delay(5000); // Pause for 5 seconds.
}

this error show what is the problem?

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

D:\technology\Final Year project\Weather Station\Weather_station\Weather_station.ino: In function 'void loop()':

Weather_station:142:10: error: 'DHT_OK' was not declared in this scope

 case DHT_OK:

      ^~~~~~

D:\technology\Final Year project\Weather Station\Weather_station\Weather_station.ino:142:10: note: suggested alternative: 'DHT_H'

 case DHT_OK:

      ^~~~~~

      DHT_H

Weather_station:147:21: error: 'class DHT' has no member named 'humidity'; did you mean 'readHumidity'?

   lcd.print(dht.humidity);

                 ^~~~~~~~

                 readHumidity

Weather_station:150:10: error: 'DHT_ERR_CHECK' was not declared in this scope

 case DHT_ERR_CHECK:

      ^~~~~~~~~~~~~

Weather_station:156:10: error: 'DHT_ERR_TIMEOUT' was not declared in this scope

 case DHT_ERR_TIMEOUT:

      ^~~~~~~~~~~~~~~

Multiple libraries were found for "DHT.h"

Used: C:\Users\Akash\Documents\Arduino\libraries\DHT_sensor_library

Not used: C:\Users\Akash\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor-master

exit status 1

'DHT_OK' was not declared in this scope

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

Hi,

It sounds like you have multiple libraries for dht sensors installed. The IDE knows this but may be trying to use the wrong one for your sketch. Use the library manager to search for "dht" with type set to "Installed". I think you will see more than one library listed. Try removing all but one of them. Before you do that, make a note of the version numbers and authors of those libraries so you can find them and re-install later if needed.

2 Likes

There are new error coming again

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

D:\technology\Weather Station\Temperature_and_humidity_meter\Temperature_and_humidity_meter.ino: In function 'void loop()':

Temperature_and_humidity_meter:17:19: error: 'boolean DHT::read()' is private within this context

switch(dht.read())

               ^

In file included from D:\Final Year project\Weather Station\Temperature_and_humidity_meter\Temperature_and_humidity_meter.ino:2:0:

C:\Users\Akdhi\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor/DHT.h:57:11: note: declared private here

boolean read(void);

       ^~~~

Temperature_and_humidity_meter:19:10: error: 'DHT_OK' was not declared in this scope

 case DHT_OK:

      ^~~~~~

D:\technology\Weather Station\Temperature_and_humidity_meter\Temperature_and_humidity_meter.ino:19:10: note: suggested alternative: 'DHT_H'

 case DHT_OK:

      ^~~~~~

      DHT_H

Temperature_and_humidity_meter:24:21: error: 'class DHT' has no member named 'humidity'; did you mean 'readHumidity'?

   lcd.print(dht.humidity);

                 ^~~~~~~~

                 readHumidity

Temperature_and_humidity_meter:28:21: error: 'class DHT' has no member named 'temperature'; did you mean 'readTemperature'?

   lcd.print(dht.temperature);

                 ^~~~~~~~~~~

                 readTemperature

Temperature_and_humidity_meter:32:10: error: 'DHT_ERR_CHECK' was not declared in this scope

 case DHT_ERR_CHECK:

      ^~~~~~~~~~~~~

Temperature_and_humidity_meter:40:10: error: 'DHT_ERR_TIMEOUT' was not declared in this scope

 case DHT_ERR_TIMEOUT:

      ^~~~~~~~~~~~~~~

exit status 1

'boolean DHT::read()' is private within this context

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

Did you follow my advice? What did you see? What did you change? We can't help you without more information.

Yes, I am following your advice,
1st I delete multiple libraries, just install only "DHT sensor libraries"

then a new error coming...

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

D:\technology\Weather Station\Temperature_and_humidity_meter\Temperature_and_humidity_meter.ino: In function 'void loop()':

Temperature_and_humidity_meter:19:10: error: 'DHT_OK' was not declared in this scope

 case DHT_OK:

      ^~~~~~

D:\technology\Weather Station\Temperature_and_humidity_meter\Temperature_and_humidity_meter.ino:19:10: note: suggested alternative: 'DHT_H'

 case DHT_OK:

      ^~~~~~

      DHT_H

Temperature_and_humidity_meter:24:21: error: 'class DHT' has no member named 'humidity'; did you mean 'readHumidity'?

   lcd.print(dht.humidity);

                 ^~~~~~~~

                 readHumidity

Temperature_and_humidity_meter:28:21: error: 'class DHT' has no member named 'temperature'; did you mean 'readTemperature'?

   lcd.print(dht.temperature);

                 ^~~~~~~~~~~

                 readTemperature

Temperature_and_humidity_meter:32:10: error: 'DHT_ERR_CHECK' was not declared in this scope

 case DHT_ERR_CHECK:

      ^~~~~~~~~~~~~

Temperature_and_humidity_meter:40:10: error: 'DHT_ERR_TIMEOUT' was not declared in this scope

 case DHT_ERR_TIMEOUT:

      ^~~~~~~~~~~~~~~

exit status 1

'DHT_OK' was not declared in this scope

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

Look inside the library you have and see what methods it supports? A library's .h file is the first place to go investigating!