Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
DHT11 Arduino Tutorial: Complete Guide to Temperature and Humidity Sensing
When clients ask me to add environmental monitoring to their PCB designs, the DHT11 Arduino combination is often my first recommendation for prototypes and budget-conscious projects. This sensor has earned its reputation in the maker community for good reason: it measures both temperature and humidity through a single data wire, costs less than a cup of coffee, and integrates seamlessly with Arduino boards.
Having worked with dozens of temperature and humidity sensors over the years, I appreciate the DHT11’s simplicity. Yes, more accurate options exist, but for learning projects, home automation experiments, and non-critical monitoring applications, the DHT11 delivers solid value. This tutorial walks you through everything needed to get reliable readings from your DHT11 Arduino setup, from understanding the sensor internals to troubleshooting those frustrating “Failed to read” errors.
Understanding the DHT11 Sensor Technology
Before wiring anything, understanding how the DHT11 actually works helps you avoid common pitfalls and interpret readings correctly.
How DHT11 Measures Humidity
The DHT11 uses a resistive humidity sensing element. Inside the blue plastic housing, there’s a moisture-absorbing substrate sandwiched between two electrodes. When ambient humidity changes, the substrate absorbs or releases water vapor, which alters its electrical resistance. Higher humidity decreases the resistance between electrodes, while drier conditions increase it.
An 8-bit microcontroller inside the sensor converts this resistance measurement into a calibrated digital humidity value. This internal processor handles all the analog-to-digital conversion, so your Arduino receives clean digital data rather than raw analog signals that would need calibration.
How DHT11 Measures Temperature
Temperature sensing happens through an NTC (Negative Temperature Coefficient) thermistor integrated into the sensor package. As temperature rises, the thermistor’s resistance decreases in a predictable, non-linear fashion. The internal microcontroller linearizes this response and outputs calibrated temperature values.
The factory calibration is a significant advantage for hobbyists. Unlike raw thermistors that require manual calibration curves, the DHT11 outputs ready-to-use temperature readings in degrees Celsius.
DHT11 Technical Specifications
Understanding the specifications helps you determine whether the DHT11 fits your project requirements.
Parameter
DHT11 Specification
Operating Voltage
3.3V to 5.5V DC
Operating Current
0.3mA (measuring), 60μA (standby)
Peak Current
2.5mA (during data transmission)
Temperature Range
0°C to 50°C
Temperature Accuracy
±2°C
Humidity Range
20% to 80% RH
Humidity Accuracy
±5% RH
Sampling Rate
1 Hz (once per second maximum)
Data Interface
Single-wire digital
Body Dimensions
15.5mm × 12mm × 5.5mm
The 0°C to 50°C temperature range and 20% to 80% humidity range work fine for indoor applications. For outdoor weather stations, greenhouses with extreme conditions, or industrial monitoring, consider the DHT22 which offers wider measurement ranges and better accuracy.
DHT11 Pinout and Configuration
The DHT11 comes in two forms: a bare 4-pin sensor and a 3-pin module with integrated pull-up resistor and filtering capacitor.
4-Pin DHT11 Sensor Pinout
Pin Number
Name
Function
1
VCC
Power supply (3.3V to 5.5V)
2
DATA
Digital data output
3
NC
Not connected (leave floating)
4
GND
Ground
When using the bare 4-pin sensor, you must add an external pull-up resistor (4.7kΩ to 10kΩ) between the DATA pin and VCC. This resistor maintains the data line at a known high state when the sensor isn’t actively transmitting.
3-Pin DHT11 Module Pinout
Pin
Label
Function
1
S or DATA
Digital data output
2
+ or VCC
Power supply
3
– or GND
Ground
The module version includes the pull-up resistor and a bypass capacitor on a small PCB, making wiring simpler. Module pin order varies between manufacturers, so always verify your specific module’s pinout before connecting.
Wiring DHT11 to Arduino
Proper wiring is critical for reliable DHT11 Arduino operation. Many troubleshooting issues trace back to connection problems.
Components Required
Component
Quantity
Notes
Arduino Uno/Nano/Mega
1
Any Arduino-compatible board works
DHT11 Sensor or Module
1
Module simplifies wiring
10kΩ Resistor
1
Only needed for bare 4-pin sensor
Breadboard
1
For prototyping
Jumper Wires
3-4
Male-to-male for breadboard
DHT11 Module Wiring (3-Pin)
For the common 3-pin module, connections are straightforward:
DHT11 Module Pin
Arduino Pin
VCC (+)
5V
DATA (S)
Digital Pin 2
GND (-)
GND
Bare DHT11 Sensor Wiring (4-Pin)
When using the 4-pin sensor without a module PCB:
DHT11 Sensor Pin
Connection
Pin 1 (VCC)
Arduino 5V
Pin 2 (DATA)
Arduino Digital Pin 2 + 10kΩ resistor to 5V
Pin 3 (NC)
Leave unconnected
Pin 4 (GND)
Arduino GND
The pull-up resistor connects between Pin 2 (DATA) and Pin 1 (VCC), ensuring stable communication. Without this resistor, you’ll experience intermittent read failures.
Installing DHT11 Arduino Libraries
The Arduino IDE requires external libraries to communicate with the DHT11. Two popular options exist, and I recommend the Adafruit library for its reliability and active maintenance.
Installing the Adafruit DHT Library
Step 1: Open Arduino IDE and navigate to Sketch → Include Library → Manage Libraries
Step 2: In the Library Manager search box, type “DHT sensor library”
Step 3: Find “DHT sensor library by Adafruit” and click Install
Step 4: When prompted to install dependencies, click “Install All” to also install the Adafruit Unified Sensor library
The Adafruit Unified Sensor library provides standardized sensor interfaces that the DHT library depends on. Skipping this dependency causes compilation errors with the message “Adafruit_Sensor.h: No such file or directory.”
Alternative: SimpleDHT Library
For simpler projects or when memory is constrained, the SimpleDHT library offers a lighter-weight alternative. Search “SimpleDHT” in Library Manager and install it. This library doesn’t require the Unified Sensor dependency.
DHT11 Arduino Code Examples
With hardware connected and libraries installed, you can start reading temperature and humidity values.
Basic DHT11 Arduino Sketch
This code reads temperature and humidity, displaying results on the Serial Monitor:
#include “DHT.h”
#define DHTPIN 2 // Digital pin connected to DHT11
#define DHTTYPE DHT11 // Specify sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(“DHT11 Temperature & Humidity Sensor”);
The dht.begin() function initializes communication with the sensor. The readHumidity() and readTemperature() functions return float values representing the current measurements. Passing true to readTemperature() returns Fahrenheit instead of Celsius.
The isnan() check is crucial. When the sensor fails to respond or returns corrupted data, these functions return NaN (Not a Number). Without this validation, your code would display meaningless values.
The 2-second delay between readings respects the DHT11’s sampling rate limitation. While the sensor technically supports 1 Hz sampling, allowing extra time improves reliability.
Displaying DHT11 Data on LCD
For standalone projects without serial monitoring, an I2C LCD provides visual feedback:
#include “DHT.h”
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
lcd.clear();
lcd.print(“Sensor Error!”);
return;
}
lcd.setCursor(0, 0);
lcd.print(“Temp: “);
lcd.print(t, 1);
lcd.print((char)223); // Degree symbol
lcd.print(“C”);
lcd.setCursor(0, 1);
lcd.print(“Humidity: “);
lcd.print(h, 0);
lcd.print(“%”);
}
Troubleshooting DHT11 Arduino Problems
After helping numerous colleagues debug their DHT11 projects, I’ve compiled the most common issues and their solutions.
Problem: “Failed to Read from DHT Sensor” or NaN Values
Causes and Solutions:
Cause
Solution
Incorrect wiring
Verify VCC connects to 5V, GND to ground, DATA to correct pin
Missing pull-up resistor
Add 4.7kΩ-10kΩ resistor between DATA and VCC (bare sensor only)
Wrong sensor type in code
Ensure DHTTYPE DHT11 is defined, not DHT22
Insufficient power
Power sensor from 5V instead of 3.3V
Sampling too fast
Increase delay between readings to at least 2 seconds
Defective sensor
Try a different DHT11; cheap sensors sometimes arrive dead
Problem: Readings Show 0.00 for Both Values
This typically indicates the sensor isn’t responding at all. Check that:
The DATA pin number in your code matches the physical connection. A common mistake is confusing Arduino pin numbers with physical board positions.
The sensor receives power. Use a multimeter to verify 5V between VCC and GND at the sensor.
Problem: Readings are Inaccurate
The DHT11’s ±2°C temperature accuracy and ±5% humidity accuracy mean some variation from reference instruments is expected. However, significantly wrong readings suggest:
The sensor needs stabilization time. After powering on, wait 1-2 minutes before trusting readings.
Environmental factors affect the sensor. Avoid placing it near heat sources, direct sunlight, or HVAC vents.
Long wire runs introduce noise. Keep wiring under 20-30cm for reliable communication.
Problem: Intermittent Failures
Sporadic read failures often stem from electrical noise or marginal connections. Adding a 100nF ceramic capacitor between VCC and GND near the sensor filters power supply noise. Also verify all connections are secure; loose breadboard contacts cause mysterious intermittent behavior.
DHT11 vs DHT22 Comparison
When the DHT11’s limitations become problematic, the DHT22 offers improved specifications at higher cost.
Specification
DHT11
DHT22
Price
~$1-2
~$4-6
Temperature Range
0°C to 50°C
-40°C to 80°C
Temperature Accuracy
±2°C
±0.5°C
Humidity Range
20% to 80%
0% to 100%
Humidity Accuracy
±5%
±2-5%
Sampling Rate
1 Hz
0.5 Hz
Body Size
Smaller
Larger
The sensors are pin-compatible and use identical communication protocols. Switching from DHT11 to DHT22 requires only changing DHTTYPE DHT11 to DHTTYPE DHT22 in your code.
Practical DHT11 Arduino Applications
The DHT11 Arduino pairing suits various real-world projects where cost matters more than precision.
Home Environment Monitoring
Track indoor temperature and humidity trends, triggering alerts when conditions exceed comfort thresholds. The ±2°C accuracy is adequate for determining whether your home feels comfortable.
Plant Care Systems
Monitor soil moisture (with additional sensors) alongside air humidity and temperature. The DHT11’s humidity range covers most indoor gardening scenarios.
Educational Projects
Teach sensor interfacing, data logging, and environmental science concepts. The low cost allows equipping entire classrooms affordably.
HVAC Automation Triggers
Use readings to control fans, heaters, or humidifiers through relays. The sensor’s accuracy suffices for on/off control with reasonable hysteresis bands.
Enclosure Monitoring
Track conditions inside electronics enclosures to detect overheating or humidity issues before they cause equipment damage.
Common sources for DHT11 sensors include Amazon, AliExpress, Adafruit, SparkFun, and local electronics retailers. Module versions typically cost slightly more than bare sensors but save troubleshooting time.
Frequently Asked Questions About DHT11 Arduino
Can I use multiple DHT11 sensors with one Arduino?
Yes. Each sensor requires its own digital pin and separate instance in your code. Define multiple DHT objects with different pin assignments: DHT dht1(2, DHT11); and DHT dht2(3, DHT11);. Each sensor operates independently.
Why does my DHT11 show humidity stuck at certain values?
The DHT11 outputs integer humidity values internally, so readings jump in whole-number increments rather than smooth decimal changes. This is normal behavior, not a defect. The DHT22 provides 0.1% resolution if smoother readings are required.
How long does a DHT11 sensor last?
Under normal indoor conditions, expect several years of service. However, prolonged exposure to high humidity, condensation, or corrosive environments degrades accuracy over time. Avoid letting the sensor get wet, as this can temporarily or permanently affect readings.
Can I use DHT11 with ESP8266 or ESP32?
Absolutely. The same Adafruit library works with ESP8266 and ESP32 boards. Just ensure you use appropriate GPIO pins (avoid pins with special boot functions) and account for the 3.3V logic levels. Most DHT11 modules work fine at 3.3V despite the 5V specification.
What causes the DHT11 to report temperature higher than actual room temperature?
Self-heating from continuous operation can slightly elevate readings. Additionally, placing the sensor near heat sources, in direct sunlight, or in enclosed spaces with poor airflow causes artificially high temperatures. Mount the sensor in open air away from electronics that generate heat.
Final Thoughts on DHT11 Arduino Projects
The DHT11 Arduino combination remains a solid choice for learning sensor interfacing and building cost-sensitive environmental monitoring projects. Its limitations are well-documented, and working within those constraints teaches valuable engineering judgment about component selection.
For your first temperature and humidity project, start with the basic serial monitor example, verify proper operation, then expand to LCD displays, data logging, or IoT connectivity. Once comfortable with the DHT11’s behavior, you’ll know exactly when a project demands the improved accuracy of a DHT22 or professional-grade sensor.
The sensor’s simplicity is ultimately its strength. One data wire, a standard library, and straightforward code get you from concept to working prototype in minutes. That rapid iteration capability makes the DHT11 a permanent fixture in my prototyping toolkit, and it deserves a place in yours.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.