• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: 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:

Capture

You'll also like:

  • 1.  Morse Code Flasher Circuit for Lighthouse
  • 2.  How to Connect an IR Photodiode Sensor in a Circuit
  • 3.  Knock Activated Door Security Intercom Circuit
  • 4.  Simple LDR Motion Detector Alarm Circuit
  • 5.  LPG Leakage SMS Alert using MQ-135 – Get Warning Message in your Cellphone
  • 6.  Arduino Barometric Pressure Sensor Circuit – Working and Interfacing Details

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « Make this Touch free Faucet Circuit for Hands-free Tap Control
Next Post: Make this Digital Temperature, Humidity Meter Circuit using Arduino »

Reader Interactions

Comments

  1. SHAIK IBRAHIM says

    February 15, 2021 at 11:41 pm

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

    Reply
    • Swagatam says

      February 16, 2021 at 2:46 pm

      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
  2. langat says

    May 16, 2020 at 11:12 pm

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

    Reply
    • Swagatam says

      May 17, 2020 at 8:00 am

      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
  3. Ubaid says

    April 13, 2018 at 3:02 pm

    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. Nitin says

    November 7, 2017 at 7:05 pm

    If can we control temperature and humidity, how

    Reply
    • Swagatam says

      November 7, 2017 at 7:34 pm

      Mr.GR will reply you soon…

      Reply
    • GR says

      November 8, 2017 at 4:31 am

      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
  5. Ananth kamath says

    July 14, 2016 at 1:44 pm

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

    Reply
    • Swagatam says

      July 14, 2016 at 5:04 pm

      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

      November 13, 2016 at 6:27 pm

      Hi,ananth

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

      Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

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

Primary Sidebar

Subscribe to New Circuit Ideas

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (83)
  • Datasheets and Components (104)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (101)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)

Calculators

  • 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
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Filter Capacitor Calculator
  • Buck Converter Calculator
  • Boost Converter Calculator
  • Solar Panel, Inverter, Battery Calculator
  • Wire Current Calculator
  • SMPS Transformer Calculator
  • IC SG3525, SG3524 Calculator
  • Inverter LC Filter Calculator

People Also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Recent Comments

  • Swagatam on How to Make Dog Barking Preventer Circuit using High Frequency Deterrence
  • Swagatam on How to Buy and Use RF Remote Control Modules – Control Any Electrical Gadget Remotely
  • Swagatam on How to Generate PWM Using IC 555 (2 Methods Explored)
  • Swagatam on Understanding SG3525 IC Pinouts
  • Dan on Understanding SG3525 IC Pinouts

Company

  • Privacy Policy
  • Cookie Policy
  • About Me
  • Contact
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin
  • © 2025 · Swagatam Innovations