DHT11 library troubles

i’ve been working on this code almost all day and i couldnt get the DHT11 sensor to work, nor my complete code, if someone can help me with this i would be amazing
my code is:

#include <dht11.h>
#define DHT11PIN 8
dht11 DHT11;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int but=LOW;

void setup() {
pinMode (6,OUTPUT);
pinMode(9,OUTPUT);
pinMode(7,INPUT_PULLUP);
lcd.begin(16,2);
lcd.setCursor(1, 0);
lcd.print(“Press button”);
lcd.setCursor(3, 1);
lcd.print(“to start”);

}

void loop() {
lcd.clear();
delay(5000);
but= digitalRead(7);
lcd.setCursor(1, 0);
lcd.print(“Press button”);
lcd.setCursor(3, 1);
lcd.print(“to start”);

noTone(9);
while(but=HIGH){
noTone(9);
lcd.setCursor(3,0);
lcd.print(“Loading…”);
delay(5000);
digitalWrite(6,HIGH);
delay(5000);
digitalWrite(6,LOW);
delay(5000);
tone (9, 600, 2000);
lcd.clear();
int tmp = DHT11.read(DHT11PIN);
if (tmp <= 10); {
lcd.setCursor(0,1);
lcd.print(“Temp:”);
lcd.print((float)DHT11.temperature,2);
lcd.print(" C");
lcd.setCursor(0,0);
lcd.print(“Go with jacket”);
delay(5000);
lcd.clear();
}

if (10< tmp <=20); {
lcd.setCursor(0,1);
lcd.print(“Temp:”);
lcd.print((float)DHT11.temperature,2);
lcd.print(" C");
lcd.setCursor(0,0);
lcd.print(“Go with sweater”);
delay(5000);
lcd.clear();
}

if (20< tmp <=30); {
lcd.setCursor(0,1);
lcd.print(“Temp:”);
lcd.print((float)DHT11.temperature,2);
lcd.print(" C");
lcd.setCursor(0,0);
lcd.print(“Go whith pants”);
delay(5000);
lcd.clear();
}

if (30< tmp <=40); {
lcd.setCursor(0,1);
lcd.print(“Temp:”);
lcd.print((float)DHT11.temperature,2);
lcd.print(" C");
lcd.setCursor(0,0);
lcd.print(“Go with shorts”);
delay(5000);
lcd.clear();
}

if (40< tmp <=50); {
lcd.setCursor(0,1);
lcd.print(“Temp:”);
lcd.print((float)DHT11.temperature,2);
lcd.print(" C");
lcd.setCursor(0,0);
lcd.print(“don’t go out”);
delay(5000);
lcd.clear();
}

}
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

When your code requires a library that’s not included with the Arduino IDE please always post a link (using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Please explain exactly what you mean by “doesn’t work”.

Thank you for telling me all of that, im new in the forum
Here’s the link that i used to download the library GitHub - adidax/dht11: DHT11 library for Arduino
i say that doesnt work because the sensor is conected correctly and the LCD screen is also conected correcly, but when the sensor reads the temperature it shows only zeros, not other value

#include <dht11.h>
#define DHT11PIN 8
dht11 DHT11;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int but=LOW;
void setup() {
  pinMode (6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(7,INPUT_PULLUP);
 lcd.begin(16,2);
lcd.setCursor(1, 0);
  lcd.print("Press button");
  lcd.setCursor(3, 1);
  lcd.print("to start");
}
void loop() {
  lcd.clear();
  delay(5000);
   but= digitalRead(7);
  lcd.setCursor(1, 0);
  lcd.print("Press button");
  lcd.setCursor(3, 1);
  lcd.print("to start");
 noTone(9);
 while(but=HIGH){
  noTone(9);
  lcd.setCursor(3,0);
  lcd.print("Loading...");
  delay(5000);
  digitalWrite(6,HIGH);
  delay(5000);
  digitalWrite(6,LOW);
  delay(5000);
  tone (9, 600, 2000);
  lcd.clear();
  int tmp = DHT11.read(DHT11PIN);
  if (tmp <= 10); {
     lcd.setCursor(0,1);
         lcd.print("Temp:");
       lcd.print((float)DHT11.temperature,2);
       lcd.print(" C");
    lcd.setCursor(0,0);
    lcd.print("Go with jacket");
     delay(5000);
    lcd.clear();
  }
    if (10< tmp <=20); {
       lcd.setCursor(0,1);
         lcd.print("Temp:");
       lcd.print((float)DHT11.temperature,2);
       lcd.print(" C");
    lcd.setCursor(0,0);
    lcd.print("Go with sweater");
     delay(5000);
    lcd.clear();
    }
       if (20< tmp <=30); {
         lcd.setCursor(0,1);
         lcd.print("Temp:");
       lcd.print((float)DHT11.temperature,2);
       lcd.print(" C");
    lcd.setCursor(0,0);
    lcd.print("Go whith pants");
    delay(5000);
    lcd.clear();
      }
      if (30< tmp <=40); {
        lcd.setCursor(0,1);
         lcd.print("Temp:");
       lcd.print((float)DHT11.temperature,2);
       lcd.print(" C");
    lcd.setCursor(0,0);
    lcd.print("Go with shorts");
     delay(5000);
    lcd.clear();
      }
      if (40< tmp <=50); {
         lcd.setCursor(0,1);
         lcd.print("Temp:");
       lcd.print((float)DHT11.temperature,2);
       lcd.print(" C");
    lcd.setCursor(0,0);
    lcd.print("don't go out");
     delay(5000);
    lcd.clear();
      }
}
}

Start with the examples provided with the library, see if that gives you any result on the Serial monitor. That to confirm whether your sensor works.

Your button will also be terribly unresponsive with those lengthy delay() calls.

The library doesn’t have any examples, and other library that I downloaded from [GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors

has examples but when I try to use it says that i have trouble compile for the arduino
the error messages are

Arduino:1.8.5 (Windows 10), Tarjeta:"Arduino Leonardo"

C:\Users\angel\Documents\Arduino\libraries\DHT_sensor_library-1.3.0\examples\DHT_Unified_Sensor\DHT_Unified_Sensor.ino:10:29: fatal error: Adafruit_Sensor.h: No such file or directory

 #include <Adafruit_Sensor.h>

                             ^

compilation terminated.

exit status 1
Error compile for arduino Leonardo

](GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors)

Install the Adafruit Unified Sensor Library - as mentioned in the instructions of that library (it's in the link you posted).

angelsanchez203:
Thank you for telling me all of that, im new in the forum

You're quite welcome. I think you might have missed the part where I requested that you use Tools > Auto Format on your code. It might sound uptight but it really does help us to quickly read your code and it only takes a second, especially if you use the Ctrl + T keyboard shortcut.

Hi,

What is your code supposed to do, what should be on the LCD screen?

Can I suggest you write code just to put the Humidity and Temperature on your LCD screen without all the garnishing.
Then work from there step by step introducing various features into your code and screen.

Tom.. :slight_smile: