I am getting a error (dht does not name a type)

Hello

i am getting a error (dht does not name a type) I downloaded the library dht and adafruit unified sensor and still dont work

board arduino mega
dht.11 sensor with 3 pins

C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:28:1: error: 'dht' does not name a type
 dht DHT;
 ^~~
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino: In function 'void loop()':
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:64:18: error: expected primary-expression before '.' token
     int chk = DHT.read11(DHT11_PIN);
                  ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:66:23: error: expected primary-expression before '.' token
     Serial.println(DHT.temperature);
                       ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:67:15: error: expected primary-expression before '.' token
     temp = DHT.temperature;
               ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:69:23: error: expected primary-expression before '.' token
     Serial.println(DHT.humidity);
                       ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:70:14: error: expected primary-expression before '.' token
     hum = DHT.humidity;
              ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:169:18: error: expected primary-expression before '.' token
     int chk = DHT.read11(DHT11_PIN);
                  ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:171:23: error: expected primary-expression before '.' token
     Serial.println(DHT.temperature);
                       ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:172:15: error: expected primary-expression before '.' token
     temp = DHT.temperature;
               ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:174:23: error: expected primary-expression before '.' token
     Serial.println(DHT.humidity);
                       ^
C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:175:14: error: expected primary-expression before '.' token
     hum = DHT.humidity;
              ^

exit status 1

Compilation error: 'dht' does not name a type
#include <Servo.h>
#include <DHT.h>
#include <SD.h>
#include <SPI.h>

 #include <Adafruit_Sensor.h>
#define DHT11_PIN 7

#define in1 3  //L298n Motor Driver pins.
#define in2 10
#define in3 4
#define in4 5
#define LED 13
int command;      //Int to store app command state.
int Speed = 204;  // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0;  //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1;  //1 for the electronic braking system, 0 for normal.

