Arduino UNO R4 - DHT11

In this guide, we will learn how to use DHT11 temperature and humidity sensor with Arduino UNO R4. In detail, we will learn:

Arduino UNO R4 and DHT11 sensor module

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×DHT11 Temperature Humidity Sensor Module
1×10 kΩ resistor
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4
1×(Recommended) Power Splitter For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
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

DHT11
Operating Voltage3 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

The DHT11 is available in two types: sensor and module.

DHT11 temperature and humidity sensor Pinout

The DHT11 sensor has four pins.

  • GND pin: connect to GND (0V)
  • VCC pin: connect to VCC (5V or 3.3V)
  • DATA pin: used for communication between the sensor and Arduino UNO R4
  • NC pin: not connected, can be ignored

The DHT11 module has three pins.

  • GND pin: connect to GND (0V).
  • VCC pin: connect to VCC (5V or 3.3V).
  • DATA pin: used for communication between the sensor and Arduino UNO R4.

Some makers offer the DHT11 sensor as a module with three pins labeled: GND, VCC, and DATA (or sometimes as -, +, and OUT).

Wiring Diagram

To connect the DHT11 sensor to the Arduino UNO R4, use a resistor between 5K and 10K Ohms. This resistor helps maintain the data line high, allowing the sensor and the Arduino to communicate properly.

Arduino UNO R4 - DHT11 Sensor Wiring

The wiring diagram between Arduino UNO R4 DHT11 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 - DHT11 Module Wiring

Most DHT11 sensor modules come with a built-in resistor, so there's no need to add one. This makes wiring or soldering easier.

The wiring diagram between Arduino UNO R4 DHT11 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

How To Program For DHT11 Temperature Sensor

Programming for both sensor and module is the same.

  • Include the library.
#include <DHT.h>
  • Set the pin on the Arduino UNO R4 that connects to the DHT sensor:
#define DHT11_PIN 2
  • Create a DHT11 sensor object.
DHT dht11(DHT11_PIN, DHT11);
  • Start the sensor:
dht11.begin();
  • Read humidity value:
float humi = dht11.readHumidity();
  • Read the temperature in Celsius:
float tempC = dht11.readTemperature();
  • Read the temperature in Fahrenheit.
float tempF = dht11.readTemperature(true);

Arduino UNO R4 Code - DHT11

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-dht11 */ #include <DHT.h> #define DHT11_PIN 2 // The Arduino UNO R4 pin 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 instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Click on the Libraries icon on the left side of the Arduino IDE.
  • Search for "DHT" and locate the DHT sensor library by Adafruit.
  • Click the Install button to add the library.
Arduino UNO R4 DHT sensor library
  • You need to install additional library dependencies
  • Click the Install All button to install all the necessary libraries.
Arduino UNO R4 Adafruit Unified sensor library
  • Copy the code for your sensor and open it in the Arduino IDE.
  • Press the Upload button in the Arduino IDE to upload the code to the Arduino UNO R4.
  • Change the temperature around the sensor to warmer or cooler.
  • Check the results on the Serial Monitor.
COM6
Send
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: 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: 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 DHT11# Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

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