ESP32 S3 - Temperature Humidity Sensor

This tutorial shows you how to connect DHT11 or DHT22 temperature and humidity sensors to your ESP32 S3 and read environmental data in real-time. Whether you're building a weather station or a home automation project, the DHT sensors pair seamlessly with the ESP32 S3's digital I/O capabilities.

What you'll build:

  1. A circuit connecting a DHT11 or DHT22 sensor to the ESP32 S3
  2. Arduino sketch that reads temperature and humidity values from the sensor
  3. Serial Monitor output displaying live temperature in both Celsius and Fahrenheit
  4. A foundation for real-world projects such as smart greenhouses and climate monitors
ESP32 S3 - Temperature Humidity Sensor

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×DHT11 Temperature Humidity Sensor Module
1×Alternatively, DHT11 Sensor
1×Optionally, Temperature and Humidity Sensor DHT22
1×Alternatively, DHT22 Sensor
1×10 kΩ Resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

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 DHT11 and DHT22 Temperature and Humidity Sensor

DHT11 and DHT22 are digital temperature and humidity sensors that deliver calibrated output over a single data wire, making them straightforward to integrate with the ESP32 S3. Both sensors are widely used in maker projects because they require no analog circuitry and are supported by a well-maintained Arduino library. While they share the same pinout and communication protocol, the DHT22 offers greater accuracy and a wider measurement range, whereas the DHT11 is the more budget-friendly option for basic applications.

Key Specifications

The table below compares the two sensors side by side:

DHT22 DHT11
The price low cost ultra low cost
The humidity range 0% to 100% 20% to 80%
The humidity accuracy ± 2% to 5% 5%
The temperature range -40°C to 80°C 0°C to 50°C
The temperature accuracy ± 0.5°C ± 2°C
The reading rate 0.5Hz (one time per 2 seconds) 1Hz (one time per second)
Dimension 15.1mm x 25mm x 7.7mm 15.5mm x 12mm x 5.5mm
Operating Voltage3 to 5V 3 to 5V

The DHT22 is the better choice when precision matters, while the DHT11 is a cost-effective solution for non-critical environmental sensing. Both sensors operate at 3.3V, which is native to the ESP32 S3 — no level shifter needed.

The Commons Between DHT11 and DHT22

  • Identical 4-pin pinout configuration
  • Same wiring connections to ESP32 S3
  • Compatible code with minimal changes
  • Both use single-wire digital communication
  • Low power consumption ideal for battery projects

DHT11 and DHT22 Pinout

Both DHT11 and DHT22 temperature humidity sensors share the same 4-pin configuration. The pin roles from left to right are as follows:

  1. VCC pin: Connect to power supply (3.3V or 5V)
  2. DATA pin: Digital signal pin for communication with ESP32 S3
  3. NC pin: Not connected (leave unconnected)
  4. GND pin: Connect to ground (0V)
DHT11 and DHT22 temperature and humidity sensor Pinout

Module Version (Recommended)

We highly recommend using DHT11 and DHT22 sensor modules for easier wiring. Sensor modules include a built-in pull-up resistor, so no external resistor is needed. The module exposes only three pins — VCC, GND, and DATA (sometimes labelled +, −, and OUT) — which makes breadboard assembly much quicker and less error-prone.

DHT11 and DHT22 temperature and humidity module Pinout
image source: diyables.io

Note: Pin order may vary between manufacturers — always check the labels printed on your module before connecting power.

Wiring Diagram between DHT11/DHT22 and ESP32 S3

The wiring connections are identical for both DHT11 and DHT22 sensors with the ESP32 S3, so you only need to learn one wiring pattern regardless of which sensor you choose. If you are using the bare 4-pin sensor (not a module), place a 10 kΩ pull-up resistor between the DATA line and the 3.3V rail to ensure reliable communication.

Safety Notes

Always power the sensor from the ESP32 S3's 3.3V pin rather than 5V — both DHT11 and DHT22 are compatible with 3.3V and the ESP32 S3's GPIO pins are not 5V-tolerant. Keep the DATA wire as short as practical to avoid signal integrity issues, and never hot-swap the sensor while the board is powered.

ESP32 S3 - DHT11 Sensor Wiring

DHT11 Pin ESP32 S3 Pin
VCC 3.3V
GND GND
DATA GPIO12 (or any digital pin)
NC Not connected
The wiring diagram between ESP32 S3 DHT11 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

ESP32 S3 - DHT22 Sensor Wiring

DHT22 Pin ESP32 S3 Pin
VCC 3.3V
GND GND
DATA GPIO12 (or any digital pin)
NC Not connected
The wiring diagram between ESP32 S3 DHT22 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

ESP32 S3 - DHT11 Module Wiring

Most DHT11 sensor modules include a built-in resistor, simplifying your wiring setup:

DHT11 Module Pin ESP32 S3 Pin
+ (or VCC) 3.3V
* (or GND) GND
OUT (or DATA) GPIO12
The wiring diagram between ESP32 S3 DHT11 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

ESP32 S3 - DHT22 Module Wiring

Most DHT22 sensor modules include a built-in resistor, eliminating the need for external components:

DHT22 Module Pin ESP32 S3 Pin
+ (or VCC) 3.3V
* (or GND) GND
OUT (or DATA) GPIO12
The wiring diagram between ESP32 S3 DHT22 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