const int TrigPin = 8;
const int EchoPin = 6;
float cm;
float ft;
int temp, hum;
dht DHT;
File sdcard_file;
int CS_pin = 53;
Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.

  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(LED, OUTPUT);  //Set the LED pin.
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  if (SD.begin()) {
    Serial.println("SD card is ready to use.");
  } else {
    Serial.println("SD card initialization failed");
    return;
  }
  sdcard_file = SD.open("data.txt", FILE_WRITE);
  if (sdcard_file) {
    sdcard_file.print("Temperature ");
    sdcard_file.print("      ");
    sdcard_file.print("Humidity ");
    sdcard_file.println("      ");
    sdcard_file.close();
  } else {
    Serial.println("error opening data.txt");
  }
}
void loop() {
  for (pos = 0; pos <= 180; pos += 1) {  // goes from 0 degrees to 180 degrees
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    temp = DHT.temperature;
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    hum = DHT.humidity;
    digitalWrite(TrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(TrigPin, LOW);
    cm = pulseIn(EchoPin, HIGH) / 58.0;  //The echo time is converted into cm
    cm = (int(cm * 100.0)) / 100.0;      //Keep two decimal places
    Serial.print("Distance\t=\t");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();

    if (Serial.available() > 0) {
      command = Serial.read();
      Stop();  //Initialize with motors stoped.
      switch (command) {
        case 'F':
          forward();
          break;
        case 'B':
          back();
          break;
        case 'L':
          left();
          break;
        case 'R':
          right();
          break;
        case 'G':
          forwardleft();
          break;
        case 'I':
          forwardright();
          break;
        case 'H':
          backleft();
          break;
        case 'J':
          backright();
          break;
        case '0':
          Speed = 100;
          break;
        case '1':
          Speed = 140;
          break;
        case '2':
          Speed = 153;
          break;
        case '3':
          Speed = 165;
          break;
        case '4':
          Speed = 178;
          break;
        case '5':
          Speed = 191;
          break;
        case '6':
          Speed = 204;
          break;
        case '7':
          Speed = 216;
          break;
        case '8':
          Speed = 229;
          break;
        case '9':
          Speed = 242;
          break;
        case 'q':
          Speed = 255;
          break;
      }
      Speedsec = Turnradius;
      if (brkonoff == 1 && cm >= 10) {
        brakeOn();
      } else {
        brakeOff();
      }
    }
    if (cm < 10) {
      Stop();
      sdcard_file = SD.open("data.txt", FILE_WRITE);
      if (sdcard_file) {
        sdcard_file.print(temp);
        sdcard_file.print("     ");
        sdcard_file.print(hum);
        sdcard_file.println("     ");
        sdcard_file.close();
      } else {
        Serial.println("error opening data.txt");
      }
    }
    myservo.write(pos);
    delay(15);
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    temp = DHT.temperature;
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    hum = DHT.humidity;
    digitalWrite(TrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(TrigPin, LOW);
    cm = pulseIn(EchoPin, HIGH) / 58.0;  //The echo time is converted into cm
    cm = (int(cm * 100.0)) / 100.0;      //Keep two decimal places
    Serial.print("Distance\t=\t");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();

    if (Serial.available() > 0) {
      command = Serial.read();
      Stop();  //Initialize with motors stoped.
      switch (command) {
        case 'F':
          forward();
          break;
        case 'B':
          back();
          break;
        case 'L':
          left();
          break;
        case 'R':
          right();
          break;
        case 'G':
          forwardleft();
          break;
        case 'I':
          forwardright();
          break;
        case 'H':
          backleft();
          break;
        case 'J':
          backright();
          break;
        case '0':
          Speed = 100;
          break;
        case '1':
          Speed = 140;
          break;
        case '2':
          Speed = 153;
          break;
        case '3':
          Speed = 165;
          break;
        case '4':
          Speed = 178;
          break;
        case '5':
          Speed = 191;
          break;
        case '6':
          Speed = 204;
          break;
        case '7':
          Speed = 216;
          break;
        case '8':
          Speed = 229;
          break;
        case '9':
          Speed = 242;
          break;
        case 'q':
          Speed = 255;
          break;
      }
      Speedsec = Turnradius;
      if (brkonoff == 1 && cm >= 10) {
        brakeOn();
      } else {
        brakeOff();
      }
    }
    if (cm < 10) {
      Stop();
      sdcard_file = SD.open("data.txt", FILE_WRITE);
      if (sdcard_file) {
        sdcard_file.print(temp);
        sdcard_file.print("     ");
        sdcard_file.print(hum);
        sdcard_file.println("     ");
        sdcard_file.close();
      } else {
        Serial.println("error opening data.txt");
      }
    }
    if (temp == 27)
      back();

    myservo.write(pos);
    delay(15);
  }
}
void forward() {
  analogWrite(in1, Speed);
  analogWrite(in3, Speed);
}
void back() {
  analogWrite(in2, Speed);
  analogWrite(in4, Speed);
}

void left() {
  analogWrite(in3, Speed);
  analogWrite(in2, Speed);
}
void right() {
  analogWrite(in4, Speed);
  analogWrite(in1, Speed);
}
void forwardleft() {
  analogWrite(in1, Speedsec);
  analogWrite(in3, Speed);
}
void forwardright() {
  analogWrite(in1, Speed);
  analogWrite(in3, Speedsec);
}
void backright() {
  analogWrite(in2, Speed);
  analogWrite(in4, Speedsec);
}
void backleft() {
  analogWrite(in2, Speedsec);
  analogWrite(in4, Speed);
}
void Stop() {
  analogWrite(in1, 0);
  analogWrite(in2, 0);
  analogWrite(in3, 0);
  analogWrite(in4, 0);
}
void brakeOn() {  //Here's the future use: an electronic braking system!
                  // read the pushbutton input pin:
  buttonState = command;
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == 'S') {
      if (lastButtonState != buttonState) {
        digitalWrite(in1, HIGH);
        digitalWrite(in2, HIGH);
        digitalWrite(in3, HIGH);
        digitalWrite(in4, HIGH);
        delay(brakeTime);
        Stop();
      }
    }
    lastButtonState = buttonState;
  }
}
void brakeOff() {}`

I combined code and got this error i have download adafruit unified senor and dht library

All DHT libraries I am aware of (there are a lot of them and you didn't specify which exactly you're using) have a DHT class. I never saw one that defines a dht class. It may be a surprise to you but C++ code is case-sensitive.

dht sensor library by adafruit

I changed DHT to dht and now I get this error

C:\Users\Jlo\AppData\Local\Temp\.arduinoIDE-unsaved2023619-19192-lpqtyx.jlbcl\sketch_jul19a\sketch_jul19a.ino:2:10: fatal error: dht.h: No such file or directory
 #include <dht.h>
          ^~~~~~~
compilation terminated.

exit status 1

Compilation error: dht.h: No such file or directory
#include <Servo.h>
#include <dht.h>
#include <SD.h>
#include <SPI.h>



 #include <Adafruit_Sensor.h>
#define DHT11_PIN 7

#define in1 3  //L298n Motor Driver pins.
#define in2 10
#define in3 4
#define in4 5
#define LED 13
int command;      //Int to store app command state.
int Speed = 204;  // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0;  //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1;  //1 for the electronic braking system, 0 for normal.

const int TrigPin = 8;
const int EchoPin = 6;
float cm;
float ft;
int temp, hum;
dht DHT;
File sdcard_file;
int CS_pin = 53;
Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.

  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(LED, OUTPUT);  //Set the LED pin.
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  if (SD.begin()) {
    Serial.println("SD card is ready to use.");
  } else {
    Serial.println("SD card initialization failed");
    return;
  }
  sdcard_file = SD.open("data.txt", FILE_WRITE);
  if (sdcard_file) {
    sdcard_file.print("Temperature ");
    sdcard_file.print("      ");
    sdcard_file.print("Humidity ");
    sdcard_file.println("      ");
    sdcard_file.close();
  } else {
    Serial.println("error opening data.txt");
  }
}
void loop() {
  for (pos = 0; pos <= 180; pos += 1) {  // goes from 0 degrees to 180 degrees
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    temp = DHT.temperature;
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    hum = DHT.humidity;
    digitalWrite(TrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(TrigPin, LOW);
    cm = pulseIn(EchoPin, HIGH) / 58.0;  //The echo time is converted into cm
    cm = (int(cm * 100.0)) / 100.0;      //Keep two decimal places
    Serial.print("Distance\t=\t");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();

    if (Serial.available() > 0) {
      command = Serial.read();
      Stop();  //Initialize with motors stoped.
      switch (command) {
        case 'F':
          forward();
          break;
        case 'B':
          back();
          break;
        case 'L':
          left();
          break;
        case 'R':
          right();
          break;
        case 'G':
          forwardleft();
          break;
        case 'I':
          forwardright();
          break;
        case 'H':
          backleft();
          break;
        case 'J':
          backright();
          break;
        case '0':
          Speed = 100;
          break;
        case '1':
          Speed = 140;
          break;
        case '2':
          Speed = 153;
          break;
        case '3':
          Speed = 165;
          break;
        case '4':
          Speed = 178;
          break;
        case '5':
          Speed = 191;
          break;
        case '6':
          Speed = 204;
          break;
        case '7':
          Speed = 216;
          break;
        case '8':
          Speed = 229;
          break;
        case '9':
          Speed = 242;
          break;
        case 'q':
          Speed = 255;
          break;
      }
      Speedsec = Turnradius;
      if (brkonoff == 1 && cm >= 10) {
        brakeOn();
      } else {
        brakeOff();
      }
    }
    if (cm < 10) {
      Stop();
      sdcard_file = SD.open("data.txt", FILE_WRITE);
      if (sdcard_file) {
        sdcard_file.print(temp);
        sdcard_file.print("     ");
        sdcard_file.print(hum);
        sdcard_file.println("     ");
        sdcard_file.close();
      } else {
        Serial.println("error opening data.txt");
      }
    }
    myservo.write(pos);
    delay(15);
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    temp = DHT.temperature;
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    hum = DHT.humidity;
    digitalWrite(TrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(TrigPin, LOW);
    cm = pulseIn(EchoPin, HIGH) / 58.0;  //The echo time is converted into cm
    cm = (int(cm * 100.0)) / 100.0;      //Keep two decimal places
    Serial.print("Distance\t=\t");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();

    if (Serial.available() > 0) {
      command = Serial.read();
      Stop();  //Initialize with motors stoped.
      switch (command) {
        case 'F':
          forward();
          break;
        case 'B':
          back();
          break;
        case 'L':
          left();
          break;
        case 'R':
          right();
          break;
        case 'G':
          forwardleft();
          break;
        case 'I':
          forwardright();
          break;
        case 'H':
          backleft();
          break;
        case 'J':
          backright();
          break;
        case '0':
          Speed = 100;
          break;
        case '1':
          Speed = 140;
          break;
        case '2':
          Speed = 153;
          break;
        case '3':
          Speed = 165;
          break;
        case '4':
          Speed = 178;
          break;
        case '5':
          Speed = 191;
          break;
        case '6':
          Speed = 204;
          break;
        case '7':
          Speed = 216;
          break;
        case '8':
          Speed = 229;
          break;
        case '9':
          Speed = 242;
          break;
        case 'q':
          Speed = 255;
          break;
      }
      Speedsec = Turnradius;
      if (brkonoff == 1 && cm >= 10) {
        brakeOn();
      } else {
        brakeOff();
      }
    }
    if (cm < 10) {
      Stop();
      sdcard_file = SD.open("data.txt", FILE_WRITE);
      if (sdcard_file) {
        sdcard_file.print(temp);
        sdcard_file.print("     ");
        sdcard_file.print(hum);
        sdcard_file.println("     ");
        sdcard_file.close();
      } else {
        Serial.println("error opening data.txt");
      }
    }
    if (temp == 27)
      back();

    myservo.write(pos);
    delay(15);
  }
}
void forward() {
  analogWrite(in1, Speed);
  analogWrite(in3, Speed);
}
void back() {
  analogWrite(in2, Speed);
  analogWrite(in4, Speed);
}

void left() {
  analogWrite(in3, Speed);
  analogWrite(in2, Speed);
}
void right() {
  analogWrite(in4, Speed);
  analogWrite(in1, Speed);
}
void forwardleft() {
  analogWrite(in1, Speedsec);
  analogWrite(in3, Speed);
}
void forwardright() {
  analogWrite(in1, Speed);
  analogWrite(in3, Speedsec);
}
void backright() {
  analogWrite(in2, Speed);
  analogWrite(in4, Speedsec);
}
void backleft() {
  analogWrite(in2, Speedsec);
  analogWrite(in4, Speed);
}
void Stop() {
  analogWrite(in1, 0);
  analogWrite(in2, 0);
  analogWrite(in3, 0);
  analogWrite(in4, 0);
}
void brakeOn() {  //Here's the future use: an electronic braking system!
                  // read the pushbutton input pin:
  buttonState = command;
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == 'S') {
      if (lastButtonState != buttonState) {
        digitalWrite(in1, HIGH);
        digitalWrite(in2, HIGH);
        digitalWrite(in3, HIGH);
        digitalWrite(in4, HIGH);
        delay(brakeTime);
        Stop();
      }
    }
    lastButtonState = buttonState;
  }
}
void brakeOff() {}

C:\Users\Jlo\Documents\Arduino\libraries yes i have the file

no its not

its in a folder called dht_sensor_library

I think you need this library instead:

what include statement do i use if i upload this library

#include <dht.h>

I think the include file is still called DHT.h.

I know it is lowercase.

https://github.com/RobTillaart/DHTlib/blob/master/dht.h

But that library calls the class "dht". You should follow the examples of the library you're using!

The code in the OP uses dht class.
The code compiles after changing the #include to <dht.h>.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.