// // FILE: DHT20_test_esp.ino // AUTHOR: Rob Tillaart // PURPOSE: Demo for DHT20 I2C humidity & temperature sensor // URL: https://github.com/RobTillaart/DHT20 // // Always check datasheet - front view // // +--------------+ // VDD ----| 1 | // SDA ----| 2 DHT20 | // GND ----| 3 | // SCL ----| 4 | // +--------------+ #include "DHT20.h" DHT20 DHT(&Wire1); // 2nd I2C interface void setup() { Serial.begin(115200); Serial.println(__FILE__); Serial.print("DHT20 LIBRARY VERSION: "); Serial.println(DHT20_LIB_VERSION); Serial.println(); Wire1.begin(12, 13); // select your pin numbers here delay(2000); Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)"); } void loop() { // READ DATA Serial.print("DHT20, \t"); int status = DHT.read(); switch (status) { case DHT20_OK: Serial.print("OK,\t"); break; case DHT20_ERROR_CHECKSUM: Serial.print("Checksum error,\t"); break; case DHT20_ERROR_CONNECT: Serial.print("Connect error,\t"); break; case DHT20_MISSING_BYTES: Serial.print("Missing bytes,\t"); break; case DHT20_ERROR_BYTES_ALL_ZERO: Serial.print("All bytes read zero"); break; case DHT20_ERROR_READ_TIMEOUT: Serial.print("Read time out"); break; case DHT20_ERROR_LASTREAD: Serial.print("Error read too fast"); break; default: Serial.print("Unknown error,\t"); break; } // DISPLAY DATA, sensor has only one decimal. Serial.print(DHT.getHumidity(), 1); Serial.print(",\t"); Serial.println(DHT.getTemperature(), 1); delay(2000); } // -- END OF FILE --