0

My brother and I are making an Arduino-based incubator by watching YouTube videos and we've got in stuck. The code was taken from a video and it doesn't work and gives errors with the DHT11 sensor library installation. We've installed many times. After that it gives another error. We're trying to get in touch with its owner but failed.

Please help me correct it. Here is my code. scheme of Arduino-based incubator

#include <LiquidCrystal.h>
#include <Servo.h>
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4

const int ok = A1;
const int UP = A2;
const int DOWN = A3;

const int bulb = 3;
const int vap = 6;

const int rs = 8;
const int en = 9;
const int d4 = 10;
const int d5 = 11;
const int d6 = 12;
const int d7 = 13;

int ack = 0;
int pos = 0;
int sec = 0;
int Min = 0;
int hrs = 0;
int T_threshold = 30;
int H_threshold = 60;
int SET = 0;
int Direction = 0;
boolean T_condition = true;
boolean H_condition = true;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Servo motor;
void setup() {
  pinMode(ok, INPUT);
  pinMode(UP, INPUT);
  pinMode(DOWN, INPUT);
  pinMode(bulb, OUTPUT);
  pinMode(vap, OUTPUT);
  digitalWrite(bulb, LOW);
  digitalWrite(vap, LOW);
  digitalWrite(ok, HIGH);
  digitalWrite(UP, HIGH);
  digitalWrite(DOWN, HIGH);
  motor.attach(A4);
  motor.write(pos);
  lcd.begin(16, 2);
  Serial.begin(9600);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temperature &");
  lcd.setCursor(0, 1);
  lcd.print("Humidity ");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Controller For");
  lcd.setCursor(0, 1);
  lcd.print("Incubator");
  delay(3000);
  lcd.clear();
  Serial.println("  Temperature and Humidity Controller For Incubator");
}
void loop() {

  if (SET == 0) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Set Temperature:");
    lcd.setCursor(0, 1);
    lcd.print(T_threshold);
    lcd.print(" *C");
    while (T_condition) {
      if (digitalRead(UP) == LOW) {
        T_threshold = T_threshold + 1;
        lcd.setCursor(0, 1);
        lcd.print(T_threshold);
        lcd.print(" *C");
        delay(200);
      }
      if (digitalRead(DOWN) == LOW) {
        T_threshold = T_threshold - 1;
        lcd.setCursor(0, 1);
        lcd.print(T_threshold);
        lcd.print(" *C");
        delay(200);
      }
      if (digitalRead(ok) == LOW) {
        delay(200);
        T_condition = false;
      }
    }
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Set Humidity:");
    lcd.setCursor(0, 1);
    lcd.print(H_threshold);
    lcd.print("%");
    delay(100);
    while (H_condition) {
      if (digitalRead(UP) == LOW) {
        H_threshold = H_threshold + 1;
        lcd.setCursor(0, 1);
        lcd.print(H_threshold);
        lcd.print("%");
        delay(100);
      }
      if (digitalRead(DOWN) == LOW) {
        H_threshold = H_threshold - 1;
        lcd.setCursor(0, 1);
        lcd.print(H_threshold);
        lcd.print("%");
        delay(200);
      }
      if (digitalRead(ok) == LOW) {
        delay(100);
        H_condition = false;
      }
    }
    SET = 1;
  }
  ack = 0;
  int chk;
  chk = DHT.read(DHT11_PIN);  // READ DATA
  switch (chk) {
    case DHTLIB_OK:
      //Serial.print("OK,\t");
      break;
    case DHTLIB_ERROR_CHECKSUM:
      //Serial.print("Checksum error,\t");
      ack = 0;
      break;
    case DHTLIB_ERROR_TIMEOUT:
      //Serial.print("Time out error,\t");
      ack = 0;
      break;
    default:
      //Serial.print("Unknown error,\t");
      break;
  }
  // DISPLAT DATA
  Serial.print("DHT11, \t");
  Serial.print(DHT.temperature, 1);
  Serial.print(",\t");
  Serial.println(DHT.humidity, 1);
  delay(100);

  if (ack == 0) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp:");
    lcd.print(DHT.temperature);
    lcd.setCursor(0, 1);
    lcd.print("Humidity:");
    lcd.print(DHT.humidity);
    delay(500);
    if (DHT.temperature >= T_threshold) {
      delay(500);
      if (DHT.temperature >= T_threshold) {
        digitalWrite(bulb, LOW);
      }
    }
    if (DHT.humidity >= H_threshold) {
      delay(500);
      if (DHT.humidity >= H_threshold) {
        digitalWrite(vap, HIGH);
      }
    }
    if (DHT.temperature < T_threshold) {
      delay(500);
      if (DHT.temperature < T_threshold) {
        digitalWrite(bulb, HIGH);
      }
    }
    if (DHT.humidity < H_threshold) {
      delay(500);
      if (DHT.humidity < H_threshold) {
        digitalWrite(vap, LOW);
      }
    }
    sec = sec + 1;
    if (sec == 3) {
      sec = 0;
      Min = Min + 1;
    }
    if (Min == 3) {
      Min = 0;
      hrs = hrs + 1;
    }
    if (hrs == 3 && Min == 0 && sec == 0) {
      Serial.println("  ROTATING FORWARD  ");
      for (pos = 0; pos <= 180; pos += 1) {
        motor.write(pos);
        delay(25);
      }
    }
    if (hrs == 6 && Min == 0 && sec == 0) {
      Serial.println("  ROTATING BACKWARD  ");
      hrs = 0;
      for (pos = 180; pos >= 0; pos -= 1) {
        motor.write(pos);
        delay(25);
      }
    }
  }
  if (ack == 1) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("No Sensor data.");
    lcd.setCursor(0, 1);
    lcd.print("System Halted.");
    digitalWrite(bulb, LOW);
    digitalWrite(vap, LOW);
  }
  delay(500);
}

