#include <DHT.h>
#define DHTPIN 14
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000); // this speeds up the simulation
// call the readTemperature() method of the dht object
float temperature = dht.readTemperature();
// check for nan (not a number) i.e. not connected or failed, then try again
// if it doesn’t work, check the wiring and check sensor is firmly in breadboard
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor.");
return;
}
// print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}