ESP32 Learn

Reading DHT11/DHT22 or AHT10/AHT20

2025-09-20 路 ~1 min read
Table of contents
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <Adafruit_Sensor.h>

#include <DHT.h>

#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(115200);
  dht.begin();
}
void loop() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  if (isnan(t) || isnan(h)) return;
  Serial.printf("T=%.1fC H=%.1f%%\n", t, h);
  delay(2000);
}

馃敄 #sensor #dht #aht