#include "DHTesp.h" // Library for DHT sensor
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
// put your main code here, to run repeatedly:
TempAndHumidity data = dhtSensor.getTempAndHumidity();
if (isnan(data.humidity) || isnan(data.temperature)) { // Condition to check whether the sensor reading was successful or not
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: "); // To print the data in serial monitor
Serial.print(data.humidity);
Serial.print(" %\t Temperature: ");
Serial.print(data.temperature);
Serial.println(" *C ");
delay(1000);
}