ESP32 S3 - DHT22

Learn how to use the ESP32 S3 with a DHT22 sensor to measure temperature and humidity. This beginner-friendly tutorial covers both the raw DHT22 sensor and the convenient module version, with complete wiring diagrams and ready-to-upload code examples.

What you'll build:

  1. A working circuit connecting a DHT22 sensor or module to the ESP32 S3
  2. Firmware that reads temperature in both Celsius and Fahrenheit plus relative humidity
  3. A live Serial Monitor feed displaying real-time environmental readings
  4. A foundation you can extend into weather stations, smart home sensors, and more
ESP32 S3 - DHT22

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×DHT22 Temperature Humidity Sensor Module
1×Alternatively, DHT22 Sensor
1×10 kΩ Resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DHT22 Temperature and Humidity Sensor

The DHT22 is a digital temperature and humidity sensor that delivers reliable, calibrated environmental readings over a single-wire interface, making it one of the most popular choices for ESP32 S3 projects. It operates on 3.3 V to 5 V, so it integrates directly with the ESP32 S3 without a level shifter. The sensor samples its environment every two seconds and reports both values in a single read cycle.

Key Specifications

The DHT22 runs on a supply voltage of 3 V to 5 V, which makes it fully compatible with the ESP32 S3's 3.3 V rail. Humidity measurement spans 0 % to 100 % with an accuracy of ±2 % to 5 %. Temperature measurement covers −40 °C to 80 °C with an accuracy of ±0.5 °C. The sensor updates at a maximum rate of 0.5 Hz, meaning one new reading is available every two seconds.

DHT22
Operating Voltage3 to 5V
The humidity range 0% to 100%
The humidity accuracy ± 2% to 5%
The temperature range -40°C to 80°C
The temperature accuracy ± 0.5°C
The reading rate 0.5Hz (one time per 2 seconds)

DHT22 Pinout

The DHT22 is available as a raw four-pin sensor and as a pre-built three-pin module that includes a built-in pull-up resistor.

DHT22 sensor module Pinout

DHT22 raw sensor pins (4 pins):

  1. GND pin: Connect to GND (0 V)
  2. VCC pin: Connect to VCC (3.3 V or 5 V)
  3. DATA pin: Communication pin between the sensor and the ESP32 S3
  4. NC pin: Not connected — leave unconnected

DHT22 module pins (3 pins):

  1. VCC (or +): Connect to 3.3 V or 5 V
  2. GND (or -): Connect to GND
  3. DATA (or OUT): Communication pin to the ESP32 S3

Wiring Diagram between DHT22 and ESP32 S3

Connecting the DHT22 to your ESP32 S3 requires only a few wires and, if you are using the raw sensor, one external pull-up resistor. When using the module version the pull-up resistor is already built in, so the module is the simpler option for beginners.

Safety Notes

Always power the DHT22 from the 3.3 V pin on the ESP32 S3 rather than an external 5 V rail unless you have verified your specific module's level-shifting capability. Keep the DATA line trace or jumper wire short to avoid noise on the single-wire bus. When using the raw sensor, the 10 kΩ pull-up resistor between DATA and VCC is not optional — omitting it will produce failed readings or no data at all.

ESP32 S3 - DHT22 Sensor Wiring

The wiring diagram between ESP32 S3 DHT22 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

DHT22 Sensor Pin ESP32 S3 Pin
VCC 3.3V or 5V
GND GND
DATA GPIO20
10kΩ Resistor Between DATA and VCC

ESP32 S3 - DHT22 Module Wiring

The DHT22 module simplifies wiring by including the pull-up resistor internally — no external resistor needed.

The wiring diagram between ESP32 S3 DHT22 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

DHT22 Module Pin ESP32 S3 Pin
VCC (or +) 3.3V or 5V
GND (or -) GND
DATA (or OUT) GPIO20

ESP32 S3 Code - DHT22

