Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA
Delivering to
Select Location ▾
Delivering to Select Location
▾

How DHT11 & DHT22 Sensors Work โ€“ MCU Interfacing

How DHT11 & DHT22 Sensors Work โ€“ MCU Interfacing
D
Written By Daniel D'Souza
๐Ÿ“… Updated on 14 Aug 2026
โœจ Summarize with AI
โœ… Prompt copied

Summary

Temperature and humidity sensing is a common requirement in many embedded and IoT projects. Choosing the right sensor and understanding how it communicates with a microcontroller is key to getting accurate data.

DHT11 and DHT22 are the go-to sensors for temperature and humidity readings - but they differ significantly in accuracy, range, and sampling rate. This guide explains how the single-wire protocol works, the hardware setup with pull-up resistor, and how to simulate and test the full circuit in Proteus before building it.

With a clear understanding of both sensors, you can select the right one and interface it reliably in your projects.

What is DHT11 and DHT22 Sensor

Sensors are used to collect data by measuring physical quantities and properties, this data is then used for various applications. Today we have sensors that can do all sorts of things: see, taste, hear and detect motions. It is hard to imagine life without these sensors around us, they help manage many things around us from opening the automatic door at your local store to controlling the water release into the nuclear plants.ย 

With this blog, we will be telling you about one such type of sensor: humidity and temperature sensor, namely DHT11 and DHT22, andย how to use them on a circuit simulation software: Proteus. These can be used in HVAC systems in pharmaceutical plants to protect life-saving drugs, in indoor agriculture facilities to keep plants at optimum condition, food processingย warehouses to avoid spoilage, etc.

Hardware components within the sensor

Best way to learn how a sensor work is to know its componentsย DHT11 and DHT22 contains a humidity sensing component, a thermistor, and a small onboard IC.

  • The humidity sensing componentย has two electrodes with a moisture-holding substrate (salt or conductive plastic polymer). The conductivity between the electrodes changes as ions is released by the substrate as it absorbs water vapour. This conductivity change is directly proportional to the relative humidity.
dht11 arduino
  • A Thermistorย is a particular type of resistor, whose resistance changes with change in temperature, there are two types: NTC (Negative Temperature Coefficient) and PTC (Positive Temperature Coefficient), NTC Thermistors resistance can decrease drastically with an increase of the temperature (about 100 ohms or more of change per degree) and vice-versa for PTC Thermistors. The DHTxx sensors uses an internal NTC Thermistor.ย 
dht11 pinout



  • The Onboard ICย measures the analog signal coming from the humidity sensor and the thermistor and uses the stored calibration coefficients to convert them for the respective usage.

Exploreย Raspberry Piย Collection

Pins on DHT11 and DHT22 sensor

Vccย :->ย provides power to the sensor (3.3V to 5.5V)

Data pin :->ย used to communicate between the sensor and the microcontroller.

Gnd :->ย connects to the ground terminal of the Arduino.

Differences between DHT11 & DHT22

Parameter

DHT22

DHT11

ย 

A close-up of a keychain

Description automatically generated with low confidence

Cost

Higher

Lower

Temp range

-40 to 125C

0 to 50C

Sampling Rate

0.5Hz

1Hz

Body Size

15.1mm x 25mm x 7.7mm

15.5mm x 12mm x 5.5mm

DHT22 is more precise and works with a larger range of temperature (-40 to 80ยฐC) & humidity (0-100%), but when it comes to a higher sampling rate and the cost of the sensor, DHT11 takes the lead. So, it is essential to weigh the pros and cons and choose which will best suit the application you are going for.

Similarities between DHT11 and DHT22

  • Both can operate in the range of 3 to 5 volts.ย 
  • They have the same pinouts.ย 
  • They use the maxย current of 2.5mA to request data from microprocessor.ย 

These similarities allow them to be used interchangeably for different advantageous scenarios, all you need is to do is adjust the Code a bit and you are all set to go!

How to Connectย DHT11 and DHT22ย sensor to an Arduino compatible MCU within the Proteus software

Initial Setup of Proteus

Create a New Project with Arduino development boardย 328

dht11 sensor working

To get this screenย ย 

dht11 temperature sensor

Then click on Library in the toolbar to go to Pick up library or the P symbol in the devices and select the DHT11 and DHT22 models. And click on the screen to place them in the workspace