eror

C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:4:1: error: 'dht11' does not name a type
 dht11 DHT;
 ^~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino: In function 'void loop()':
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:125:9: error: 'DHT' was not declared in this scope
   chk = DHT.read(DHT11_PIN);  // READ DATA
         ^~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:127:10: error: 'DHTLIB_OK' was not declared in this scope
     case DHTLIB_OK:
          ^~~~~~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:130:10: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
     case DHTLIB_ERROR_CHECKSUM:
          ^~~~~~~~~~~~~~~~~~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:134:10: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
     case DHTLIB_ERROR_TIMEOUT:
          ^~~~~~~~~~~~~~~~~~~~
Multiple libraries were found for "LiquidCrystal.h"
  Used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal
  Not used: C:\Users\User\AppData\Local\Arduino15\libraries\LiquidCrystal
Multiple libraries were found for "Servo.h"
  Used: C:\Users\User\Documents\Arduino\libraries\Servo
  Not used: C:\Users\User\AppData\Local\Arduino15\libraries\Servo
exit status 1

Compilation error: 'dht11' does not name a type

info about the library I used

https://www.arduino.cc/reference/en/libraries/servo/

https://www.arduino.cc/reference/en/libraries/liquidcrystal/

https://github.com/dhrubasaha08/DHT11

AGAIN ERROR

C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:4:7: error: no matching function for call to 'DHT11::DHT11()'
 DHT11 DHT;
       ^~~
