#include <DHT.h> // Include the DHT sensor library to handle the DHT11 sensor functions
#define DHTPIN 2 // Define the pin where the data wire of the DHT11 sensor is connected
#define DHTTYPE DHT11 // Specify the type of DHT sensor being used (DHT11)
DHT dht(DHTPIN, DHTTYPE); // Create a DHT object named 'dht' that uses the specified pin and sensor type
void setup() {
Serial.begin(9600); // Initialize serial communication at a baud rate of 9600, enabling data transmission to the computer
dht.begin(); // Initialize the DHT sensor
}
void loop() {
Serial.print("Humidity: "); // Print the text "Humidity: " to the serial monitor
Serial.print(dht.readHumidity()); // Read and print the humidity value from the DHT sensor
Serial.print(" %, Temp: "); // Print the text " %, Temp: " to the serial monitor
Serial.print(dht.readTemperature()); // Read and print the temperature value from the DHT sensor
Serial.println(" Celsius"); // Print the text " Celsius" and move to a new line on the serial monitor
delay(2000); // Wait for 2 seconds before running the loop again (to avoid flooding the serial monitor with data)
}