#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
if(Serial.available()>0){
String command = Serial.readStringUntil('\n');
if(command =="humi"){
sensor_dht22();
}
}
delay(1000); // this speeds up the simulation
}
void sensor_dht22() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
}