In the realm of DIY electronics and Arduino projects, the DHT11 sensor holds a special place. This simple yet powerful sensor is capable of measuring both temperature and humidity, providing critical data for various applications, from home automation systems to weather stations.
In this article, we will guide you through the process of connecting a DHT11 sensor with an Arduino. We will cover everything from the basic connection of the sensor to the Arduino board, to installing necessary libraries in the Arduino IDE, and finally writing and uploading the code to start receiving data from your sensor.
What Is A DHTT Sensor?
Relative humidity (RH) is a measure of the amount of water vapor present in the air compared to the maximum amount of water vapor the air can hold at a given temperature. The DHT11 sensor provides this information as a percentage, where 0% RH indicates very dry air, and 100% RH indicates saturated air where condensation may occur.
The DHT11 sensor can be interfaced with microcontrollers and Arduino boards, making it a popular choice for DIY projects and environmental monitoring applications where measuring humidity and temperature is important. It provides a relatively simple way to obtain humidity and temperature data for various purposes.
Inside the DHT11 Sensor:
DHT11 Module Parts
The DHT11 sensor module typically consists of the following key components:
- Humidity and Temperature Sensor: This is the primary sensor element within the DHT11 module responsible for measuring humidity and temperature. It usually contains a moisture-sensitive component to measure humidity and a temperature-sensitive component to measure temperature;
- Signal Conditioning Circuitry: The sensor’s output is analog in nature, and the module includes signal conditioning circuitry to convert the analog signals into digital signals that can be read by a microcontroller or other digital devices;
- Microcontroller: Many DHT11 modules include a microcontroller to process the sensor data and provide a digital output. This microcontroller is often embedded within the module;
DHT11 Module Pinout
The DHT11 module typically has four pins, and the pinout is as follows:
- VCC (Voltage Supply): This pin is connected to the power supply, typically 3.3V or 5V, depending on the module’s specifications;
- Data (Signal Output): The digital humidity and temperature data is read from this pin. It’s the pin that communicates with the microcontroller to transmit the sensor’s readings;
- NC (Not Connected): Some DHT11 modules may have an additional pin that is not used or connected to anything. It’s labeled as “NC” and can be left unconnected;
- GND (Ground): This pin is connected to the ground or 0V reference of the power supply [2];
DHT11 Module Circuit Diagram
The circuit diagram for the DHT11 module typically includes the connections.
The VCC and GND pins are connected to the appropriate power supply and ground connections, and the Data pin is connected to a digital input pin on a microcontroller or another device to read the sensor’s output data. The microcontroller then processes the data to obtain temperature and humidity readings from the DHT11 sensor module.
How Does the DHT11 Measures Humidity and Temperature?
The DHT11 sensor is a basic, ultralow-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air. The sensor provides humidity values in percentage of relative humidity (20 to 90% RH) and temperature values in degrees Celsius (0 to 50 °C).
The temperature measurement is carried out by a thermistor, a type of resistor whose resistance changes significantly with temperature. The DHT11 measures the resistance of the thermistor and converts it into temperature data.
For humidity, the DHT11 uses a capacitive humidity sensor. Capacitive humidity sensors measure relative humidity by placing a thin strip of metal oxide between two electrodes. The metal oxide’s electrical capacity changes with the atmosphere’s humidity levels and these changes are converted into humidity readings.
The sensor gives a calibrated digital signal output of the temperature and humidity measurements, which can be easily read using a microcontroller.
In terms of applications, this sensor is utilized in various areas such as measuring humidity and temperature values in heating, ventilation, and air conditioning systems, weather stations, home automation systems, and more.
How Can It Be Used With an Arduino?
The DHT11 sensor can be easily interfaced with an Arduino microcontroller to create a variety of temperature and humidity monitoring applications.
Here’s a basic outline of how you can use the DHT11 with an Arduino:
- Connect the Sensor to the Arduino: The DHT11 sensor has three pins: VCC, GND, and Data. Connect the VCC pin to the 5V power supply on the Arduino, the GND pin to the ground, and the Data pin to any digital I/O pin on the Arduino;
- Install the DHT Library in Arduino IDE: To simplify the programming, it’s recommended to use the DHT library, which can be installed via the library manager in the Arduino IDE;
- Write the Code: With the library installed, you can write the Arduino code to read data from the DHT11 sensor. The DHT library provides functions for reading temperature and humidity data from the sensor;
- Upload and Run the Code: Once your code is written, upload it to the Arduino board. If everything is connected correctly, the Arduino should start reading temperature and humidity data from the DHT11 sensor and output it to the serial monitor [3];
Interface DHT11 Using Arduino:
Components Required:
- Arduino Board (e.g., Arduino Uno): This will be the microcontroller that reads data from the DHT11 sensor and processes it;
- DHT11 Sensor Module: The sensor itself with its pins labeled as VCC, Data, and GND;
- Breadboard and Jumper Wires: These are used for making electrical connections between the components;
Wiring the Circuit:
Connect the DHT11 sensor module to the Arduino as follows:
- Connect the VCC pin of the DHT11 to the 5V output of the Arduino;
- Connect the GND pin of the DHT11 to the GND (0V) output of the Arduino;
- Connect the Data pin of the DHT11 to a digital input/output pin on the Arduino (e.g., Digital Pin 2);
- Ensure that all connections are secure and correctly made;
Programming the Arduino:
Now, you need to write the Arduino code to read data from the DHT11 sensor and display it.
Here’s a simple example sketch to get you started:
#include <DHT.h>
// Define the type of sensor (DHT11 or DHT22)
#define DHTTYPE DHT11
// Define the pin to which the data pin of the DHT11 is connected
#define DHTPIN 2
// Create a DHT object
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Read humidity value from the sensor
float humidity = dht.readHumidity();
// Read temperature value from the sensor in Celsius
float temperature = dht.readTemperature();
// Check if any read failed and exit early (to try again)
if (isnan(humidity) || isnan(temperature)) {
Serial.println(“Failed to read from DHT sensor!”);
delay(2000);
return;
}
// Print humidity and temperature values to the serial monitor
Serial.print(“Humidity: “);
Serial.print(humidity);
Serial.print(“%\t”);
Serial.print(“Temperature: “);
Serial.print(temperature);
Serial.println(“°C”);
// Wait a few seconds before reading the sensor again
delay(2000);
}
Here’s a breakdown of what the code does:
- It includes the necessary library for the DHT sensor;
- Defines the sensor type (DHT11), the pin to which the sensor’s data pin is connected, and creates a DHT object;
- In the setup() function, it initializes serial communication for debugging and sets up the DHT sensor;
- In the loop() function, it reads humidity and temperature values from the sensor, checks for reading failures, and then prints the values to the serial monitor;
- Upload this code to your Arduino, open the Serial Monitor, and you should see the humidity and temperature readings from the DHT11 sensor displayed in the monitor [4];
How to Connect DHT11 Sensor with Arduino UNO:
Installing the Required Arduino Libraries
Before we dive into connecting the DHT11 sensor, it’s essential to ensure that you have the necessary Arduino libraries installed. These libraries simplify the process of interfacing with the sensor and extracting data.
To install the DHT library, follow these steps:
- Open the Arduino IDE on your computer;
- Navigate to the “Sketch” menu, select “Include Library”, and then click on “Manage Libraries”;
- In the Library Manager window, type “DHT” into the search bar;
- Look for the “DHT sensor library” by Adafruit and click the “Install” button;
With the library installed, you’re now ready to interface the DHT11 sensor with your Arduino Uno.
Interfacing Arduino with DHT11 Sensor:
DHT11 Sensor Pinout:
- VCC (Voltage Supply) – Connect this to the 5V output on the Arduino Uno;
- GND (Ground) – Connect this to one of the GND (0V) pins on the Arduino;
- DATA – Connect this to a digital input/output pin on the Arduino (e.g., Digital Pin 2) [5];
Hardware:
- Connect the VCC pin of the DHT11 sensor to the 5V output on your Arduino Uno;
- Connect the GND pin of the DHT11 sensor to any of the GND (0V) pins on your Arduino;
- Finally, connect the DATA pin of the DHT11 sensor to a digital input/output pin on your Arduino Uno. In our example, we’ll use Digital Pin 2, but you can choose any other suitable digital pin;
Code
With the hardware connections in place, it’s time to write the code that reads data from the DHT11 sensor.
#include <DHT.h>
#define DHTPIN 2 // Define the digital pin to which the DHT11 data pin is connected.
#define DHTTYPE DHT11 // Define the type of sensor (DHT11 or DHT22).
DHT dht(DHTPIN, DHTTYPE); // Create a DHT object.
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging.
dht.begin(); // Initialize the DHT sensor.
}
void loop() {
delay(2000); // Wait a few seconds between readings.
float humidity = dht.readHumidity(); // Read humidity value from the sensor.
float temperature = dht.readTemperature(); // Read temperature value from the sensor.
Serial.print(“Humidity: “);
Serial.print(humidity);
Serial.print(“%\t”);
Serial.print(“Temperature: “);
Serial.print(temperature);
Serial.println(“°C”);
}
Output
When you upload the code to your Arduino Uno and open the Serial Monitor (baud rate set to 9600), you’ll start seeing the humidity and temperature values being printed [6].
The sensor will read the data every two seconds (as specified by the delay) and display it on the Serial Monitor.
You’ve now successfully connected a DHT11 sensor to your Arduino Uno and extracted humidity and temperature data. This is a fundamental step in various projects involving environmental monitoring and automation.
How to Set Up the DHT11 on an Arduino:
Connecting a Three-Pin DHT11
The DHT11 sensor comes in two variants: three-pin and four-pin. We’ve covered the four-pin variant in the previous section.
Hardware Connections:
- Connect the VCC pin of the three-pin DHT11 sensor to the 5V output on your Arduino Uno;
- Connect the GND pin of the sensor to any of the GND (0V) pins on your Arduino;
- Connect the DATA pin of the sensor to a digital input/output pin on your Arduino (e.g., Digital Pin 2);
Connecting a Four-Pin DHT11
For the four-pin DHT11 sensor, you can follow the hardware connections described in the previous section:
Display Humidity and Temperature on the Serial Monitor
Whether you’re using a three-pin or four-pin DHT11 sensor, the code for displaying humidity and temperature on the Serial Monitor remains the same as the example provided earlier. You can refer to the code and follow the setup process to start receiving data on your computer.
Display Humidity and Temperature on an LCD
To take your project a step further, you can connect an LCD (Liquid Crystal Display) to your Arduino Uno to directly display humidity and temperature values on the screen. You’ll need an LCD module and appropriate libraries to achieve this. The process involves initializing the LCD, setting up its pins, and updating the display with the sensor data.
Using the Data in Other Programs
FAQ:
1. What does a DHT11 do?
The DHT11 is a sensor that measures temperature and relative humidity in the air. It provides digital output data, making it easy to interface with microcontrollers like Arduino for various applications, including weather monitoring, home automation, and environmental sensing.
2. How accurate is DHT11?
The DHT11 sensor is relatively inexpensive but has limited accuracy compared to more advanced sensors. It typically has an accuracy of ±2°C for temperature and ±5% for relative humidity [8]. While it may not be suitable for highly precise applications, it is suitable for many hobbyist and educational projects.
3. Is the DHT11 waterproof?
No, the DHT11 sensor is not waterproof. It is a sensitive electronic component, and exposure to moisture or water can damage it. If you need a waterproof version, you should consider sensors designed for such environments.
4. What’s the sampling rate of a DHT11 sensor?
The DHT11 sensor is not designed for high-speed applications. It has a relatively slow sampling rate, typically around 1 Hz, meaning it can provide a new reading approximately once every second [9].
5. How to read the DHT11 sensor in Arduino?
To read a DHT11 sensor in Arduino, you need to use a library like the Adafruit DHT library. You’ll need to connect the sensor to your Arduino and then use the library to read temperature and humidity data.
6. How to connect DHT11 to Arduino Nano?
The connection process for a DHT11 sensor to an Arduino Nano is the same as with other Arduino boards, such as the Arduino Uno. You can follow the wiring instructions and code example provided in the earlier response for the Arduino Uno.
7. How to connect DHT11 to Arduino Mega?
The connection process for a DHT11 sensor to an Arduino Mega is also the same as with other Arduino boards. You can use the same wiring instructions and code example mentioned earlier for the Arduino Uno.
8. Is DHT11 3.3V or 5V?
The DHT11 sensor can operate on both 3.3V and 5V power supplies, making it versatile and compatible with a wide range of Arduino boards. You can choose the voltage supply according to your specific application and the voltage levels supported by your Arduino board.
9. How do you set up a DHT11 sensor?
Setting up a DHT11 sensor involves connecting its pins (VCC, GND, DATA) to an Arduino or microcontroller, installing the necessary library, and writing code to read and display the sensor data [10].
10. What voltage for DHT11 Arduino?
You can use either 3.3V or 5V as the voltage supply for a DHT11 sensor when connecting it to an Arduino, depending on your specific application and Arduino board capabilities.
11. What is the pin of DHT11?
The DHT11 sensor typically has three pins: VCC (power supply), GND (ground), and DATA (digital data output). These pins are used for connecting the sensor to an Arduino or other microcontroller.
12. What is the DHT11 sensor 4-pin in Arduino?
The four-pin DHT11 sensor uses the same pins as the three-pin version when interfacing with an Arduino. The additional pin is not connected to the Arduino and is typically left unconnected. The important pins are VCC, GND, and DATA.
13. Is the DHT11 digital or analog?
The DHT11 sensor provides digital output. It communicates temperature and humidity readings in digital form, making it easy to interface with digital pins on microcontrollers like Arduino.
14. Is DHT11 input or output?
The DHT11 sensor is an input device. It senses temperature and humidity in the environment and provides digital output data that can be read by a microcontroller or other devices.
15. Does DHT11 need a resistor?
The DHT11 sensor doesn’t require an external pull-up resistor when used with most microcontrollers, as it already has an internal pull-up resistor. You can directly connect it to your microcontroller without additional resistors.
16. Does DHT11 need calibration?
DHT11 sensors are factory-calibrated, and they generally do not require user calibration [11]. However, if high precision is essential for your application, you may want to calibrate the sensor by comparing its readings with a calibrated reference.
17. Can DHT11 measure temperature?
Yes, the DHT11 sensor is designed to measure temperature along with relative humidity. It provides both temperature and humidity readings.
18. How many Celsius is Arduino DHT11?
The DHT11 sensor provides temperature readings in degrees Celsius (°C). It is the default temperature unit used by the sensor when you read temperature data.
19. Is the DHT11 sensor waterproof?
No, the DHT11 sensor is not waterproof. It is sensitive to moisture, and exposure to water or high humidity can damage the sensor. If you need a waterproof sensor, you should consider other options specifically designed for such conditions.
20. Which protocol is used for the DHT11 sensor?
The DHT11 sensor uses a proprietary single-wire communication protocol to transmit data to the microcontroller. The Arduino library (e.g., Adafruit DHT library) handles the protocol details, making it easy to use with Arduino and similar platforms.
Useful Video: DHT11 Temperature & Humidity sensor with Arduino – Tutorial
References:
- https://lastminuteengineers.com/dht11-module-arduino-tutorial/
- https://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/
- https://circuitdigest.com/microcontroller-projects/interfacing-dht11-sensor-with-arduino
- https://startingelectronics.org/beginners/arduino-tutorial-for-beginners/arduino-DHT11-sensor-tutorial/
- https://linuxhint.com/dht11-temperature-humidity-sensor-arduino/
- https://www.instructables.com/Interface-DHT11-Using-Arduino/
- https://projecthub.arduino.cc/arcaegecengiz/using-dht11-12f621
- https://www.electronicwings.com/arduino/dht11-sensor-interfacing-with-arduino-uno
- https://electronicsprojectshub.com/setup-dht11-sensor-with-arduino/
- https://www.electroduino.com/interfacing-dht11-with-arduino-dht11-temperature-and-humidity-sensor-arduino-code/
- https://srituhobby.com/how-does-work-dht-11-sensor-with-the-arduino/