DHT11 sensor and I2C LCD displaying only 0 values

Hi all,
I am new to Arduino. I am trying to connect my Arduino UNO with I2C LCD display and DHT11 sensor. I connected all, tried different codes, but results for humidity and temperature are always 0.

#include <LiquidCrystal_I2C.h>
#include <dht.h>
//#define DHTTYPE DHT11
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x3F, 16 column and 2 rows
#define DHTPIN 4
dht DHT;
//DHT ddt(DHTPIN, DHTTYPE);
void setup(){
  lcd.init();
  lcd.backlight();
  lcd.begin(16,2);
  Serial.begin(9600);
}
 
void loop(){
    DHT.read11(DHTPIN);
    lcd.setCursor(0, 0);
    lcd.print("Humidity = ");
    lcd.print(DHT.humidity);
    lcd.print("%  ");
    delay(2000);
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(DHT.temperature); 
    lcd.print((char)223); // print ° character
    lcd.print("C  ");
    delay(1000);
}

I followed this tutorial
I tried to change pin for data on DHT11 from 2 to 3,5,7,8 and A0, but result is the same.
I tried to change code multiple times, tried given code and code in tutorial.
I am pretty sure that board and all wires are working properly.
Printing results as Serial.print also gives 0, so I doubt that my DHT11 sensor is not working.
Any help? Advice?



Several things to try. Try the contrast trim pot and see if your characters will appear, you should at least get some blocks where the characters should appear. If that does not work change your lcd.print statements to Serial.print and see if you get the information on the console. At this point you will know if your problem is in the interface-library or the hardware. If this does not resolve your problem post a schematic and links to each of the hardware devices.

The FLOAT value direct from the sensor needs to be formatted for printing. Try

lcd.print(String(DHT.temperature, 1) + char(223));
...
lcd.print(String(DHT.humidity, 0) + "%");

DHT temp only has 1 decimal place, humidity has zero.

With this code change, I got "0%" for humidity and nothing is printed for temperature.
Tested on both Serial.print and lcd.print and result is the same.
Here is the output I get:

I got same result on lcd and in console, 0 for both temperature and humidity.
Here is my schema:

Maybe it ought to be --
DHT.read(DHTPIN);

Still getting the same result, printing only 0 values.

Your pic shows DHT data connected to D2,
but your sketch has --
#define DHTPIN 4
// So Use D4

Some modules show 5V supply rather than the 3v3 you have.
So which DHT11 module do you have?
Are you using a breadboard for connections.
Show a photo of what you have in front of you rather than what could be.

I tried using different pins, but still facing the same issue.

image

The above diagram shows that DATA-pin of the Sensor is connected with DPin-2 of UNO. So, check that the following code line has been included in your sketch.

#define DHTPIN 2 //and not #define DHTPIN 4

Not this....????

I have DTH11 with 3 connectors (VCC, Data and GND). Tried with 3.3V and 5V, but no result.
I do not use breadboard.

What should I change?

Yes, I corrected the code and uploaded it once again, but result is the same.

Did you actually read the question before posting that? :rofl:

1 Like

Try by uploading the following sketch and report result:

#include <dht.h> //header file containing codes various commands
dht DHT;  //dht = className; DHT = Object
#define DHT11_PIN 2

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  if (chk != 0)
  {
    Serial.print("There is error!");
    while (1); //wait for ever
  }
  Serial.println("Sensor is found.");

  Serial.println();
  Serial.print("Humidity: ");
  float myHum = DHT.humidity;
  Serial.print(myHum, 2); Serial.println ('%');

  Serial.print("Temperature = ");
  float myTemp = DHT.temperature;
  Serial.print(myTemp, 2);  //2-digit after decimal point
  Serial.print(' '); Serial.println("degC");
  
  delay(1000);  //test/sampling interval
}

Output:

Humidity: 22.00%
Temperature = 29.00 degC

If the DHT-11 was not connected you'd get NAN (Not A Number) returned on your display for f and h. Soo, I'd say your DHT is fried. If it's returning zero's for both, that sounds like a dead ground.

Did you try the Example sketch for the library that you are using to read the DHT11?

Well basically you have changed the code from the link description and I was wondering why...

Also, do you have pullup resistor on the data line (10k) ....perhaps it is already on the module.

Either way, throw in some pics of "what you have there" include power supply.