DHT11 sensor error

Hello, iam using this code..
when i compile it i got this error, any help please ?

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

//------------------Program Developed by R.GIRISH-------------------//
#include <LiquidCrystal.h>
#include <Servo.h>


#define DHT11 A0
const int ok = A1;
const int UP = A2;
const int DOWN = A3;
const int bulb = A4;
const int vap = A5;
const int rs = 12;
const int en = 11;
const int d4 = 5;
const int d5 = 4;
const int d6 = 3;
const int d7 = 2;
int ack = 0;
int pos = 0;
int sec = 0;
int Min = 0;
int hrs = 0;
int T_threshold = 25;
int H_threshold = 35;
int SET = 0;
int Direction = 0;
boolean T_condition = true;
boolean H_condition = true;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Servo motor;
dht DHT;
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(7);
motor.write(pos);
lcd.begin(16, 2);
Serial.begin(9600);
lcd.setCursor(5, 0);
lcd.print("Digital");
lcd.setCursor(4, 1);
lcd.print("Incubator");
delay(1500);
}
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 = DHT.read11(DHT11);
switch (chk)
{
case DHTLIB_ERROR_CONNECT:
ack = 1;
break;
}
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);
if (DHT.temperature >= T_threshold)
{
delay(3000);
if (DHT.temperature >= T_threshold)
{
digitalWrite(bulb, LOW);
}
}
if (DHT.humidity >= H_threshold)
{
delay(3000);
if (DHT.humidity >= H_threshold)
{
digitalWrite(vap, LOW);
}
}
if (DHT.temperature < T_threshold)
{
delay(3000);
if (DHT.temperature < T_threshold)
{
digitalWrite(bulb, HIGH);
}
}
if (DHT.humidity < H_threshold)
{
delay(3000);
if (DHT.humidity < H_threshold)
{
digitalWrite(vap, HIGH);
}
}
sec = sec + 1;
if (sec == 60)
{
sec = 0;
Min = Min + 1;
}
if (Min == 60)
{
Min = 0;
hrs = hrs + 1;
}
if (hrs == 8 && Min == 0 && sec == 0)
{
for (pos = 0; pos <= 180; pos += 1)
{
motor.write(pos);
delay(25);
}
}
if (hrs == 16 && Min == 0 && sec == 0)
{
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(1000);
}
//------------------Program Developed by R.GIRISH-------------------//

36:32:1: error: 'dht' does not name a type
dht DHT;
^~~
C:\Users\ousse\Documents\Arduino\36\36.ino: In function 'void loop()':
36:123:14: error: expected primary-expression before '.' token
int chk = DHT.read11(DHT11);
^
36:126:6: error: 'DHTLIB_ERROR_CONNECT' was not declared in this scope
case DHTLIB_ERROR_CONNECT:
^~~~~~~~~~~~~~~~~~~~
36:135:14: error: expected primary-expression before '.' token
lcd.print(DHT.temperature);
^
36:138:14: error: expected primary-expression before '.' token
lcd.print(DHT.humidity);
^
36:139:8: error: expected primary-expression before '.' token
if (DHT.temperature >= T_threshold)
^
36:142:8: error: expected primary-expression before '.' token
if (DHT.temperature >= T_threshold)
^
36:147:8: error: expected primary-expression before '.' token
if (DHT.humidity >= H_threshold)
^
36:150:8: error: expected primary-expression before '.' token
if (DHT.humidity >= H_threshold)
^
36:155:8: error: expected primary-expression before '.' token
if (DHT.temperature < T_threshold)
^
36:158:8: error: expected primary-expression before '.' token
if (DHT.temperature < T_threshold)
^
36:163:8: error: expected primary-expression before '.' token
if (DHT.humidity < H_threshold)
^
36:166:8: error: expected primary-expression before '.' token
if (DHT.humidity < H_threshold)
^
exit status 1
'dht' does not name a type

Greetings,

Change this to this

DHT dht; 

After that change all DHT's into dht.

And the constructor needs 2 parameters, the pin number and the DHT type. Have you looked at the DHT library examples ?

still having the same problem

#define DHT11 A0
DHT dht;

i just did it

Post your updated code with parameters in the constructor


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

#define DHT11 A0
const int ok = A1;
const int UP = A2;
const int DOWN = A3;
const int bulb = A4;
const int vap = A5;
const int rs = 12;
const int en = 11;
const int d4 = 5;
const int d5 = 4;
const int d6 = 3;
const int d7 = 2;
int ack = 0;
int pos = 0;
int sec = 0;
int Min = 0;
int hrs = 0;
int T_threshold = 25;
int H_threshold = 35;
int SET = 0;
int Direction = 0;
boolean T_condition = true;
boolean H_condition = true;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Servo motor;
DHT dht;
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(7);
motor.write(pos);
lcd.begin(16, 2);
Serial.begin(9600);
lcd.setCursor(5, 0);
lcd.print("Digital");
lcd.setCursor(4, 1);
lcd.print("Incubator");
delay(1500);
}
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 = DHT.read11(DHT11);
switch (chk)
{
case DHTLIB_ERROR_CONNECT:
ack = 1;
break;
}
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);
if (dht.temperature >= T_threshold)
{
delay(3000);
if (dht.temperature >= T_threshold)
{
digitalWrite(bulb, LOW);
}
}
if (dht.humidity >= H_threshold)
{
delay(3000);
if (dht.humidity >= H_threshold)
{
digitalWrite(vap, LOW);
}
}
if (dht.temperature < T_threshold)
{
delay(3000);
if (dht.temperature < T_threshold)
{
digitalWrite(bulb, HIGH);
}
}
if (dht.humidity < H_threshold)
{
delay(3000);
if (dht.humidity < H_threshold)
{
digitalWrite(vap, HIGH);
}
}
sec = sec + 1;
if (sec == 60)
{
sec = 0;
Min = Min + 1;
}
if (Min == 60)
{
Min = 0;
hrs = hrs + 1;
}
if (hrs == 8 && Min == 0 && sec == 0)
{
for (pos = 0; pos <= 180; pos += 1)
{
motor.write(pos);
delay(25);
}
}
if (hrs == 16 && Min == 0 && sec == 0)
{
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(1000);
}

DHT dht;

Still no parameters in the constructor

#define DHTTYPE DHT11
DHT dht2 = DHT(A0,DHTTYPE);

is this correct ?

No

It should be

#define DHTTYPE DHT11
DHT dht(A0, DHTTYPE);

You are declaring an object named dht which you use throughout the sketch when referring to the DHT11 sensor on pin A0

now i got an other error in this expression

if (DHT.humidity < H_threshold)

Arduino : 1.8.16 (Windows 10), Carte : "Arduino Uno"

C:\Users\ousse\Documents\Arduino\36\36.ino: In function 'void loop()':

36:121:14: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11);

          ^

36:124:6: error: 'DHTLIB_ERROR_CONNECT' was not declared in this scope

case DHTLIB_ERROR_CONNECT:

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

36:133:14: error: expected primary-expression before '.' token

lcd.print(DHT.temperature);

          ^

36:136:14: error: expected primary-expression before '.' token

lcd.print(DHT.humidity);

          ^

36:137:8: error: expected primary-expression before '.' token

if (DHT.temperature >= T_threshold)

    ^

36:140:8: error: expected primary-expression before '.' token

if (DHT.temperature >= T_threshold)

    ^

36:145:8: error: expected primary-expression before '.' token

if (DHT.humidity >= H_threshold)

    ^

36:148:8: error: expected primary-expression before '.' token

if (DHT.humidity >= H_threshold)

    ^

36:153:8: error: expected primary-expression before '.' token

if (DHT.temperature < T_threshold)

    ^

36:156:8: error: expected primary-expression before '.' token

if (DHT.temperature < T_threshold)

    ^

36:161:8: error: expected primary-expression before '.' token

if (DHT.humidity < H_threshold)

    ^

36:164:8: error: expected primary-expression before '.' token

if (DHT.humidity < H_threshold)

    ^

exit status 1

expected primary-expression before '.' token

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

Read what I wrote

You are trying to use an object named DHT rather than dht

Make the required changes and post the revised sketch if you still have problems

Sorry, i still newbie
So i should replace all DHT with dht ?

Basically yes, but not in the name of the library file (DHT.h) or in the constructor

I really would urge you to look at the examples that came with the library

ok i will do this now

Note particularly how the DHT object is declared, the parameters used and how the name of the DHT object is used in the code

Hello, at first make sure that you've installed the dht.h library .

Since you're new, I think this tutorial will also help you to understand more.

I even tryed the same code and library in this tutorial and i am still having the same problems, i 've read the full tutorial, but still didn't understand why i am getting these errors..
please guide me guys, i am tyring to have a correct code since i bought all composants and wire it togheter to build an automatic incubator..

Are we supposed to understand the schematic of your project from that picture of a rats nest ?

I have seen some bad pictures of projects on the forum but this takes the biscuit

my problem is with coding, i just made the circuit without any error
i just included this photo to show u that all is ready, only the code didn't work for me and i need help..