ESP32 S3 UNO - DHT11

This ESP32 S3 Uno DHT11 tutorial shows you how to wire a DHT11 temperature and humidity sensor to the ESP32 S3 Uno form board and read its data with Arduino code. It works with both the bare 4-pin DHT11 sensor and the 3-pin DHT11 module. You will see the humidity and the temperature in Celsius and Fahrenheit on the Serial Monitor.

In this tutorial, you will:

  1. Learn the pinout of the DHT11 sensor and the DHT11 module.
  2. Wire the DHT11 sensor or module to the ESP32 S3 Uno.
  3. Install the DHT sensor library in the Arduino IDE.
  4. Read temperature and humidity with readTemperature() and readHumidity().
ESP32 S3 Uno DHT11

Hardware Preparation

1×ESP32 S3 Uno-form Board
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×10 kΩ Resistor
1×Breadboard
1×Jumper Wires

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

The DHT11 is a cheap, easy sensor that measures two things at once: air temperature and relative humidity. It sends both values over a single data wire, so it uses only one pin on your board. It is slow but steady, which makes it a good fit for room monitors and simple weather projects.

DHT11
Operating Voltage 3 to 5V
Temperature Range 0°C to 50°C
Temperature Accuracy ± 2°C
Humidity Range 20% to 80%
Humidity Accuracy 5%
Reading Rate 1Hz (once every second)

Pinout

You can buy the DHT11 in two forms: a bare sensor and a small module. Knowing the pins of each one helps you wire it the right way.

DHT11 temperature and humidity sensor Pinout

DHT11 Sensor (4 pins)

The bare sensor has four pins. GND goes to ground (0V). VCC goes to the power supply (3.3V or 5V). DATA carries the readings between the sensor and the ESP32 S3 Uno. NC is not connected, so you can leave it alone.

DHT11 Module (3 pins)

The module has only three pins: GND, VCC and DATA. Some makers print them as -, + and OUT instead. GND goes to ground, VCC goes to the power supply, and DATA goes to an ESP32 S3 Uno pin.

ESP32 S3 Uno Pinout

The image below shows the pinout of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D2, A0, SDA…) and their GPIO numbers while you wire the circuit.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The DATA line of the DHT11 needs a pull-up resistor of 5K to 10K Ohms. This resistor keeps the line high when nobody is talking, so the sensor and the ESP32 S3 Uno can exchange data correctly.

ESP32 S3 Uno - DHT11 Sensor Wiring

With the bare 4-pin sensor, you add the pull-up resistor yourself, between VCC and DATA.

The wiring diagram between ESP32 S3 Uno DHT11 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

DHT11 Sensor Pin ESP32 S3 Uno Pin
VCC 3.3V
DATA D2 (GPIO18), plus 10 kΩ resistor to 3.3V
NC not connected
GND GND

ESP32 S3 Uno - DHT11 Module Wiring

Most DHT11 modules already have the pull-up resistor on the board. So you only need three wires, and no extra parts.

The wiring diagram between ESP32 S3 Uno DHT11 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

DHT11 Module Pin ESP32 S3 Uno Pin
VCC (+) 3.3V
DATA (OUT) D2 (GPIO18)
GND (-) GND

WARNING

The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. Power the DHT11 from 3.3V, so the pull-up resistor holds the DATA line at 3.3V. If you power the DHT11 from 5V, the DATA line goes up to 5V and can damage GPIO18.

How To Program For DHT11 Temperature Sensor

The code is the same for the sensor and the module. Only a few lines from the DHT library do all the work, so it is worth knowing each one.

  1. Include the library.
#include <DHT.h>
  1. Set the ESP32 S3 Uno pin that is connected to the DHT11 DATA pin. D2 on the header is GPIO18, so the code uses 18.
#define DHT11_PIN 18
  1. Create a DHT11 sensor object.
DHT dht11(DHT11_PIN, DHT11);
  1. Start the sensor.
dht11.begin();
  1. Read the humidity.
float humi = dht11.readHumidity();
  1. Read the temperature in Celsius.
float tempC = dht11.readTemperature();
  1. Read the temperature in Fahrenheit.
float tempF = dht11.readTemperature(true);

ESP32 S3 Uno Code - DHT11

