Temperature and humidity sensing using Arduino Uno

How you can sense temperature and humidity using Arduino uno? In this post, we going to see how to set up the DHT11 temperature and humidity sensor in Arduino uno.

We have two different Temperature and humidity sensors that we are going to see in this post. The first one is DHT11 and another one is DHT22. At beginning of this, we are going to see the basic of these two temperature & humidity sensors.

DHT11 Sensor & DHT22 Sensor

Both of these sensors belong to the DHTXX series. These types of humidity and temperature are generally made by thermisters and capacitive humidity sensors. It performs the digital and analog conversion, that’s how we get the digital signal as an output. These output signals can easily be read by microcontrollers.

DHT11 Sensor VS DHT Sensor

Comparison DHT11 DHT22
Cost Low Low
Power & I/O 3 to 5V 3 to 5V
Max current 2.5mA 2.5mA
Humidity readings 20-80% with 5% accuracy 0-100% with 2-5% accuracy
Temperature reading 0-50°C with ±2°C accuracy -40 to 80°C with ±0.5°C accuracy
Sampling rate No more than 1Hz (once every second) No more than 0.5 Hz (once every second)
Body size 15.5mm x 12mm x 5.5mm 15.1mm x 25mm x 7.7mm

As you can observe after going through the above data, DHT22 is having slightly large range and greater accuracy than DHT11.

Connecting DHT11 With Arduino Uno

  • Vcc to 5v
  • GND to GND
  • Data pin to D3 pin of Arduino Uno
connecting dht11 with arduino uno

After connecting every successfully. You have to follow some important instructions given below.

  • Open your Arduino IDE software
  • Click on Sketch > Include Library > Manage Libraries
  • Add the DHT sensor Library and Adafruit Unified Sensor Library
#include "DHT.h"
#define DHTPIN 3
#define DHTTYPE DHT11

DHT dht(DHTPIN,DHTTYPE);

void setup()
{
    Serial.begin(9600);
    Serial.println(F("DHT11 test!"));
    dht.begin();
}

void loop()
{
  delay(2000);
  float h= dht.readHumidity();
  float t= dht.readTemperature();
  float f= dht.readTemperature(true);

  if(isnan(h)||isnan(t)||isnan(f))
  {
    Serial.println(F("Failed to read from DHT11 sensor!"));
    return;
  }

  Serial.print(F("Humidity"));
  Serial.print(h);
  Serial.print("%\t");
  Serial.print(F("% Tempterature:"));
  Serial.print(t);
  Serial.print(F("°C\t"));
  Serial.print(f);
  Serial.println("°F");
}
C

You can see your output in the serial monitor panel.

This is for DHT11 similarly you can also set up DHT22 with Arduino uno.

Leave a Comment