#include "DHT.h"
#define DHT22_PIN 7
DHT dht22(DHT22_PIN, DHT22);
void setup() {
Serial.begin(9600);
dht22.begin(); // Initialize the DHT22 sensor
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read humidity
float humi = dht22.readHumidity();
// Read temperature as Celsius
float tempC = dht22.readTemperature();
// Read temperature as Fahrenheit
float tempF = dht22.readTemperature(true);
// Check if any reads failed
if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
Serial.println("Failed to read from DHT22 sensor!");
} else {
Serial.print("DHT22# Humidity: ");
Serial.print(humi);
Serial.print("% | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
}
}