DHT11 Sensor Interfacing with Arduino UNO

Introduction

DHT11 Sensor

DHT11 Sensor

  • DHT11 sensor measures and provides humidity and temperature values serially over a single wire.
  • It can measure relative humidity in percentage (20 to 90% RH) and temperature in degree Celsius in the range of 0 to 50°C.
  • It has 4 pins; one of which is used for data communication in serial form.
  • Pulses of different TON and TOFF are decoded as logic 1 or logic 0 or start pulse or end of a frame.

For more information about the DHT11 sensor and how to use it, refer the topic DHT11 sensor in the sensors and modules topic.

Interfacing Diagram

 

Interfacing DHT11 Sensor With Arduino UNO

Interfacing DHT11 Sensor With Arduino UNO

 

Example

Reading temperature and humidity from a DHT11 sensor.

Here, we will be using a DHT11 library by Mark Ruys from GitHub.

Download this library from here.

Extract the library and add the folder to the libraries folder path of Arduino IDE.

For information about how to add a custom library to the Arduino IDE and use examples from it, refer Adding Library To Arduino IDE in the Basics section.

Once the library has been added to the Arduino IDE, open the IDE and open the example sketch named DHT_Test from the library added.

 

Sketch For Reading Temperature And Humidity From DHT11

#include "DHT.h"

DHT dht;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");

  dht.setup(2); 	/* set pin for data communication */
}

void loop()
{
  delay(dht.getMinimumSamplingPeriod());	/* Delay of amount equal to sampling period */	

  float humidity = dht.getHumidity();	    /* Get humidity value */
  float temperature = dht.getTemperature();	/* Get temperature value */

  Serial.print(dht.getStatusString());	    /* Print status of communication */
  Serial.print("\t");
  Serial.print(humidity, 1);
  Serial.print("\t\t");
  Serial.print(temperature, 1);
  Serial.print("\t\t");
  Serial.println(dht.toFahrenheit(temperature), 1);	/* Convert temperature to Fahrenheit units */
}

​​​​​​

Video

 

 


Supporting Files

Source Code