DHT11: digital temperature and humidity sensor

Posted on by
Temperature and humidity sensor

Temperature and humidity sensor

If you are looking for a low cost sensor for measuring temperature and humidity one of the most common options is the DHT11 sensor. It has excellent quality, fast response, interference protection, digital communication and accurate calibration. All this makes it one of the most used for small home projects like greenhouses, home automation, controls temperature regulators, indoor thermometers or relative humidity sensors.

Works from 3.3V to 5V, it is capable of measuring in a range of temperatures between 0 to 50 Celsius degrees with 5% accuracy and 20% to 80% relative humidity with 5% accuracy. If you want something that offers more resolution or more accurate you will have to spend more money, you have to keep in mind that you get what you pay for. But there are many projects have enough with these specifications.

Arduino connected to DHT11.

Arduino connected to DHT11.

It has three pin VCC, GND and DATA. Therefore communications are made bidirectionally on the same pin (DATA). Every time we make a request for measure will return us 40 bits, or 5 bytes. The first two octets are the relative humidity, the third and the fourth octet is the temperature and the last byte is a checksum to validate the correct transmission of all bits, but for arduino we can abstract because there is a library that will save us a lot job.

For use with arduino we have to decide what digital pin we want to useinclude DHT11.h library and start to program. Here is an example of basic code that you can try:

#include <DHT11.h>

int pin=2;
DHT11 dht11(pin);

void setup()
   {
       Serial.begin(9600);
   }

void loop()
   {
       int err;
       float temp, hum;
       if((err = dht11.read(hum, temp)) == 0)
          {
             Serial.print("Temperature: ");
             Serial.print(temp);
             Serial.print(" Humidity: ");
             Serial.print(hum);
             Serial.println();
          }
       else
          {
             Serial.println();
             Serial.print("Error Num :");
             Serial.print(err);
             Serial.println();
          }
       delay(1000);
   }
}
Comments are disabled