// Question:
// Does the ESP32-S3 work with the DHT22 ?
// Answer:
// Probably not.
//
// This project is with the "DHTNew" library by Rob Tillaart.
//
// Test1: https://wokwi.com/projects/475345517909932033
// Test2: https://wokwi.com/projects/475346162827297793
// Test3: https://wokwi.com/projects/475346465292234753 (this project)
//
// Only Test3 with the DHTNew library works.
#include <dhtnew.h>
DHTNEW mySensor(16); // ESP 16, UNO 5, MKR1010 5
void setup()
{
Serial.begin(115200);
}
void loop()
{
// Code from an example with the library.
// Print all the possible codes.
int chk = mySensor.read();
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT_A:
Serial.print("Time out A error,\t");
break;
case DHTLIB_ERROR_TIMEOUT_B:
Serial.print("Time out B error,\t");
break;
case DHTLIB_ERROR_TIMEOUT_C:
Serial.print("Time out C error,\t");
break;
case DHTLIB_ERROR_TIMEOUT_D:
Serial.print("Time out D error,\t");
break;
case DHTLIB_ERROR_SENSOR_NOT_READY:
Serial.print("Sensor not ready,\t");
break;
case DHTLIB_ERROR_BIT_SHIFT:
Serial.print("Bit shift error,\t");
break;
case DHTLIB_WAITING_FOR_READ:
Serial.print("Waiting for read,\t");
break;
default:
Serial.print("Unknown: ");
Serial.print(chk);
Serial.print(",\t");
break;
}
float humidity = mySensor.getHumidity();
float temperature = mySensor.getTemperature();
Serial.println("Temp: " + String(temperature, 2) + "°C");
Serial.println("Humidity: " + String(humidity, 1) + "%");
Serial.println("-----------------------------");
delay(2000);
}