How to Use a DHT11 Temperature Sensor with Arduino – Step-by-Step Guide

The DHT11 is one of the most popular sensors for measuring temperature and humidity using an Arduino. In this guide, you’ll learn how to wire it, read data from it, and use it in your own projects.


What You’ll Need

  • Arduino UNO (or compatible)
  • DHT11 temperature and humidity sensor
  • 10k ohm resistor (optional but recommended)
  • Breadboard
  • Jumper wires

Wiring the DHT11 to Arduino

Connect the DHT11 sensor to the Arduino as follows:

  • VCC → 5V on Arduino
  • GND → GND
  • DATA → Digital Pin 2

Optional: Place a 10k ohm resistor between VCC and DATA to improve signal stability.


Arduino Code Example

To use the DHT11, you’ll need the DHT sensor library.

1. Install the Library:

In the Arduino IDE, go to:

Search for “DHT sensor library” by Adafruit and install it. Also install “Adafruit Unified Sensor”.

2. Upload the Code:


Troubleshooting Tips

If you’re having issues with your DHT11 sensor, try the following:

  • ✅ Double-check the wiring: VCC to 5V, GND to GND, DATA to digital pin 2
  • ✅ Use a 10k ohm pull-up resistor between VCC and DATA
  • ✅ Make sure you’ve installed the correct libraries (DHT and Adafruit Unified Sensor)
  • ✅ Try a different pin if pin 2 doesn’t work
  • ✅ Upload the sketch again after verifying the board and COM port are correct

If the serial monitor shows:
“Failed to read from DHT sensor!”
…it usually means the wiring or timing is off.