In file included from C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:3:0:
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:29:3: note: candidate: DHT11::DHT11(int)
   DHT11(int pin);
   ^~~~~
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:29:3: note:   candidate expects 1 argument, 0 provided
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:20:7: note: candidate: constexpr DHT11::DHT11(const DHT11&)
 class DHT11
       ^~~~~
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:20:7: note:   candidate expects 1 argument, 0 provided
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:20:7: note: candidate: constexpr DHT11::DHT11(DHT11&&)
c:\Users\User\Documents\Arduino\libraries\DHT11\src/DHT11.h:20:7: note:   candidate expects 1 argument, 0 provided
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino: In function 'void loop()':
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:125:13: error: 'class DHT11' has no member named 'read'; did you mean 'readByte'?
   chk = DHT.read(DHT11_PIN);  // READ DATA
             ^~~~
             readByte
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:127:10: error: 'DHTLIB_OK' was not declared in this scope
     case DHTLIB_OK:
          ^~~~~~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:130:10: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
     case DHTLIB_ERROR_CHECKSUM:
          ^~~~~~~~~~~~~~~~~~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:134:10: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
     case DHTLIB_ERROR_TIMEOUT:
          ^~~~~~~~~~~~~~~~~~~~
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:144:20: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
   Serial.print(DHT.temperature, 1);
                    ^~~~~~~~~~~
                    readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:146:22: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
   Serial.println(DHT.humidity, 1);
                      ^~~~~~~~
                      readHumidity
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:153:19: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
     lcd.print(DHT.temperature);
                   ^~~~~~~~~~~
                   readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:156:19: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
     lcd.print(DHT.humidity);
                   ^~~~~~~~
                   readHumidity
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:158:13: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
     if (DHT.temperature >= T_threshold) {
             ^~~~~~~~~~~
             readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:160:15: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
       if (DHT.temperature >= T_threshold) {
               ^~~~~~~~~~~
               readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:164:13: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
     if (DHT.humidity >= H_threshold) {
             ^~~~~~~~
             readHumidity
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:166:15: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
       if (DHT.humidity >= H_threshold) {
               ^~~~~~~~
               readHumidity
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:170:13: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
     if (DHT.temperature < T_threshold) {
             ^~~~~~~~~~~
             readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:172:15: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'?
       if (DHT.temperature < T_threshold) {
               ^~~~~~~~~~~
               readTemperature
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:176:13: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
     if (DHT.humidity < H_threshold) {
             ^~~~~~~~
             readHumidity
C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:178:15: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'?
       if (DHT.humidity < H_threshold) {
               ^~~~~~~~
               readHumidity
Multiple libraries were found for "LiquidCrystal.h"
  Used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal
  Not used: C:\Users\User\AppData\Local\Arduino15\libraries\LiquidCrystal
Multiple libraries were found for "Servo.h"
  Used: C:\Users\User\Documents\Arduino\libraries\Servo
  Not used: C:\Users\User\AppData\Local\Arduino15\libraries\Servo
exit status 1

Compilation error: no matching function for call to 'DHT11::DHT11()'

error after correction of DHT11 DHT(4);

C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino: In function 'void loop()': C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:125:13: error: 'class DHT11' has no member named 'read'; did you mean 'readByte'? chk = DHT.read(DHT11_PIN); // READ DATA ^~~~ readByte C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:127:10: error: 'DHTLIB_OK' was not declared in this scope case DHTLIB_OK: ^~~~~~~~~ C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:130:10: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope case DHTLIB_ERROR_CHECKSUM: ^~~~~~~~~~~~~~~~~~~~~ C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:134:10: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope case DHTLIB_ERROR_TIMEOUT: ^~~~~~~~~~~~~~~~~~~~ C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:144:20: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? Serial.print(DHT.temperature, 1); ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:146:22: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? Serial.println(DHT.humidity, 1); ^~~~~~~~ readHumidity C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:153:19: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? lcd.print(DHT.temperature); ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:156:19: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? lcd.print(DHT.humidity); ^~~~~~~~ readHumidity C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:158:13: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? if (DHT.temperature >= T_threshold) { ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:160:15: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? if (DHT.temperature >= T_threshold) { ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:164:13: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? if (DHT.humidity >= H_threshold) { ^~~~~~~~ readHumidity C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:166:15: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? if (DHT.humidity >= H_threshold) { ^~~~~~~~ readHumidity C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:170:13: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? if (DHT.temperature < T_threshold) { ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:172:15: error: 'class DHT11' has no member named 'temperature'; did you mean 'readTemperature'? if (DHT.temperature < T_threshold) { ^~~~~~~~~~~ readTemperature C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:176:13: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? if (DHT.humidity < H_threshold) { ^~~~~~~~ readHumidity C:\Users\User\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:178:15: error: 'class DHT11' has no member named 'humidity'; did you mean 'readHumidity'? if (DHT.humidity < H_threshold) { ^~~~~~~~ readHumidity Multiple libraries were found for "LiquidCrystal.h" Used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal Not used: C:\Users\User\AppData\Local\Arduino15\libraries\LiquidCrystal Multiple libraries were found for "Servo.h" Used: C:\Users\User\Documents\Arduino\libraries\Servo Not used: C:\Users\User\AppData\Local\Arduino15\libraries\Servo exit status 1

Compilation error: 'class DHT11' has no member named 'read'; did you mean 'readByte'?

12
  • 2
    If you are getting errors from the compiler, please include them into your question (by editing it, not in the comments). And please provide information on what library you used exactly. Also you might wanna move the definition of DHT11_PIN to above the include of that library.
    – chrisl
    Apr 2 at 8:03
  • I've edited my question please look at my info Apr 2 at 11:44
  • 1
    Ahh, now we can see the problem. Your definition of the DHT object is wrong. You used dht11 DHT;, where the type would be dht11. Though if you look at the examples of the library, the type of the object is actually DHT11 (in upper case letters). C++ is case sensitive, so dht11 and DHT11 are not the same. Change dht11 DHT; to DHT11 DHT; and this error should go away. Since this is only a spelling error, which probably won't help future readers, we often try to help with a comment and close the question afterwards, instead of keeping it.
    – chrisl
    Apr 2 at 12:00
  • bro it didn't work again it shows the same error Apr 2 at 13:15
  • 1
    It does not show the same error. Did you read the error message? Please, do so. Apr 2 at 13:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.