• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

problem with the DHT22 sensor

Q&A Forum › Category: Other › problem with the DHT22 sensor
0 Vote Up Vote Down
spezi1805 asked 7 years ago

Hi everybody,
I hav litle problems with the communication to the DHT22 sensor. I use a ESP32 LOLIN board and the communikation is not continious (sorry about my bad englisch) 
I start the sketch and i get betwen 4 – 5 telegram´s in the correct way but after this it´s a little bit bingo playing to get data from the sensor. I tested diferent sensors and diferent pull up resistors but …
has anywon an idea about this problem?
The used code is from Rui´s tutorial (original only the pin is canched).

7 Answers
0 Vote Up Vote Down
Bruno Santos answered 7 years ago

I also had problems as you say but with the DHT11 and a copy from the Arduino Nano. In someway my sensor as burnout and made a short circuit with the Arduino.
I end up to buying a DHT22 with more quality and I solved the problem with Arduino Uno. 
Try it with another microcontroller…
 
Good luck!

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Hi! I think it might be a problem with the power or you are trying to read the readings very frequently.

What’s the timing in seconds between each reading?

When the DHT11/DHT22 failed to read from DHT sensor doesn’t work, it’s usually:

  • Power issue
  • Wrong wiring
  • Faulty DHT
  • Faulty ESP8266

Please read our DHT11/DHT22 Troubleshooting Guide.

0 Vote Up Vote Down
spezi1805 answered 7 years ago

Hey Bruno, thank´s for your answer. I made some test´s with other ESP32 board´s and with diferent sensor´s, but nothing getting better. I think the timing is the problem and i write more simple sketch for reading the sensor. Later more… now I must go cooking

0 Vote Up Vote Down
spezi1805 answered 7 years ago

Hi Rui, 
the power is a 10A industrial power suply. The timing… might be able. I test another sketch whitch is more simple. 
 

#include

// for DHT22,
// VCC: 5V or 3V
// GND: GND
// DATA: 16
int pinDHT22 = 16;
SimpleDHT22 dht22;

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

void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT22...");

// read without samples.
// @remark We use read2 to get a float data, such as 10.1*C
// if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
return;
}

Serial.print("Sample OK: ");
Serial.print((float)temperature); Serial.print(" *C, ");
Serial.print((float)humidity); Serial.println(" RH%");

// DHT22 sampling rate is 0.5HZ.
delay(2500);
}
With this code it work´s better but not perfekt. Every 10 - 20 reading the conektion to the sensor dosn´t work.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Not sure why, but sometimes I also get some reading errors, but it’s definitely like 1 every 100 readings…

0 Vote Up Vote Down
spezi1805 answered 7 years ago

Hi Rui,
I play´d a little bit with library´s and get a good result with the DHTesp.h.
Here is the code

#include "DHTesp.h"

DHTesp dht;

void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)\tHeatIndex (C)\t(F)");

dht.setup(17); // Connect DHT sensor to GPIO 17
}

void loop()
{
delay(dht.getMinimumSamplingPeriod());

float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

Serial.print(dht.getStatusString());
Serial.print("\t");
Serial.print(humidity, 1);
Serial.print("\t\t");
Serial.print(temperature, 1);
Serial.print("\t\t");
Serial.print(dht.toFahrenheit(temperature), 1);
Serial.print("\t\t");
Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1);
Serial.print("\t\t");
Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1);
}

In the last 5 hours it work´s realy fine. The only thing is that Iget the best result with no pullup. i dont know why…

Nice sunday

Peter

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

According to the datasheet the pullup is required, but if you get betters results I wouldn’t use the pullpup. 
Thanks for sharing that example! Regards,
Rui

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.