ESP32 S3 UNO - DHT22
This ESP32 S3 Uno DHT22 tutorial shows you how to wire a DHT22 temperature and humidity sensor to the ESP32 S3 Uno form board and read it with Arduino code. You can use the bare 4-pin DHT22 sensor or the 3-pin DHT22 module. The sketch prints the humidity and the temperature in Celsius and Fahrenheit to the Serial Monitor.
In this tutorial, you will:
- Learn the DHT22 sensor pinout and its main specs
- Wire a DHT22 sensor (with a pull-up resistor) to the ESP32 S3 Uno
- Wire a DHT22 module with a built-in resistor
- Install the DHT sensor library in the Arduino IDE
- Read temperature and humidity with readTemperature() and readHumidity()

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of DHT22 Temperature and Humidity Sensor
The DHT22 measures both temperature and humidity in one small package, and it sends the result over a single data wire. It is more accurate and has a wider range than the cheaper DHT11, so it is a good choice for weather stations, greenhouses and room monitors.
| DHT22 | |
|---|---|
| Temperature Range | -40°C to 80°C |
| Temperature Accuracy | ± 0.5°C |
| Humidity Range | 0% to 100% |
| Humidity Accuracy | ± 2 to 5% |
| Reading Rate | 0.5Hz (once every 2 seconds) |
| Operating Voltage | 3 to 5V |
The DHT22 is a slow sensor. It gives a new reading only about once every 2 seconds, so do not read it faster than that.
Pinout
You can buy the DHT22 in two forms: the bare sensor and the module. Both work the same way in code. The only difference is the number of pins and the pull-up resistor.

DHT22 sensor (4 pins)
The bare sensor has four pins. GND goes to GND (0V). VCC goes to the power pin (3.3V or 5V). DATA is the single wire the sensor uses to talk to the ESP32 S3 Uno. NC is not connected, so you can leave it alone.
DHT22 module (3 pins)
The module has only three pins: GND, VCC and DATA. Some makers label them -, + and OUT instead. Most modules already have the pull-up resistor on the board.
ESP32 S3 Uno Pinout
The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the D2, 3.3V and GND header pins and their GPIO numbers when you wire the DHT22.

Wiring Diagram
The DATA line needs a pull-up resistor between 5K and 10K Ohms. It keeps the line HIGH when nobody is talking, so the sensor and the ESP32 S3 Uno can exchange data reliably.
ESP32 S3 Uno - DHT22 Sensor Wiring
With the bare sensor, you add the resistor yourself between the DATA pin and VCC.

This image is created using Fritzing. Click to enlarge image
| DHT22 Sensor Pin | ESP32 S3 Uno Pin |
|---|---|
| VCC | 3.3V |
| DATA | D2 (GPIO18), plus a 10K resistor to 3.3V |
| NC | not connected |
| GND | GND |
ESP32 S3 Uno - DHT22 Module Wiring
Most DHT22 modules have the resistor built in, so you only need three wires. This saves you some wiring or soldering.

