• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

Circuits for Beginners | Basic Circuits | LED Driver | Hobby Circuits | Transistor Circuits

New-Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright

Home » Sensors and Detectors » Interfacing DHTxx Temperature Humidity Sensor with Arduino

Interfacing DHTxx Temperature Humidity Sensor with Arduino

Last Updated on March 23, 2022 by Swagatam 11 Comments

In this article we are going to take a look at DHTxx series sensors, which is used for measuring temperature and humidity, both the functionality is integrated into one module.

We are going to see their specification, so that you can choose best sensor for your project and finally we are going to interface it with arduino and read the values in serial monitor of arduino IDE software.

DHTxx consist of just two series DHT11 and DHT22. The major difference between them is their specification and cost. DHT11 is low end sensor and DHT22 is high end one. DHT22 is more expensive than DHT11, but low end is decent enough for hobby project unless you do some serious measurement with you project.

DHTxx is 4-pin device one of them is NC or no connection so, we are going to use just 3-pins. Two of them are supply pins and remaining one is output pin. The sensor may look simple, but it requires a library for handling it.

The sensor consists of a thermistor, a humidity sensing device and a microcontroller embedded in a module. Their specifications are as follows:

DHT11:
• Operating voltage range is 3 to 5V.
• Its maximum current consumption is 2.5mA.
• It can measure humidity ranging from 20% to 80% -/+ 5% accuracy.
• It can measure temperature ranging from 0 to 50 degree Celsius +/- 2% accuracy.
• It refreshes it value every one second.
• Its size is 15.5mm x 12mm x 5.5mm

DHT22:
• Operating voltage is 3 to 5V
• Its maximum current consumption is 2.5mA.
• It can measure humidity ranging from 0% to 100% 2-5 % accuracy.
• It can measure temperature ranging from -40 to +125 degree Celsius +/- 0.5% accuracy.
• It refreshes it value twice every one second.
• Its size is 15.1mm x 25mm x 7.7mm
From the above raw specifications you can choose which one is optimum for your project.

DHT11 Temperature Humidity Sensor

The data pin always should be connected with a pull-up resistor from 4.7K to 10K. The above illustrated sensor came with PCB with eliminated NC pin and with pull-up resistor. But some sensors come without those feature, without the pull-up resistor the readings send to arduino will be fatally error values.

Now we are going to interface DHT sensor with arduino. Before proceeding the project download the library file form the following link:

https://arduino-info.wikispaces.com/file/detail/DHT-lib.zip

You just need these four components: DHTxx sensor, arduino Uno, USB cable, and a PC.

Just insert the sensor on analog pins of the arduino as illustrated in prototype and dump the code to arduino, open the serial monitor and you can see the readings.
Author’s prototype:

Interfacing DHTxx Temperature Humidity Sensor with Arduino
//----------------------Program developed by R.Girish-------------//
#include <dht.h>
dht DHT;
#define DHTxxPIN A1
int p = A0;
int n = A2;
int ack;
int f;
void setup(){
  Serial.begin(9600);
  pinMode(p,OUTPUT);
  pinMode(n,OUTPUT);
}
void loop()
{
  digitalWrite(p,1);
  digitalWrite(n,0);
  ack=0;
  int chk = DHT.read11(DHTxxPIN);
  switch (chk)
  {
    case DHTLIB_ERROR_CONNECT:
        ack=1;
        break;
  }
  if(ack==0)
  {
  f=DHT.temperature*1.8+32;
  Serial.print("Temperature(°C) = ");
  Serial.println(DHT.temperature);
  Serial.print("Temperature(°F) = ");
  Serial.print(f);
  Serial.print("\n");
  Serial.print("Humidity(%) = ");
  Serial.println(DHT.humidity);
  Serial.print("\n");
  delay(500);
}
if(ack==1)
{
  Serial.print("NO DATA");
  Serial.print("\n\n");
  delay(500);
}
}
//----------------------Program developed by R.Girish-------------//

Serial monitor output:

