#include "DHT.h"
// Set the pin where your sensor is connected
#define DHTPIN 2
// Choose your sensor type: DHT11 or DHT22
#define DHTTYPE DHT22 // Change to DHT22 if you're using that model
// Create the DHT sensor object
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Start serial communication
dht.begin(); // Initialize the sensor
}
void loop() {
// Read humidity and temperature
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" % | ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(2000); // Wait 2 seconds before next reading
}