#include<DHT.h>
#define DHTPIN 33 // Define the pin connected to the DHT22 sensor
#define DHTTYPE DHT22 // Define the type of DHT sensor
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
void setup()
{
Serial.begin(115200); // Start the serial communication
dht.begin();// Initialize the DHT sensor
Serial.println("DHT22 Sensor Initialized");
}
void loop()
{
delay(2000); // Wait a few seconds between readings
float temp = dht.readTemperature();// Read temperature in Celsius
float humidity = dht.readHumidity();// Read humidity
// Check if any readings failed
if (isnan(temp) || isnan(humidity))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print temperature and humidity to the serial monitor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}