dht11 arduino code

ย 

LM016L

dht11 sensor arduino
Virtual Terminal & Oscilloscope
dht11 sensor pin diagram

Go to meters ย ย symbol in the left Task Bar and select Virtual terminal and Oscilloscope(2 times ).

dht11 sensor specifications
dht11 temperature and humidity sensor arduino code

Connections

First we will try to attach the RXD of the Arduino to the TXD of the Virtual Terminal and vice versa

Instead of connecting them directly with wires we use labels and different types of terminals in proteus to connect them .

To do that find the terminals ย  symbol from the left task bar and select the default terminal

dht11 vs dht22

Now we connect them to the Virtual terminal (clicking on the screen brings up the same object )

dht11 diagram

Now we right click on the default terminal and the rename it as TXD and RXD respectively

dht11 sensor information

DHT 11

Connect the DHT-11 sensor, where the Vdd pin goes to +5v (Using the terminal for power and renaming it as 5V) and the data pin to IO9(Rename the terminal as IO9) and connecting the resistor R5, with a value of 4.7K ohms between the Supply and the data pin. This ensures that it is always in a high state and a ground connection to the 4th pin. The third, not connected pin, is not shown in proteus.ย The ground pin is connected to the ground terminal.

The Same connection is to be done for DHT-22; only the input should be IO11.

dht11 setup

ย 

LM016L

Connect the LCD screen According to the Diagram below

LM016L

Where Vss, Vee, RW, D0, D1, D2, D3 are connected to the ground, as shown.ย ย 

ย Vdd is Connected to the +5V.ย 

RS, E, D4, D5, D6, D7 are connected to IO8, IO7, IO6, IO5, IO4, IO3 respectively using the default terminal.

Here we will be using the DHT library, making our work much easier.

Click the link to download the Library from the GitHub repository:

To install the Library in Proteus, open the installation folder of proteus, and Extract the folder in "Installation_Directory\Proteus 8 Professional\Tools\ARDUINO\librariesโ€

Note: - if any issues occur in proteus simulation, then it is recommended to use an older DHT library

The Code

ย 

//ย Thisย isย anย Arduinoย Programย toย compareย theย readingsย ofย DHT-11ย andย DHT-22ย temperatureย humidityย sensorย simulatedย inย Proteusย 

#includeย <LiquidCrystal.h>

#include<math.h>

//ย includeย theย DHTย libraryย 

#includeย "DHT.h"

ย 

LiquidCrystalย lcd(8,7,6,5,4,3);

ย 

DHTย dht(9,DHT11);ย //ย Thisย isย toย Initializeย theย whichย DHTย 11ย Libraryย 

DHTย dht2(11,DHT22);ย //ย Includingย DHTย 22ย libraryย 

ย 

charย temperature[]ย =ย "Tempย 11ย =ย 00.0ย Cย ย ";

charย temperature2[]ย =ย "Tempย 22ย =ย 00.0ย Cย ย ";

charย humidity[]ย ย ย ย =ย "RHย 11ย =ย 00.0ย %ย ย ";

charย humidity2[]ย ย ย ย =ย "RHย 22ย =ย 00.0ย %ย ย ";

ย 

voidย setup()

ย {ย 

ย lcd.begin(16,ย 2);

ย Serial.begin(9600);

ย dht.begin();

ย dht2.begin();

ย }

ย 

voidย loop()

