DHT11 Room Monitor with Arduino Uno: Temperature, Humidity, Wiring and Code
EDITOR REVIEW — MODULE VERIFICATION PENDING: Confirm the supplied PCB pin labels and its fitted data pull-up against the shipping revision. The store photo shows a Keyes-style three-pin module, but no exact PCB revision datasheet or total module current is supplied. Code has been checked against the library API, but has not been compiled or hardware-tested.
Build a simple indoor temperature and humidity display using a DHT11 sensor module and Arduino Uno R3. The computer’s Serial Monitor shows a fresh reading every few seconds, with an explicit error message if communication fails.
Level: beginner. Build time: about 20–30 minutes after software installation. You will learn: module wiring, installing a sensor library, handling failed readings and interpreting relative humidity. A computer is the display; no internet, cloud account or separate screen is required.
Contents
- How it works
- Parts list
- Pinout and diagrams
- Assembly and IDE setup
- Complete code
- Upload and test
- Troubleshooting
- FAQs
How it works
The DHT11 measures temperature and relative humidity, then sends a digital message on one data line. The Adafruit library handles the timing and checks the response. This is the DHT protocol, not I²C or a Dallas/Maxim OneWire device. D2 is the data connection, and both boards share ground.
The sketch requests data every three seconds, respecting the manufacturer manual’s interval greater than two seconds. This interval is separate from how quickly the sensor responds to a real change in air conditions. A repeated value does not necessarily mean the circuit has stopped.
Parts list
| Component / purchase link | Required | Specification / pack size |
|---|---|---|
| DHT11 sensor module | 1 | Assembled 3-pin board with fitted pull-up; use 5 V in this build. |
| Arduino Uno R3 | 1 | Classic 5 V ATmega328P board. |
| Male-to-female jumper wires | 3 leads | 20 cm; sold as a pack of 40. |
| USB A–B data cable | 1 | Fits the Uno R3 USB Type-B connector. |
You also need a computer and Arduino IDE. The pictured assembled module has male pins and a fitted resistor, so the direct module build needs no breadboard or separate pull-up resistor. If yours is a bare four-pin sensor or lacks the pull-up, stop and use its exact application circuit; do not apply this module layout by pin position.
Pinout and connections
| Module function / label | Uno connection | Diagram colour |
|---|---|---|
| VCC / + (supply) | 5V | Orange |
| GND / − | GND | Grey |
| DATA / S | D2 | Teal |
Follow the printed labels and the seller’s pinout for your actual board. On the photo, S identifies signal and − identifies ground; confirm the remaining supply pin before powering it. Both diagrams are symbolic and do not establish physical pin positions.
Circuit schematic

Visual module wiring