The sketch below reads the DHT11 every three seconds. It prints the humidity and the temperature in °C and °F on one line. If a reading fails, it prints an error message instead, so you know to check the wiring.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-dht11 */ #include <DHT.h> #define DHT11_PIN 18 // The ESP32 S3 Uno pin GPIO18 (D2) connected to DHT11 DHT dht11(DHT11_PIN, DHT11); void setup() { Serial.begin(9600); dht11.begin(); // initialize the sensor } void loop() { // wait a few seconds between measurements. delay(3000); // read humidity float humidity = dht11.readHumidity(); // read temperature as Celsius float tempC = dht11.readTemperature(); // read temperature as Fahrenheit float tempF = dht11.readTemperature(true); // check if any reads failed if (isnan(humidity) || isnan(tempC) || isnan(tempF)) { Serial.println("Failed to read from DHT11 sensor!"); } else { Serial.print("DHT11# Humidity: "); Serial.print(humidity); Serial.print("%"); Serial.print(" | "); Serial.print("Temperature: "); Serial.print(tempC); Serial.print("°C ~ "); Serial.print(tempF); Serial.println("°F"); } }

Detailed Instructions

Follow these steps one by one:

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Open the library manager by clicking the Libraries icon on the left side of the Arduino IDE.
  6. Find the library: search for "DHT" and find the DHT sensor library by Adafruit.
  7. Install it by clicking the Install button.
  • 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 the dependencies: the IDE asks for extra libraries. Click the Install All button.
  2. Copy the code above and paste it into the Arduino IDE.
  3. Upload the code by clicking the Upload button.
  4. Open the Serial Monitor and set the baud rate to 9600.
  5. Test it: make the air around the sensor warmer or cooler, for example by holding it in your hand, and watch the values change.
∞
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
DHT11# Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F DHT11# Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F DHT11# Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F DHT11# Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F DHT11# Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F DHT11# Humidity: 32.00% | Temperature: 28.00°C ~ 82.40°F DHT11# Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F DHT11# Humidity: 32.00% | Temperature: 29.00°C ~ 84.20°F
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Tip: the DHT11 is slow and its values change in steps of 1°C and 1%. If you need more precision, try the DHT22 instead.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Should I power the DHT11 from 3.3V or 5V on the ESP32 S3 Uno?

Use 3.3V. The DHT11 works from 3V to 5V, and at 3.3V its DATA line stays at a safe level for the ESP32 S3 Uno. The ESP32 S3 Uno pins are not 5V tolerant, so a 5V pull-up on DATA can damage the pin.

Which ESP32 S3 Uno pin can I use for the DHT11?

Almost any digital pin works. This tutorial uses D2, which is GPIO18, so the code says 18. If you move the wire, change DHT11_PIN to the GPIO number of the new pin, not the D label. Avoid D6 (GPIO3) and D9 (GPIO46) because they are boot strapping pins.

Why does the Serial Monitor show "Failed to read from DHT11 sensor!"?

The library could not get a valid answer from the sensor. Most often the DATA wire is on the wrong pin, the pull-up resistor is missing on a bare sensor, or the sensor has no power. Check the wiring and make sure DHT11_PIN matches the GPIO you used.

Is the code different from the UNO R4 code?

Only the pin number changes. The UNO R4 code uses pin 2, while the ESP32 S3 Uno code uses 18, because D2 on this board is GPIO18. The Adafruit DHT library works on both boards.

How often can I read the DHT11?

The DHT11 gives a new reading about once per second. The sketch waits three seconds between reads to keep the values stable. Reading faster does not give new data and can cause failed reads.

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 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them and write the GPIO number in code. A second DHT11 fits well on GPIO15, GPIO16 or GPIO35 to GPIO42, but not on GPIO47/GPIO48, because the DHT11 DATA line needs an input. Be careful with two things. First, GPIO47/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. Second, 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.

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 you press RESET
Upload fails with a timeout error Wrong board selected Select ESP32S3 Dev Module and the correct COM port, then upload again
"Failed to read from DHT11 sensor!" DATA wire on the wrong pin or loose wire Connect DATA to D2 (GPIO18) and make sure DHT11_PIN is 18
Readings fail with the bare sensor No pull-up resistor on DATA Add a 5K to 10K Ohm resistor between VCC and DATA
Board resets or pin acts strange DHT11 powered from 5V so DATA is at 5V Power the DHT11 from 3.3V
Compile error DHT.h not found Library not installed Install the DHT sensor library by Adafruit and the Adafruit Unified Sensor library
Strange characters on Serial Monitor Wrong baud rate Set the Serial Monitor to 9600 baud
Values do not change or look wrong Reading too fast or sensor near a heat source Keep at least 1 second between reads and move the sensor away from the board and other warm parts

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