You'll also like:

  • 1.  Cell Phone Ring to Flashing Lamp Indicator for People with Hearing Loss
  • 2.  Industrial Valve Switching Detector Indicator Circuit
  • 3.  Mains AC Xenon Tube Flasher Circuit
  • 4.  How to Connect a TSOP1738 IR Sensor
  • 5.  How to Make a Soil Moisture Tester Circuit with a Single IC 741
  • 6.  IC 555 Low Battery Indicator Circuit

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Subscribe for the Latest Posts


 

Reader Interactions

Comments

    Your Comments are too Valuable! But please see that they are related to the above article, and are not off-topic! Cancel reply

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

  1. Ananth kamath says

    Sir can we use LM35 or thermistor sensors instead of DHTxx?

    Reply
    • Swagatam says

      Ananth, it will depend on the specifications of the two sensors, if they match reasonably well then perhaps it could work with the proposed Arduino design.

      Reply
    • GR says

      Hi,ananth

      you can't use LM35 in the place of DHT sensor, they both work in very different way.

      Reply
  2. Nitin says

    If can we control temperature and humidity, how

    Reply
    • Swag says

      Mr.GR will reply you soon…

      Reply
    • GR says

      Hi Nitin,

      To control temperature and humidity you need a cooling or heating device or both. To control humidity you need water vaporizer (humidifier) or dehumidifier or both. The sensor and Arduino must be programmed in a way that it triggers the mentioned climate control devices on/off to meet your set temp & humidity.
      The above concept works optimally in a closed enclosure.

      One example of this is a incubator: https://www.homemade-circuits.com/incubator-using-arduino-with-automatic-temperature-and-humidity-control/

      Regards

      Reply
  3. Ubaid says

    Hello sir !

    I use correct library for dht as
    Above mention link.but I face error in compilation.
    Void loop:
    error : DHTLIB_ERROR_CONNECT
    was not declared in this scope.

    but i delete this line from code
    (case DHTLIB_ERROR_CONNECT:)

    Compilation successful.

    Reply
  4. langat says

    hi, I am also getting error : DHTLIB_ERROR_CONNECT
    was not declared in this scope.
    What could be the problem?

    Reply
    • Swagatam says

      Hi, you must find and import the dht.h library correctly, it appears to be be slightly difficult since most files do not seem to work, but you have to do it, you can refer to the following link for some info:

      https://community.blynk.cc/t/correct-dht-library/30774/5

      Reply
  5. SHAIK IBRAHIM says

    THANKS,BRO. IN EGG INCUBATOR PROJECT
    DHTLIB_ERROR_CONNECT’ was not declared in this scope. HOW CAN I SOLVE THIS ERROR.

    Reply
    • Swagatam says

      Sorry Shaik, I tried a lot to find the solution, but I could not understand the reason….. actually I am an Arduino expert, and this code was generated by an external author.

      Reply

Primary Sidebar



Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (53)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (98)
  • 741 IC Circuits (19)
  • Amplifiers (58)
  • Arduino Engineering Projects (82)
  • Audio Projects (95)
  • Battery Chargers (82)
  • Car and Motorcycle (94)
  • Datasheets (46)
  • Decorative Lighting (Diwali, Christmas) (33)
  • DIY LED Projects (89)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (109)
  • Fish Aquarium (5)
  • Free Energy (35)
  • Fun Projects (11)
  • GSM Projects (9)
  • Health Related (18)
  • Heater Controllers (28)
  • Home Electrical Circuits (101)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (63)
  • Mini Projects (171)
  • Motor Controller (66)
  • MPPT (7)
  • Oscillator Circuits (24)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (74)
  • Radio Circuits (9)
  • Remote Control (47)
  • Security and Alarm (61)
  • Sensors and Detectors (116)
  • SG3525 IC (5)
  • Simple Circuits (74)
  • SMPS (29)
  • Solar Controllers (61)
  • Timer and Delay Relay (54)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (40)
  • Ultrasonic Projects (14)
  • Water Level Controller (45)

Circuit Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora

© 2022 · Swagatam Innovations

We use cookies on our website to give you the best experience.
Cookie settingsAccept All
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Please visit the Privacy Policy Page for more info.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT