#include "DHT.h"
#define DHTPIN 4 // Define the GPIO pin where the DHT sensor is connected
#define DHTTYPE DHT22 // Change this to DHT11 if you're using a DHT11 sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200); // Initialize Serial communication
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait for 2 seconds between readings
float humidity = dht.readHumidity(); // Read humidity from the DHT sensor
float temperature = dht.readTemperature(); // Read temperature in Celsius from the DHT sensor
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor. Check wiring.");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}