ย {ย 

ย ย delay(500);ย ย ย ย ย ย ย ย ย ย ย //ย waitย 1sย betweenย readings

ย ย //ย Readย humidity

ย ย floatย RHย =ย dht.readHumidity();

ย ย floatย RH2ย =ย dht2.readHumidity();

ย ย 

ย ย //Readย temperatureย 

ย ย floatย Tempย =ย dht.readTemperature();

ย ย floatย Temp2ย =ย dht2.readTemperature();

ย ย 

ย ย ifย (isnan(RH)ย ||ย isnan(Temp))ย {

ย ย ย ย lcd.setCursor(6,ย 0);

ย ย ย ย lcd.print("Error");

ย ย ย ย return;

ย ย }

ย ย 

ย ย temperature[10]ย ย ย ย ย =ย Tempย /ย 10ย +ย 48;ย //ย Atย Charย 10ย weย haveย ourย 10'sย Digitย ,ย weย addย 48ย (ย 0ย inย decimal)ย toย convertย itย toย ASCIIย nomenclatureย 

ย ย temperature2[10]ย ย ย ย =ย Temp2ย /ย 10ย +ย 48;ย 

ย 

ย ย temperature[11]ย ย ย ย ย =ย int(Temp)ย %ย 10ย +48ย ;ย //ย onesย value

ย ย temperature2[11]ย ย ย ย =ย int(Temp2)ย %ย 10ย +ย 48;

ย 

ย 

ย //Charย 12ย isย theย decimalย pointย inย ourย initialย setย ofย Charactersย 

ย ย temperature2[13]=ย (int(10*(Temp2-int(Temp2))))+48;ย //ย Thisย isย toย calculateย theย remainderย partย forย DHTย 22ย ,ย becauseย itย hasย anย accuracyย ofย 0.2ย -0.5ย 

ย 

ย ย temperature[14]ย ย ย ย =ย 223;ย //ย Thisย assignsย theย degreeย symbolย 

ย ย temperature2[14]ย ย ย =223;

ย //Sameย forย Humidityย 

ย ย humidity[8]ย ย ย ย ย ย ย ย =ย RHย /ย 10ย +ย 48;

ย ย humidity2[8]ย ย ย ย ย ย ย =ย RH2ย /ย 10ย +ย 48;

ย ย humidity[9]ย ย ย ย ย ย ย ย =ย int(RH)ย %ย 10ย +ย 48;

ย ย humidity2[9]ย ย ย ย ย ย ย =ย int(RH2)ย %ย 10ย +ย 48;

ย ย //ย charย 10ย isย theย dotย ,ย theย charย 12ย willย beย theย fractionย partย 

ย ย humidity2[11]ย ย ย ย ย ย ย =ย (int(10*(RH2-int(RH2))))+48;

ย ย 

ย ย //Printingย theย Valuesย 

ย ย 

ย ย Serial.println(temperature);

ย ย Serial.println(temperature2);

ย ย 

ย ย Serial.println(humidity);

ย ย Serial.println(humidity2);

ย ย 

ย ย lcd.setCursor(0,ย 0);

ย ย lcd.print(temperature);

ย ย lcd.print(humidity);

ย ย lcd.scrollDisplayLeft();

ย ย lcd.setCursor(0,ย 1);

ย ย lcd.print(temperature2);

ย ย lcd.print(humidity2);

ย ย lcd.scrollDisplayLeft();

}

ย 

ย 

Execution :-

This Code must be written in the Source Code of the Arduino -Proteus Simulation. You can find the Source code by clicking on the Source Code icon in the top taskbar.ย ย Paste the Code in the file named main.ino

dht11 temperature and humidity sensor arduino program

ย 

The Next Step is to Build the Project

dht11 temperature and humidity sensor working

And then Click on Debug>>Start VSM debuggingย or Run simulation.ย 

Shortcut - Ctrl+F12

Graphical user interface, text, application

Description automatically generated

And Click on the Bottom Play button to Start the Simulation if the Simulation is Paused.

Chart

Description automatically generated

After That, we can compare the Reading of the Two sensors using the Virtual Terminal, LCD screen and an Oscilloscope.

Code explanation

The Code starts with defining the Arduino libraries like LiquidCrystal for LCD interface and math.hย  for some math functions and DHT Library to Interface with the Sensors.

And we are Defining the LCD PINs followed by creating two separateย DHT objects Connected to their respective data pins to access the various functions in the DHT library.

//ย Thisย isย anย Arduinoย Programย toย compareย theย readingsย ofย DHT-11ย andย DHT-22ย temperatureย humidityย sensorย simulatedย inย Proteusย 

#includeย <LiquidCrystal.h>

#include <math.h>

//ย includeย theย DHTย libraryย 

#includeย "DHT.h"

ย 

LiquidCrystalย lcd(8,7,6,5,4,3);

ย 

DHTย dht(9,DHT11);ย //ย Thisย isย toย Initializeย theย whichย DHTย 11ย Libraryย 

DHTย dht2(11,DHT22);ย //ย Includingย DHTย 22ย library

