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:
- How to connnect the DHT11 sensor and DHT11 module to Arduino UNO R4.
- How to write a program for Arduino UNO R4 to receive temperature and humidity data from the DHT11 sensor and module.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of DHT11 Temperature and Humidity Sensor
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
The DHT11 is available in two types: sensor and module.
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
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.
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.
- Set the pin on the Arduino UNO R4 that connects to the DHT sensor:
- Create a DHT11 sensor object.
- Start the sensor:
- Read humidity value:
- Read the temperature in Celsius:
- Read the temperature in Fahrenheit.
Arduino UNO R4 Code - DHT11
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.
- You need to install additional library dependencies
- Click the Install All button to install all the necessary libraries.
- 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.