ESP32 S3 Code - DHT11

The following code reads temperature and humidity from the DHT11 sensor and prints both values to the Serial Monitor every two seconds. It initialises the Adafruit DHT library with the sensor type set to DHT11 and the data pin assigned to GPIO12, then formats each reading as a human-readable line showing humidity percentage alongside temperature in both Celsius and Fahrenheit.

/* * 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-temperature-humidity-sensor */ #include <DHT.h> #define DHT_SENSOR_PIN 12 // The ESP32 S3 pin GPIO12 connected to DHT11 sensor #define DHT_SENSOR_TYPE DHT11 DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE); void setup() { Serial.begin(115200); dht_sensor.begin(); // initialize the DHT sensor } void loop() { // read humidity float humi = dht_sensor.readHumidity(); // read temperature in Celsius float temperature_C = dht_sensor.readTemperature(); // read temperature in Fahrenheit float temperature_F = dht_sensor.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 DHT 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); }

ESP32 S3 Code - DHT22

The following code reads temperature and humidity from the DHT22 sensor with improved accuracy compared to the DHT11. Only the sensor type constant differs from the DHT11 sketch — the wiring, library calls, and output format are identical, making it easy to switch between sensors.

/* * 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-temperature-humidity-sensor */ #include <DHT.h> #define DHT_SENSOR_PIN 12 // The ESP32 S3 pin GPIO12 connected to DHT22 sensor #define DHT_SENSOR_TYPE DHT22 DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE); void setup() { Serial.begin(115200); dht_sensor.begin(); // initialize the DHT sensor } void loop() { // read humidity float humi = dht_sensor.readHumidity(); // read temperature in Celsius float temperature_C = dht_sensor.readTemperature(); // read temperature in Fahrenheit float temperature_F = dht_sensor.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 DHT 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); }

Important: The two code examples above differ by only one line — the sensor type definition (DHT11 vs DHT22).

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the components: Follow the wiring diagram above to connect your DHT sensor to the ESP32 S3.
  3. Connect USB cable: Plug your ESP32 S3 into your computer using a Type-C cable.
  4. Open Arduino IDE: Launch the Arduino IDE software on your computer.
  5. Select board: Choose ESP32 S3 from the board menu.
  6. Select COM port: Choose the correct COM port for your ESP32 S3.
  7. Install DHT library: Click the Library Manager icon in the left sidebar.
  8. Search for library: Type "Adafruit DHT" in the search box.
  9. Install Adafruit DHT: Click Install on the DHT sensor library by Adafruit.
  • 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 add required dependencies.
ESP32 S3 Adafruit Unified sensor library
  1. Copy the code: Select either the DHT11 or DHT22 code based on your sensor.
  2. Upload code: Click the Upload button to program your ESP32 S3.
  3. Open Serial Monitor: Set baud rate to 115200 to view sensor readings.
  4. Test the sensor: Place the sensor near a heat source (like a coffee cup) to see values change.
  5. Pro Tip: Wait 2–3 seconds between readings for stable measurements — DHT sensors need a brief settling period after each sample, and polling them too quickly can return stale or invalid data.

Serial Monitor Output

After uploading the code, open the Serial Monitor at 115200 baud to see real-time temperature and humidity readings. The output below shows typical values measured in a room environment on 2026-06-16:

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
[09:14:02] Humidity: 52.00% | Temperature: 23.00°C ~ 73.40°F [09:14:04] Humidity: 52.00% | Temperature: 23.00°C ~ 73.40°F [09:14:06] Humidity: 51.00% | Temperature: 23.50°C ~ 74.30°F [09:14:08] Humidity: 51.00% | Temperature: 24.00°C ~ 75.20°F
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Application and Project Ideas

The DHT11 and DHT22 sensors open the door to a wide range of practical ESP32 S3 projects, from simple data displays to fully automated environmental control systems.

  1. Home weather station: Monitor indoor temperature and humidity on a display.
  2. Smart greenhouse controller: Automate watering and ventilation based on humidity levels.
  3. Bathroom exhaust fan automation: Turn on a fan automatically when humidity exceeds a set threshold.
  4. Server room monitor: Send an alert when temperature rises above safe operating levels.
  5. Smart thermostat: Build a WiFi-enabled temperature controller for home automation.
  6. Data logger: Record environmental data to an SD card for long-term analysis.
  7. Comfort index calculator: Derive heat index or dew point values from the sensor readings.

Video Tutorial

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

Challenge Yourself

Once you have the basic sensor readings working, there are many ways to extend the project and deepen your understanding of the ESP32 S3 platform.

  1. Beginner: Add an LED that lights up when temperature exceeds 25°C.
  2. Beginner: Display temperature in Celsius only, or add a button to toggle between Celsius and Fahrenheit.
  3. Intermediate: Add a buzzer alarm that sounds when humidity drops below 30% or rises above 70%.
  4. Intermediate: Create a web server on the ESP32 S3 to display live sensor readings on a smartphone browser.
  5. Advanced: Log temperature and humidity data to an SD card with timestamps for trend analysis.
  6. Advanced: Send sensor data to a cloud platform such as ThingSpeak or Blynk for remote monitoring.
  7. Advanced: Build a complete climate control system that automatically drives a fan and humidifier based on real-time sensor readings.

※ 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!