This image is created using Fritzing. Click to enlarge image
| DHT22 Module Pin | ESP32 S3 Uno Pin |
|---|---|
| VCC (+) | 3.3V |
| DATA (OUT) | D2 (GPIO18) |
| GND (-) | GND |
WARNING
ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. The pull-up resistor pulls the DATA line up to the same voltage as VCC. If you power the DHT22 from 5V, the DATA line goes to 5V and can damage GPIO18. Power the sensor or module from the 3.3V pin. The DHT22 works fine from 3.3V.
How To Program For DHT22 Temperature Sensor
The code is the same for the sensor and the module. The Adafruit DHT library does the hard timing work, so you only need a few calls.
- Include the library.
- Define the ESP32 S3 Uno pin that is connected to the DATA pin. D2 is GPIO18, and in code you always write the GPIO number.
- Create a DHT object for the DHT22.
- Start the sensor in setup().
- Read the humidity in percent.
- Read the temperature in Celsius.
- Read the temperature in Fahrenheit by passing true.
ESP32 S3 Uno Code - DHT22
The sketch below reads the DHT22 every 3 seconds. It prints the humidity and the temperature in both Celsius and Fahrenheit. If a reading fails, the library returns NaN, and the code prints an error message instead of wrong numbers.
Detailed Instructions
Follow these steps in order:
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram. Use the 3.3V pin for VCC.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Open the Library Manager by clicking the Libraries icon on the left side of the Arduino IDE.
- Find the library. Type "DHT" in the search box and look for the DHT sensor library by Adafruit.
- Install it by clicking the Install button.
- Search for DHT sensor library created by Adafruit and click the Install button.
- Install the dependencies. The IDE asks to add other libraries. Click Install All.
- Copy the code above and paste it into the Arduino IDE.
- Upload the code by clicking the Upload button.
- Open the Serial Monitor and set the baud rate to 9600.
- Test it. Warm the sensor with your hand or breathe near it, and watch the values change.
- Tip: Humidity changes faster than temperature. Breathe gently on the sensor and you will see the humidity jump within a few seconds.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
FAQ
Can I power the DHT22 from 5V on the ESP32 S3 Uno?
The DHT22 itself works from 3 to 5V, but on the ESP32 S3 Uno you should use 3.3V. The pull-up resistor pulls the DATA line up to VCC, so a 5V supply puts 5V on the GPIO pin. ESP32 S3 Uno pins are not 5V tolerant and can be damaged.
Which ESP32 S3 Uno pin should I use for the DHT22 DATA line?
This tutorial uses D2, which is GPIO18. Any normal digital pin works, such as D4 (GPIO19), D5 (GPIO20) or D7 (GPIO14). Just change the number in #define DHT22_PIN. Avoid D6 (GPIO3) and D9 (GPIO46), because they are boot strapping pins.
Why do I see "Failed to read from DHT22 sensor!"?
The library could not get valid data from the sensor. Most of the time the DATA wire is on the wrong pin, the pull-up resistor is missing on a bare sensor, or the sensor has no power. Reading faster than once every 2 seconds can also cause failed reads.
Is the code different from the UNO R4 version?
The logic is the same and it uses the same Adafruit DHT library. The only change is the pin number: on the UNO R4 you write 2, and on the ESP32 S3 Uno you write the GPIO number 18 for the D2 header pin.
What if my project needs more pins than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 support I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 support I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For extra DHT22 sensors, use GPIO15, GPIO16 or GPIO35 to GPIO42, because the DATA line is both input and output, so GPIO47/GPIO48 will not work. Two warnings: GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
Can I use a DHT11 instead of a DHT22?
Yes. Wire it the same way and change DHT22 to DHT11 in the DHT object. The DHT11 is cheaper but less accurate, has a smaller range, and reads only once per second.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | USB driver missing or board not in upload mode | Install the CP210x or CH340 driver, use a data USB cable, or hold BOOT while pressing RESET |
| Failed to read from DHT22 sensor | Wrong DATA pin or no power | Check that DATA is on D2 (GPIO18) and VCC is on 3.3V, and that the code uses 18 |
| Readings fail now and then | Missing pull-up resistor on the bare sensor | Add a 5K to 10K resistor between DATA and 3.3V |
| Values are always NaN after a fast loop | Reading faster than the sensor allows | Keep at least 2 seconds between readings |
| Compile error DHT.h not found | Library not installed | Install DHT sensor library by Adafruit and the Adafruit Unified Sensor library |
| Strange characters in Serial Monitor | Wrong baud rate | Set the Serial Monitor to 9600 baud |
| Board resets or GPIO stops working | Sensor powered from 5V so DATA is at 5V | Move VCC to the 3.3V pin to keep the DATA line at 3.3V |
| Temperature reads a few degrees too high | Sensor too close to the board or a warm part | Place the sensor a few cm away from the board and other heat sources |