Hi,
I have written a program that uses a DHT sensor. But I have a problem, before I used a DHT11 and all of it worked good. Now I have changed the sensor with DHT22 and an error occured.
In particular there is this error: DHTLIB_ERROR_TIMEOUT.
I post under an example that, as I told above, worked with DHT11 but not with DHT22.
#include <dht.h>
dht DHT;
#define DHT11_PIN 4
#define DHT21_PIN 5
#define DHT22_PIN 13
void setup()
{
Serial.begin(9600);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT22, \t");
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
delay(1000);
// // READ DATA
// Serial.print("DHT21, \t");
// chk = DHT.read21(DHT21_PIN);
// switch (chk)
// {
// case DHTLIB_OK:
// Serial.print("OK,\t");
// break;
// case DHTLIB_ERROR_CHECKSUM:
// Serial.print("Checksum error,\t");
// break;
// case DHTLIB_ERROR_TIMEOUT:
// Serial.print("Time out error,\t");
// break;
// default:
// Serial.print("Unknown error,\t");
// break;
// }
// // DISPLAY DATA
// Serial.print(DHT.humidity, 1);
// Serial.print(",\t");
// Serial.println(DHT.temperature, 1);
//
// delay(1000);
//
// // READ DATA
// Serial.print("DHT11, \t");
// chk = DHT.read11(DHT11_PIN);
// switch (chk)
// {
// case DHTLIB_OK:
// Serial.print("OK,\t");
// break;
// case DHTLIB_ERROR_CHECKSUM:
// Serial.print("Checksum error,\t");
// break;
// case DHTLIB_ERROR_TIMEOUT:
// Serial.print("Time out error,\t");
// break;
// default:
// Serial.print("Unknown error,\t");
// break;
// }
// // DISPLAY DATA
// Serial.print(DHT.humidity,1);
// Serial.print(",\t");
// Serial.println(DHT.temperature,1);
// delay(1000);
}
//
// END OF FILE
//
I use this library: