Interfacing DHT11 Humidity & Temperature Sensor with Arduino
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-dht11-sensor-with-arduino.webp)
Welcome to this beginner-friendly Arduino tutorial on the dht11. By the end of the guide, you'll wire the module to an Arduino UNO, flash a short sketch, and read live values on the Serial Monitor — no prior electronics experience required.
What you'll learn
- How the module works in plain language
- The exact parts you need and how to wire them safely
- The full Arduino IDE sketch with comments
- Common issues and how to fix them
 — overview](/uploads/arduino/interfacing-dht11-sensor-with-arduino/2022-05-12 (1).jpg)
 — wiring diagram](/uploads/arduino/interfacing-dht11-sensor-with-arduino/2022-05-12.png)
Arduino code
Open the Arduino IDE, paste the sketch below into a new file, install any libraries the sketch #includes (Tools → Manage Libraries), select your board and COM port, then click Upload.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT11 // DHT 11
#define DHTPIN 2
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
dht.begin();
sensor_t sensor;
delayMS = sensor.min_delay / 1000;
}
void loop()
{
sensors_event_t event;
dht.temperature().getEvent(&event);
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
dht.humidity().getEvent(&event);
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
delay(delayMS);
}
 — reference image](/uploads/arduino/interfacing-dht11-sensor-with-arduino/DHT11_sensor_GIF.gif)
 — reference image](/uploads/arduino/interfacing-dht11-sensor-with-arduino/Schematic_DHT11_2022-05-13.png)
 — reference image](/uploads/arduino/interfacing-dht11-sensor-with-arduino/dht11_title.jpg)
How it works
The sketch initialises serial communication and the dht11 driver in setup(), then in loop() it samples the sensor at a regular interval and prints the result to the Serial Monitor at 9600 baud. Open the Serial Monitor (Ctrl+Shift+M) after upload to see live readings.
Troubleshooting checklist
- No readings: verify the baud rate in Serial Monitor matches the sketch (usually 9600).
- Garbage characters: wrong baud rate or loose GND wire.
- Library not found: install the exact library referenced in the
#includeline via Library Manager. - Sensor not detected (I²C): run an I²C scanner sketch to confirm the address.
What to build next
Once the basic readout works, try logging values to an SD card, sending them over Wi-Fi with an ESP32, or pushing them to a Blynk IoT dashboard. Pair this module with our simulator round-up to prototype the circuit before soldering.
You may also like
Frequently Asked Questions
Q.What library do I need for the dht11?
Open Arduino IDE → Tools → Manage Libraries, then search for any library named in the sketch's #include lines and install the latest version.
Q.Why does the Serial Monitor show nothing?
The most common cause is a baud-rate mismatch — set the Serial Monitor to 9600 baud (bottom-right dropdown) so it matches Serial.begin(9600) in the code.
Q.Can I use this with an ESP32 instead of Arduino UNO?
Yes. The dht11 works with any 3.3-5 V microcontroller. Just remap the wiring to ESP32 I/O pins and keep the rest of the sketch the same.
The Engineer Post
Embedded systems engineer and educator. Writes weekly tutorials at EmbedLab to help beginners ship real hardware.
Related projects
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-the-sr04t-sr04m-waterproof-ultrasonic-sensor-with-arduino.webp)
Interfacing SR04T/SR04M Waterproof UltraSonic Sensor with Arduino Uno
Step-by-step Arduino tutorial: wire the the sr04t, sr04m waterproof ultrasonic to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-tsl25911-ambient-light-sensor-with-arduino.webp)
Interfacing TSL25911 Ambient Light Sensor with Arduino
Step-by-step Arduino tutorial: wire the tsl25911 ambient light to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-lm35-temperature-sensor-with-arduino.webp)
How Does a LM35 Temperature Sensor Work and how to Interface it with Arduino
Step-by-step Arduino tutorial: wire the lm35 temperature to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-ir-sensor-module-with-arduino.webp)
Interfacing IR Sensor Module with Arduino
Step-by-step Arduino tutorial: wire the ir to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-hall-effect-sensor-with-arduino.webp)
Interfacing Hall Effect Sensor With Arduino
Step-by-step Arduino tutorial: wire the hall effect to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.



