How to Measure Temperature and Humidity with Arduino and DHT11 DHT22 Sensor


Welcome to the world of Arduino and environmental sensing! In this guide, we’ll explore How to Measure Temperature and Humidity with Arduino and DHT11 DHT22 Sensor. These sensors offer a convenient way to gather environmental data, making them popular choices for DIY projects and professional applications alike. Let’s dive in and uncover the capabilities of these sensors!

Hardware Required

You will require the following Hardware Components for How to Measure Temperature and Humidity with Arduino and DHT11 DHT22 Sensor.

Components#Buy From Amazon
Arduino UNO1Buy Link
DHT11 Temperature and Humidity Sensor1Buy Link
DHT22 Temperature and Humidity Sensor1Buy Link
Resistor 10K1Buy Link
9v DC Adapter (Optional)1Buy Link
Jumper WiresFewBuy Link
Breadboard1Buy Link

What is a DHT11/DHT22 Sensor?

The DHT11 and DHT22, also known as the AM2302, belong to the same family of sensors designed for simultaneous measurement of temperature and humidity. These sensors feature an internal processor that handles the measurement process, providing digital output for easy integration with microcontrollers like Arduino. While both sensors come in a similar plastic casing, they can be distinguished by their colors – the DHT11 has a blue casing, whereas the DHT22 has a white exterior.

DHT11 Temperature and Humidity Sensor:

The DHT11, often considered the “little brother” of the family, offers basic functionality but lacks precision and range compared to the DHT22. Its features include:

  • Temperature measurement range: 0 to 50°C with a precision of 2°C
  • Humidity measurement range: 20 to 80% with a precision of 5%
  • Sampling rate: 1 sample per second (1 Hz) The DHT11 is suitable for simple projects, testing, or training purposes where precise measurements are not critical.

DHT11 Temperature and Humidity Sensor:

The DHT22, on the other hand, offers improved characteristics suitable for more demanding applications. Its features include:

  • Temperature measurement range: -40 to 125°C with an accuracy of 0.5°C
  • Humidity measurement range: 0 to 100% with a precision of 2-5%
  • Sampling rate: 2 samples per second (2 Hz) While not a high-precision sensor, the DHT22 provides acceptable performance for projects requiring medium precision and real monitoring or recording capabilities.

Pinout of DHT11/DHT22 Sensor


Pin Configuration

Pin NamePin Type
VCCPositive supply Pin
GNDGround Pin
NCNot used
OutOutput or sending data

Circuit Diagram

The following circuit shows you the connection of How to Measure Temperature and Humidity with Arduino and DHT11 DHT22 Sensor, Please make the connection carefully


Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Installing Libraries

Now when you are Ready to upload the code, to the Arduino Board you will need first to add the Following Libraries in Arduino, If you Learn How to add the library in the Arduino step-by-step guide click on how to install the library Button given Blow


//For more Projects:

#include "DHT.h"

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

const int DHTPin = 5; // what digital pin we're connected to


void setup() {
  Serial.println("DHTxx test!");


void loop() {
  // Wait a few seconds between measurements.

  // Reading temperature or humidity takes about 250 milliseconds!
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");

  Serial.print("Humidity: ");
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(" *C ");


  1. Indoor Climate Monitoring: Use DHT11 or DHT22 sensors to monitor temperature and humidity levels indoors. This application is useful for maintaining comfortable living or working conditions and preventing issues like mold growth.
  2. Greenhouse Management: Employ DHT sensors in greenhouse environments to monitor temperature and humidity, ensuring optimal conditions for plant growth. Automated systems can adjust environmental parameters based on sensor data to maximize crop yield.
  3. Weather Stations: Build your weather station using DHT sensors to collect data on temperature and humidity. With additional sensors, you can expand your weather station to measure other parameters like pressure and rainfall, providing comprehensive weather data.
  4. Food Storage Monitoring: Utilize DHT sensors to monitor temperature and humidity levels in food storage environments such as refrigerators and pantries. Monitoring these parameters helps ensure food safety by preventing spoilage and maintaining optimal storage conditions.


With these versatile applications, DHT11 and DHT22 sensors offer valuable insights into temperature and humidity levels, enabling a wide range of projects from home automation to agricultural management and beyond. Let’s get started with building our temperature and humidity monitoring system with Arduino!

Leave a Comment