Assembly and software setup
- Unplug USB. Check the sensor board labels and fitted pull-up. Do not force loose wires into the sensor housing.
- Connect three female jumper ends to the module header. Connect the male ends to Uno 5V, GND and D2 according to the table.
- Place the module in room air away from the Uno regulator, direct sunlight and other heat sources. Keep its vents clear and avoid liquid water or condensation.
- Install Arduino IDE. Select Arduino Uno under Arduino AVR Boards and the correct port.
- In Library Manager install DHT sensor library by Adafruit. Install its Adafruit Unified Sensor dependency when prompted. Avoid choosing another library with a similar name.
- Create a sketch named dht11_room_monitor, then paste the code below.
Power: use the Uno USB supply. Connect the sensor to 5V, never VIN or an external higher-voltage rail. The manufacturer sensor manual lists up to 1 mA while measuring for that sensor revision; this is not a total-current guarantee for the reseller’s assembled board. Power it from the supply pin rather than a GPIO. This 5 V wiring must not be transferred unchanged to a 3.3 V-only controller.
Complete program
Download complete code (.txt); save as dht11_room_monitor.ino in a matching sketch folder.
// Anu Electronics: DHT11 module room monitor, classic Arduino Uno R3.
// Module VCC -> 5V, GND -> GND, DATA/S -> D2.
// Install DHT sensor library by Adafruit and Adafruit Unified Sensor.
#include <DHT.h>
#include <math.h>
const uint8_t SENSOR_PIN = 2;
const unsigned long READ_INTERVAL_MS = 3000UL;
DHT sensor(SENSOR_PIN, DHT11);
unsigned long sampleNumber = 0;
void setup() {
Serial.begin(9600);
sensor.begin();
Serial.println("DHT11 room monitor: waiting for first sample...");
}
void loop() {
// Also allows more than one second of startup settling before first read.
delay(READ_INTERVAL_MS);
float humidity = sensor.readHumidity();
float temperatureC = sensor.readTemperature();
if (isnan(humidity) || isnan(temperatureC)) {
Serial.println("Read failed: check power, DATA pin and DHT11 selection.");
return; // Next attempt still waits three seconds.
}
++sampleNumber;
Serial.print("Sample ");
Serial.print(sampleNumber);
Serial.print(" | Temperature: ");
Serial.print(temperatureC, 1);
Serial.print(" C | Humidity: ");
Serial.print(humidity, 1);
Serial.println(" %RH");
}
Code explained
DHT sensor(SENSOR_PIN, DHT11) selects the sensor type and D2. sensor.begin() prepares the library. Humidity is returned in percent relative humidity and the default temperature unit is Celsius. The two read calls use the library’s cached result within its minimum read interval, rather than forcing two back-to-back sensor transactions.
isnan() catches a failed read. The sketch prints an error and waits again on its next loop, so it does not report a failed measurement as zero. The sample counter increases only for successful readings. Printing one decimal place formats the value; it does not promise 0.1-degree accuracy.
Upload and test
- Click Verify, then Upload. Resolve any missing-library errors before continuing.
- Open Serial Monitor at 9600 baud. Press reset to see the startup message.
- Wait at least three seconds for the first result, then observe several readings.
- Move the sensor away from heat sources and let it settle. Compare with a trusted room instrument only after both are in the same conditions.
- For a communication check, unplug USB before disconnecting DATA. Power up again and confirm the error message. Unplug before restoring the wire.
Sample 1 | Temperature: 25.0 C | Humidity: 54.0 %RH Sample 2 | Temperature: 25.0 C | Humidity: 55.0 %RH
These values and the animation below are illustrative, not recorded measurements. Your room conditions will differ. Relative humidity depends on temperature and is not the same as an absolute amount of water in the air.

Troubleshooting
| Symptom | Check |
|---|---|
| DHT.h not found | Install Adafruit’s DHT sensor library through Library Manager. |
| Adafruit_Sensor.h not found | Install Adafruit Unified Sensor. |
| Read failed repeatedly | Disconnect power, verify supply/ground/signal labels, D2 and the fitted pull-up. Confirm DHT11 rather than DHT22 in the sketch. |
| No readable serial text | Check 9600 baud, selected port, data-capable USB cable and upload result. |
| Readings are steady or coarse | Allow time for room changes. Do not increase the polling rate to force faster physical response. |
| Temperature seems high | Move away from board heat, hands and sunlight; allow time to settle. |
Frequently asked questions
Is the three-pin module the same as the bare sensor?
It contains the same type of sensing device, but the PCB changes the connector arrangement and may include supporting parts. The bare four-pin sensor has an unused pin; its pin order must not be copied onto a three-pin module.
Can I substitute a DHT22?
Only after checking that module’s wiring and specifications and changing the library type to DHT22. Do not expect identical limits or resolution.
Is this suitable for precision control?
This is an educational room monitor. The store lists about ±2 °C temperature accuracy and ±5% RH humidity accuracy, with a 0–50 °C and 20–90% RH range. Manufacturer revisions differ, so use the supplied unit’s documentation before relying on limits. Do not use the example as a calibrated measurement instrument.
Can I use long sensor wires?
Start with the 20 cm leads shown. Cable length, power and pull-up selection affect communication; a working short-wire setup does not establish a longer cable limit.
Related tutorials and parts
Compare this digital sensor with our Arduino voltage-divider tutorial, or learn a simple on/off input with the TTP223 touch-sensor tutorial.
Build your monitor with the DHT11 module and the compatible controller and cables in the parts table.
Sources and testing limits
- Aosong DHT11 manual, revision V1.3 — sensor interface, power and read interval; it is not the reseller PCB schematic.
- Adafruit DHT sensor library — API and required dependency.
- Arduino Uno R3 datasheet — board connections.
Original tutorial and sketch using the Adafruit library API. No library source is redistributed. Diagrams are original; the cover uses the store photo as its product reference. API and wiring consistency were reviewed; compilation and physical testing remain unperformed.