ESP32 Bench
Boards: ESP32, S3, C3
Flash and monitor: Web Serial
← All projects

DHT22 climate logger

Read temperature and humidity every two seconds and print them as a log line.

Starter15 min115200 baud
Board
Fig. 1. Pins this project uses on the ESP32-DevKitC V4, 38 pin. USB connector at the bottom.

Wiring

FromTo boardNote
DHT22 VCC3V3
DHT22 DATAGPIO 410 kΩ pull-up to 3V3 on a bare sensor
DHT22 GNDGND

Tested on this board

Not run on this board yet. Treat the wiring and code as a first draft.

Firmware, Arduino sketch for ESP32 Dev Module

#include <DHT.h>

DHT dht(4, DHT22);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Sensor read failed, check wiring");
    return;
  }
  Serial.printf("%.1f C  %.1f %%RH\n", t, h);
}

Parts

QuantityPartWhere to buy
1×ESP32 dev boardBuy at Amazon
1×DHT22 (AM2302) sensor
1×10 kΩ resistor, only for a bare sensor without a breakout
3×Jumper wires

Amazon buy links may include an Associates tag, and this site may earn a commission from qualifying Amazon purchases at no extra cost to you. Adafruit links are direct.

Libraries

DHT sensor library (Adafruit), Adafruit Unified Sensor

Load it

  1. In the Arduino IDE, install the esp32 board package and pick the board named above the sketch.
  2. Install the libraries listed above from the Library Manager.
  3. Paste the sketch, choose the board's port and upload. Hold BOOT if the upload stalls at Connecting.
  4. Close the IDE's serial monitor, then open the bench here to watch the output.