Wiring guide

How to wire a DHT22 to an ESP32-S3

To wire a DHT22 to an ESP32-S3, connect VCC to 3V3, DATA to GPIO 4 and GND to G. The ESP32-S3 is a 3.3 V board, so power the sensor from 3.3 V: the module’s built-in pull-up then keeps DATA at 3.3 V, which the pin can take. The sketch below uses the Adafruit DHT sensor library (DHT.h) library. It prints the temperature and the humidity on the serial monitor every two seconds.

  • 3.3 V logic
  • Library: DHT.h
  • 3 wires
ESP32-S3 · DHT22live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

DHT22 to ESP32-S3 wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

DHT22 pinESP32-S3 pinWire colorWhy
VCC (+)3V3redThe sensor runs from 3.3 V, and so does its pull-up, so DATA never rises above what the pin can take.
DATA (out)GPIO 4amberOne wire, both directions: the board pulls it low to ask, the sensor answers with 40 bits.
GND (-)GblueA shared ground, or the board cannot read the sensor’s levels.
Voltage

Power and logic levels for DHT22 and ESP32-S3

Logic level

The ESP32-S3’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The DHT22 takes 3.3 V from 3V3. That pin is the ESP32-S3’s own regulated 3.3 V output.

This pair

The three-pin module carries a pull-up resistor from DATA to VCC. Powered from 5V, that resistor would hold a ESP32-S3 pin at 5 V, which the ESP32-S3 (Xtensa LX7) is not rated for. From 3V3 the whole line stays at 3.3 V and the sensor still reads normally.

Pins to leave alone

GPIO 19 and 20 are the USB port’s data lines, GPIO 35 to 37 belong to the PSRAM on octal-PSRAM boards such as the N8R8, and GPIO 0, 3, 45 and 46 are strapping pins.

The sketch

The working code for the ESP32-S3

Library: Adafruit DHT sensor library (DHT.h). This is the sketch the circuit above runs.

DHT22 on ESP32-S3 GPIO 4
#include "DHT.h"

#define DHT_PIN 4     // DATA, GPIO 4
#define DHT_TYPE DHT22

DHT dht(DHT_PIN, DHT_TYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
  Serial.println("DHT22 on the ESP32-S3");
}

void loop() {
  delay(2000);                          // the DHT22 measures every 2 s
  float celsius = dht.readTemperature();
  float humidity = dht.readHumidity();
  if (isnan(celsius) || isnan(humidity)) {  // a failed read is NAN
    Serial.println("No reading from the DHT22");
    return;
  }
  Serial.print("Temperature: ");
  Serial.print(celsius, 1);
  Serial.print(" C  Humidity: ");
  Serial.print(humidity, 1);
  Serial.println(" %");
}
Output

What you should see

Open the serial monitor at 115200 baud. The sketch waits two seconds, which is how often a DHT22 can measure, and then prints one line per reading. The sensor starts at 22 degrees C and 50 percent humidity, and the line follows its two sliders when you drag them.

If a read fails the sketch prints No reading from the DHT22 instead of a number. That is what a wrong DATA pin or a missing pull-up looks like.

The serial monitor prints this, recorded from the circuit above left at its defaults:

DHT22 on the ESP32-S3
Temperature: 22.0 C  Humidity: 50.0 %
Pitfalls

Common mistakes wiring a DHT22 to an ESP32-S3

Reading faster than every two seconds

A DHT22 needs two seconds between measurements. Ask sooner and it returns the previous reading, or nothing at all, so a fast loop looks like a stuck sensor. Keep the delay(2000), or time the reads with millis().

Powering the module from 5V

It works for a while, which is the trap. The module’s pull-up then holds DATA at 5 V, above the ESP32-S3 (Xtensa LX7)’s absolute maximum, and the pin can be damaged slowly. Use 3V3, as in the circuit above.

Using the USB or PSRAM pins

GPIO 19 and 20 are the USB port’s data lines and GPIO 35 to 37 belong to the PSRAM on N8R8 boards. Wire the DHT22’s DATA line to one of those and the USB socket or the memory stops working on a real board, even though the simulator carries on. Stay on GPIO 4 to 18.

Build your own DHT22 project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.