#include <DHT.h>
#define DHTPIN 15 // Pin to which the DHT22 sensor is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302) sensor type
#define ledPin 23
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop() {
// Read data from the DHT sensor
float temperature = dht.readTemperature();
// Check if the DHT sensor read was successful
if (!isnan(temperature)) {
Serial.println("Connected");
// Check if temperature is above 38 degrees Celsius
if (temperature > 45.0) {
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.println("Hot");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.println("Cold");
}
} else {
Serial.println("Cannot read DHT22");
digitalWrite(ledPin, LOW); // Turn off the LED in case of an error
}
delay(2000); // Delay for 2 seconds before reading again
}