Overview of DHT11
DHT11 Sensor
The DHT11 sensor measures humidity and temperature, sending values serially over a single data wire.
It can detect relative humidity from 20% to 90% RH and temperature from 0°C to 50°C.
The sensor has four pins, with one dedicated to serial data communication. Pulses with different TON and TOFF values are decoded as logic 1, logic 0, a start pulse, or an end-of-frame signal.
For more details on the DHT11 sensor and its usage, refer to the DHT11 Sensor topic in the sensors and modules section.
Connection Diagram of DHt11 with Arduino Uno
Interfacing DHT11 Sensor With Arduino UNO
Read Temperature and Humidity from DHT11 using Arduino
To read temperature and humidity data from a DHT11 sensor:
We’ll use Mark Ruys’s DHT11 library from GitHub.
Download the library, extract it, and add the folder to the Arduino IDE’s libraries folder.
https://github.com/markruys/arduino-DHT/archive/master.zip
For guidance on adding custom libraries and using example sketches, refer to in the Basics section.
Temperature and Humidity Measurement Code using DHT11 for Arduino
#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 */
}