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).
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!
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.
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
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.
Not sure why, but sometimes I also get some reading errors, but it’s definitely like 1 every 100 readings…
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