ARDUINO DHT11 INTERFACE

DHT11 (Digital Temperature and Humidity sensor) is a composite Sensor that contains a calibrated digital signal output of the temperature and humidity.

In this tutorial, How to interface DHT11 (Temperature and Humidity Sensor) sensor to arduino is explained.

CONNECTIONS :
  ARDUINO              DHT 11 
  5v          -        5v
  Gnd         -        Gnd
  2          -        Data pin
PROCEDURE :
Program for Arduino:
  1. Open the Arduino software and open the DHTtester file from File–>Examples–>DHT sensor library–>DHTtester.

2. Comment  the DHT22 dht type line and uncomment the DHT11 dht type line as shown below

1
2
3
4
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

3. Then the program looks like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
 Serial.begin(9600);
 Serial.println("DHT11 test!");
 
dht.begin();
}
 
void loop() {
 // Wait a few seconds between measurements.
 delay(2000);
 float h = dht.readHumidity();
 // Read temperature as Celsius (the default)
 float t = dht.readTemperature();
 // Read temperature as Fahrenheit (isFahrenheit = true)
 float f = dht.readTemperature(true);
 
// Check if any reads failed and exit early (to try again).
 if (isnan(h) || isnan(t) || isnan(f)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }
 float hif = dht.computeHeatIndex(f, h);
 // Compute heat index in Celsius (isFahreheit = false)
 float hic = dht.computeHeatIndex(t, h, false);
 Serial.print("Humidity: ");
 Serial.print(h);
 Serial.print(" % ");
 Serial.print("Temperature: ");
 Serial.print(t);
 Serial.print(" *C ");
 Serial.print("Heat index: ");
 Serial.print(hic);
 Serial.print(" *C ");
 Serial.println("");
}

4. Upload the program and open the Serial Monitor using Ctrl+Shift+M.

THANK YOU
SHARE THIS!!!

Gowtham S

Gowtham is a programming enthusiast. His field of interest includes Arduino, NodeMCU, Raspberry Pi, and Python. To know more about him visit https://mybtechprojects.tech/about-us/.

8 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.