// This line includes the DHTesp library,
// which provides functions and functionalities specifically designed for interacting with DHT sensors like the DHT22.
#include <DHTesp.h>
#define DHT_PIN 13
// This line creates an object named dhtSensor of type DHTesp.
// This object will be used to interact with the DHT22 sensor connected to the pin defined earlier.
DHTesp dhtSensor;
void setup(){
// This allows you to view the sensor readings on your computer. (baud rate)
Serial.begin(115200);
// This line configures the dhtSensor object.
// It specifies the pin to which the sensor is connected (DHT_PIN) and the sensor type (DHTesp::DHT22).
dhtSensor.setup(DHT_PIN, DHTesp :: DHT22);
}
void loop(){
// This line reads the temperature and humidity values from the DHT22 sensor and stores them in a variable named data.
// The data variable is of type TempAndHumidity, which likely has separate fields for temperature and humidity within the library.
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "C"); // temperature value IS formatted to two decimal places
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println(" --- ");
delay(1000);
}