ย 

Then we define our Character Strings which we will manipulate to Display the Temperature and the Relative Humidity.ย 

charย temperature[]ย =ย "Tempย 11ย =ย 00.0ย Cย ย ";

charย temperature2[]ย =ย "Tempย 22ย =ย 00.0ย Cย ย ";

charย humidity[]ย ย ย ย =ย "RHย 11ย =ย 00.0ย %ย ย ";

charย humidity2[]ย ย ย ย =ย "RHย 22ย =ย 00.0ย %ย ย ";

ย 

Next comes the void setup function, where we begin the Lcd and initiate the serial communication to print results on the serial monitor andย  initialize both the sensors.

voidย setup()

ย {ย 

ย lcd.begin(16,ย 2);

ย Serial.begin(9600);

ย dht.begin();

ย dht2.begin();

ย }

ย 

In the loop function

voidย loop()

ย {ย 

ย ย delay(500);ย ย ย ย ย ย ย ย ย ย ย //ย waitย 1sย betweenย readings

ย ย //ย Readย humidity

ย ย floatย RHย =ย dht.readHumidity();

ย ย floatย RH2ย =ย dht2.readHumidity();

ย ย 

ย ย //Readย temperatureย 

ย ย floatย Tempย =ย dht.readTemperature();

ย ย floatย Temp2ย =ย dht2.readTemperature();

ย 

We set a delay so the values are readable.ย 

And we define the RH and RH2 as float variables to read humidity in the dht and dht2 object, respectively.ย 

Likewise, we define Temp and Temp2 as float variables to read the temperature in the dht and dht2 objects, respectively.ย 

Error detection codeย 

ย ย ifย (isnan(RH)ย ||ย isnan(Temp))ย {

ย ย ย ย lcd.setCursor(6,ย 0);

ย ย ย ย lcd.print("Error");

ย ย ย ย return;

ย ย }

ย 

If, the sensors read no value then the LCD screen will display Error

Conversion

temperature[10]ย ย ย ย ย =ย Tempย /ย 10ย +ย 48;ย //ย Atย Charย 10ย weย haveย ourย 10'sย Digitย ,ย weย addย 48ย (ย 0ย inย decimal)ย toย convertย itย toย ASCIIย nomenclatureย 

temperature2[10]ย ย ย ย =ย Temp2ย /ย 10ย +ย 48;ย 

ย 

temperature[11]ย ย ย ย ย =ย int(Temp)ย %ย 10ย +48ย ;ย //ย onesย value

temperature2[11]ย ย ย ย =ย int(Temp2)ย %ย 10ย +ย 48;

ย 

ย 

//Charย 12ย isย theย decimalย pointย inย ourย initialย setย ofย Charactersย 

temperature2[13]=ย (int(10*(Temp2- ย  ย int(Temp2))))+48;ย //ย Thisย isย toย calculateย theย remainderย partย forย DHTย 22ย ,ย becauseitย hasย anย accuracyย ofย 0.2ย -0.5ย 

ย 

temperature[14]ย ย ย ย =ย 223;ย //ย Thisย assignsย theย degreeย symbolย 

temperature2[14]ย ย ย =223;

ย 

In this, we convert the raw float values and individually replace them with the Character set we defined earlierย 

Note that we add 48 after the calculation because LCD screens work with ASCII nomenclature; 48 is 0 in ASCII Nomenclatureย 

char 13 is the fractional part of the DHT 22 sensor as it has uncertainty or accuracy of 0.2 - 0.5 Celsius, while DHT 11 has uncertainty or accuracy of 2 deg Celsius.ย ย 

Same for Relative Humidityย 

Now we print and display the resultsย 

ย ย //Printingย theย Valuesย 

ย ย 

ย ย Serial.println(temperature);

ย ย Serial.println(temperature2);

ย ย 

ย ย Serial.println(humidity);

ย ย Serial.println(humidity2);

ย 

This is for the Serial monitor. Then, we just must print the Character sets, which have all the texts.ย 

Next part is for the Lcd LM160L

ย 

ย  lcd.setCursor(0,ย 0);

ย ย lcd.print(temperature);

ย ย lcd.print(humidity);

ย ย lcd.scrollDisplayLeft();

ย ย lcd.setCursor(0,ย 1);

ย ย lcd.print(temperature2);

ย ย lcd.print(humidity2);

ย ย lcd.scrollDisplayLeft();

ย 

Here we display the temperature and Humidity of DHT 11 in the Same Line and temperature and Humidity of DHT 22 in the below line as the LCD cannot display all of them at the same time; we use the scrollDisplayleft function to display them all, scrolling through them.

Expected Outputย 

Final Circuit

circuit diagram of dht11

Readingsย 

Graphical user interface

Description automatically generated

Virtual Terminalย 

Text

Description automatically generated

Oscilloscope

A picture containing text, electronics, display

Description automatically generated

ย 

The Delay is not that visible in the given screenshot.ย 

LCD screen

A picture containing text, clock

Description automatically generatedA picture containing text, clock

Description automatically generatedย 

This blog has been submitted by Robotics and Circuits, MIT Manipal under the Robocraze Club Outreach Program.

Author: Anirudh Bharadwaj, Prakhar Swarnakar

ย 

Excerpt

Learn how DHT11 & DHT22 sensors work and interface with a MCU on Proteus. Understand applications, working, and easy implementation.

Frequently Asked Questions

1. What is the difference between DHT11 and DHT22?

The DHT11 is a basic, cheaper sensor with a temperature range of 0-50ยฐC and humidity range of 20-80%. The DHT22 offers higher accuracy, measuring temperatures from -40 to 80ยฐC and humidity from 0-100%. Additionally, DHT22 has better precision, making it suitable for more demanding applications.

2. How do these sensors measure humidity and temperature?

DHT sensors use a thermo-hygrometer technique. They incorporate a polymer humidity sensor and a thermistor for temperature. The sensor interacts with the surrounding air, generating a digital signal that represents the humidity and temperature, which can be read by microcontrollers like Arduino.

3. What is the pin configuration of DHT sensors?

DHT sensors typically feature three pins: VCC (power), GND (ground), and Data (signal). Connect VCC to a 3.3V or 5V power source, GND to the ground, and the Data pin to an input pin on your microcontroller for readings.

4. How to interface DHT11 with Arduino?

To interface a DHT11 with an Arduino, connect the VCC pin to 5V, GND to ground, and the Data pin to a digital pin. Use the DHT library in the Arduino IDE to read the sensor data. Just include the library, initialize the sensor, and start reading temperature and humidity values.

5. How to simulate DHT sensors in Proteus?

To simulate DHT sensors in Proteus, create a new schematic and add the DHT sensor component from the library. Wire it correctly to a microcontroller like Arduino. Configure the virtual environment to simulate temperature and humidity readings, allowing you to test your code within the software.

6. What is the accuracy of DHT11 vs DHT22?

The DHT11 has a temperature accuracy of ยฑ2ยฐC and a humidity accuracy of ยฑ5%. In contrast, the DHT22 boasts a temperature accuracy of ยฑ0.5ยฐC and a humidity accuracy of ยฑ2-5%, making it the better choice for precision applications requiring reliable readings.

7. What are the applications of DHT sensors?

DHT sensors are commonly used in various applications, including home automation, HVAC systems, weather stations, and greenhouse monitoring. They are popular for projects requiring accurate humidity and temperature data for efficient controls and monitoring.

8. How to troubleshoot DHT sensor errors?

To troubleshoot DHT sensor errors, first check the wiring and ensure the connections are secure. Verify that the sensor is powered properly and using the correct library. If errors persist, replace the sensor, as it may be faulty. Testing with another compatible microcontroller can also help isolate the issue.

9. How to calibrate a DHT sensor?

Calibrating a DHT sensor involves comparing its readings with a known accurate device. Take several measurements and adjust the readings in your code as needed to match the accurate device. This will enhance the sensor's accuracy for temperature and humidity measurements.

10. Can I use DHT sensors for outdoor weather monitoring?

Yes, DHT sensors can be used for outdoor weather monitoring, but they're sensitive to direct sunlight and moisture. To protect the sensor, use a protective enclosure, ensuring airflow while shielding it from rain. This setup will provide reliable outdoor temperature and humidity data.

Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
โ‚น100 OFF
โ‚น200 OFF
โ‚น999
โ‚น2500
โ‚น4900
WhatsApp Chat Chat