The following code initializes the DHT22 on GPIO20, then enters a loop that requests a fresh reading every two seconds, converts the raw temperature to both Celsius and Fahrenheit, and prints all three values to the Serial Monitor in a formatted line. Error checking is included so the program prints a clear failure message rather than silently outputting garbage values if the sensor is not responding.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-dht22 */ #include <DHT.h> #define DHT22_PIN 20 // The ESP32 S3 pin GPIO20 connected to DHT22 sensor DHT dht22(DHT22_PIN, DHT22); void setup() { Serial.begin(115200); dht22.begin(); // initialize the DHT22 sensor } void loop() { // read humidity float humi = dht22.readHumidity(); // read temperature in Celsius float temperature_C = dht22.readTemperature(); // read temperature in Fahrenheit float temperature_F = dht22.readTemperature(true); // check whether the reading is successful or not if ( isnan(temperature_C) || isnan(temperature_F) || isnan(humi)) { Serial.println("Failed to read from DHT22 sensor!"); } else { Serial.print("Humidity: "); Serial.print(humi); Serial.print("%"); Serial.print(" | "); Serial.print("Temperature: "); Serial.print(temperature_C); Serial.print("°C ~ "); Serial.print(temperature_F); Serial.println("°F"); } // wait a 2 seconds between readings delay(2000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Prepare the wiring: Connect the DHT22 sensor or module to your ESP32 S3 according to the wiring diagram above.
  3. Connect to computer: Plug the ESP32 S3 into your computer using a USB Type-C cable.
  4. Open Arduino IDE: Launch the Arduino IDE on your computer.
  5. Select your board: Choose ESP32 S3 from the board selector and select the correct COM port.
  6. Install DHT library: Click the Library Manager icon on the left sidebar of Arduino IDE.
  7. Search for library: Type "DHT" in the search box and find the DHT sensor library by Adafruit.
  8. Install the library: Click the Install button next to the Adafruit DHT library.
  • Search for DHT sensor library created by Adafruit and click the Install button.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DHT sensor library by Adafruit
Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors More info
1.4.6
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Install dependencies: When prompted, click Install All to install all required dependencies (including Adafruit Unified Sensor library).
ESP32 S3 Adafruit Unified sensor library
  1. Upload the code: Copy the code above, paste it into Arduino IDE, and click the Upload button.
  2. Test the sensor: Try changing the temperature around the DHT22 (place it near a warm cup or use a fan to cool it).
  3. View readings: Open the Serial Monitor (set to 115200 baud) to see live temperature and humidity readings.
  4. Pro Tip: Wait at least 2 seconds between readings — the DHT22 sensor updates at a maximum rate of 0.5 Hz, so polling it faster will simply return the same cached value or a read error.

Serial Monitor Output

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:01:02] Humidity: 51.30% | Temperature: 24.10°C ~ 75.38°F [2026-06-16 09:01:04] Humidity: 51.10% | Temperature: 24.20°C ~ 75.56°F [2026-06-16 09:01:06] Humidity: 50.80% | Temperature: 24.30°C ~ 75.74°F [2026-06-16 09:01:08] Humidity: 50.50% | Temperature: 24.50°C ~ 76.10°F
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Applications and Project Ideas

The ESP32 S3 and DHT22 make a powerful combination for any project that needs accurate, low-cost environmental sensing. Here are practical ways to put this circuit to work:

  1. Home weather station: Monitor indoor temperature and humidity with continuous data logging to a microSD card or cloud dashboard.
  2. Smart greenhouse controller: Automatically trigger ventilation fans or misters based on live humidity readings.
  3. Comfort monitor: Send a notification or sound a buzzer when room conditions drift outside a comfortable range.
  4. Server room monitoring: Track temperature continuously to catch overheating before equipment is damaged.
  5. DIY thermostat: Combine with a relay to build a smart temperature control system for any room.
  6. Pet habitat monitor: Ensure reptiles or other humidity-sensitive animals always have optimal conditions.
  7. Indoor air quality tracker: Pair with CO₂ or VOC sensors to build a comprehensive environmental monitor.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that your ESP32 S3 is reading temperature and humidity data reliably, push the project further with these progressively harder challenges:

  1. Beginner: Add an LED that turns on when temperature exceeds 25 °C and turns off when it drops below 23 °C, implementing a simple hysteresis band.
  2. Beginner: Display a "Too Humid" warning on the Serial Monitor when humidity rises above 70 %.
  3. Intermediate: Log temperature and humidity readings to an SD card with ISO 8601 timestamps obtained from an NTP server over Wi-Fi.
  4. Intermediate: Publish readings to an MQTT broker every 30 seconds so a Home Assistant dashboard can display live charts.
  5. Advanced: Build a web server on the ESP32 S3 that renders a real-time temperature and humidity graph in the browser using Chart.js.
  6. Advanced: Deploy two DHT22 sensors on different GPIO pins to monitor two rooms simultaneously and compare readings in a single Serial Monitor output stream.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!