DHT11 sensor, it didn't show on serial monitor

Hello everybody, i’m new at arduino world and I want to make a egg hatchery.

I just started with DHT11 sensor and after i made a simple code to try this sensor. I write it as i understand but it didn’s show anything at serial monitor. It didn’t say anything about errors.

I don’t know.
all solutions will be welcome

That’s the code:

#include <DHT11.h>
DHT11 dht(4);
float temp;
float hum;
int lectura;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
 if(lectura=dht.read(temp, hum)== 0)
 { Serial.print("Temperatura");
  Serial.print(temp);
  Serial.print("ºC");
  Serial.print("Humedad");
  Serial.print(hum);
  Serial.print("%");
  Serial.println();
  delay(1000);
}
else
  {Serial.println("error");
  }
}

Make sure you have the baud rate menu at the bottom right corner of Serial Monitor set to 9600.

Unfortunately, I could not compile/upload your program in my UNO/Dht11. This is the program (taken from IDE Example) that I have executed in my UNO; it is working fine. You may use this program to check your sensor functionality. This is the Library File that I have used.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 4     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}

pert:
Make sure you have the baud rate menu at the bottom right corner of Serial Monitor set to 9600.

Yes i have it at 9600bauds

GolamMostafa:
Unfortunately, I could not compile/upload your program in my UNO/Dht11. This is the program (taken from IDE Example) that I have executed in my UNO; it is working fine. You may use this program to check your sensor functionality. This is the Library File that I have used.

Thank you for your help
i copied your code with your library exactly but now it gives me the following error:

In file included from D:\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.cpp:22:0:

D:\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

#include <Adafruit_Sensor.h>

^
compilation terminated.
Error compiling for board arduino/genuino mega or mega 2560

I make sure i had the correct Com Port. I updated board controller and libraries but I don’t understand the error now

Just now, I have compiled and uploaded into Arduino MEGA successfully. It is working fine.

Why do you encounter problem?

Probably, the Library has not been included correctly in the IDE? To include the dht11-master.zip Library, I have followed these steps:

1. Save the zip file in the desktop.
2. From the Tool bar of IDE: Sketch ----> Include Library ----> Add .ZIP Library... -----> Desktop ----> Select the dht11-master.zip file ----->click on Open

Hope, your problem will be solved.

GolamMostafa:
Just now, I have compiled and uploaded into Arduino MEGA successfully. It is working fine.

Why do you encounter problem?

Probably, the Library has not been included correctly in the IDE? To include the dht11-master.zip Library, I have followed these steps:

1. Save the zip file in the desktop.
2. From the Tool bar of IDE: Sketch ----> Include Library ----> Add .ZIP Library… -----> Desktop ----> Select the dht11-master.zip file ----->click on Open

Hope, your problem will be solved.

Hi again, I unistalled all my libraries and started from zero. Now i made again the code and now didn’t give me error. Now at serial monitor only write TEST but nothing more

#include <DHT11.h>

#include <Adafruit_Sensor.h>

DHT11 dht(2);
float temp;
float hum;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.print("TEST");
}

void loop() {
dht.read(temp,hum);
Serial.print("Temperatura");
Serial.print(temp);
Serial.print("Humedad");
Serial.print(hum);
Serial.println();
delay(1000);
}

It could be that my DHT11 it’s broke because yours it’s light up and mine not. And the code it’s without errors??

Do you have a RED colored power LED on your dht11, and is it ON? Please, upload the following program in the Arduino. This program requires the library that I have provided you. The DATA line of the Dht11 should be connected at DPin-4. Vcc line to 5V, and GND to GND. Why have you included this line #include <Adafruit_Sensor.h> in your program?

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 4     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}

That’s my sensor and never lighted up so… It could be broken?. I added Adafruit_sensor.h because it gives me error that I didn’t have it, so I installed it and now it works “fine” with no errors but it Says:

failed to read from DHT sensor

Check the continuity of the jumper wires. Also, try to make direct jumper on the pins of the sensors instead of through breadboard holes.

GolamMostafa:
Check the continuity of the jumper wires. Also, try to make direct jumper on the pins of the sensors instead of through breadboard holes.

Totally working, 5v wire which I was using was broken. I'm sorry to ask this topics but for me it was very strange this error.

Now it's working fine

Thank you so much GolamMostafa :slight_smile: