Using DHT11

This tutorial will show you how to use DHT11 with Arduino.

Nov 23, 2018

491580 views

62 respects

Components and supplies

1

DHT22 Temperature Sensor

1

DHT11 Temperature & Humidity Sensor (4 pins)

1

DHT11 Temperature & Humidity Sensor (3 pins)

1

Jumper wires (generic)

1

Arduino UNO

1

Breadboard (generic)

Apps and platforms

1

Arduino IDE

Project description

Code

DHT11 Library

Don't forget to add this library to the Arduino IDE.

Latest commit to the master branch on 19-01-2015

DHT11.ino

arduino

The code for receiving the data from the DHT11 and printing it out on the serial monitor.

DHT11 Library

Don't forget to add this library to the Arduino IDE.

Latest commit to the master branch on 19-01-2015

Downloadable files

Schematics

Schematics

Schematics

Schematics

Comments

Only logged in users can leave comments

angela_proc_burgarolas

3 days ago

When I try to upload the library into the program it says that the file isn't recognized as a library. Does anyone else have this problem? How could I fix it?

alexandrite24

10 days ago

How to upload code here to arduino

cuppermo

a year ago

This is going to be alot of fun i can tell. By the way .I am not Interested In the Moment right know but this is a good Project. Keep up the Great Work!

milespeterson101

a year ago

Yes! I was able to use this code and print out the temp and humidity to an OLED display, and have the sensor outside my window so I could see the temp and humidity without having to go outside! Very nice project, and was lots of fun to upgrade!

alexanderreddy

a year ago

Thanks for the good explanation - Inspired and Created the Channel - https://www.youtube.com/@AlexArduinoProjects - Thanks

milespeterson101

a year ago

Can you please post a schematic with the 3 pin sensor?

alexanderreddy

a year ago

https://youtu.be/zDC8pEDqgXk

swapnil2011

a year ago

A very good tutorial but my only problem is that there were no schematics for the 3-pin sensor (which made me waste my time searching) and there were no comments in the code to explain it better. Just some feedback, I hope you see this :)

andrea7zguz

2 years ago

Very interesting project

supratim069

2 years ago

Awesome Explanation of Using DHT11

mastercoder1234

2 years ago

Do you need to use the DHT22?

teddy1001

2 years ago

How do you make the circut with a 3 pin sensor

mojang231

2 years ago

have you guys heard of this website all about circuits????? It has over 700 articles and podcasts for Arduino/tech lovers!

mojang231

2 years ago

bet bro, making a spray fan that measures temperature using one of those, yet i am only 11

milespeterson101

a year ago

Me too, lol

pharsh2121

2 years ago

in the schematics, where have you used a 3 pin dht 11 please reply quick

Anonymous user

2 years ago

Thanks so much for the code, i am currently creating a clock with temperature and humidity readings, I have used other code that sometimes gives negative values and incorrect numbers, and this is the first bit of code that works very well Thanks! :)

Anonymous user

2 years ago

What's are the pins are used to connect data pin of dht11 to Arduino nano reply immediately

KrypticCoconut

2 years ago

mine has 3 pins what do i do?

arcaegecengiz

2 years ago

You connect the pin labelled '-' to GND, the pin labelled 'S' is the sensor pin, and you connect the pin in the middle to 5V

Anonymous user

2 years ago

i have a dht11 sensor and i did everything correctly and copy-pasted the code but is shows 0.0. btw I'm a begginer and i dont understand everything correctly.

Anonymous user

2 years ago

Just bought my starter kit and was struggling with figuring out why it was returning zero. Swaped the VCC and Signal wires and voila, it works! Thank you!

norang

2 years ago

I had the same issue. Do you use the three-pin version of dht11? Then, you should change wiring since the configuration of the pins is different. Check this link below. https://www.circuitbasics.com/wp-content/uploads/2015/12/DHT11-Pinout-for-three-pin-and-four-pin-types-2.jpg

Anonymous user

2 years ago

Hello, I have the 4 Pin version. But as a beginner I can't identify the resistor - waht is the Ohm value? Regards, Kai

arcaegecengiz

2 years ago

4.7 KΩ ±5%

Anonymous user

2 years ago

Thanks, arcaegecengiz. Simple and great article

Anonymous user

2 years ago

I wanna advise users of this particular breakout board shown in the first picture that I found a big issue on the pcb.The Vcc line is connected with the NC pin because someone supposed that the latter wasn't connected. Instead, the NC pin is connected to the GND pin and this will cause an short-circuit at Vcc line (5 or 3,3 Volt). To solve this problem, simply cut the NC pin of DHT11 from the pcb. I hope this will help.

Anonymous user

2 years ago

IAM getting a value from sensor nan for temperature and humidy also nan

Anonymous user

2 years ago

I have always wanted to do something like this, but how do you see what the sensor reads?

titanic123

2 years ago

When i upload the code and verify it it says dht11.h does not represent a name or type what should i do? thanks!!!

arcaegecengiz

2 years ago

I'm guessing you haven't got the dht library installed.

Anonymous user

2 years ago

I'm using the DHT11 sensor to check if it is raining, everything works when the Serial Monitor is on, but when I connect the arduino to a battery or to my computer the DHT11 sensor doesn't work anymore. What could be the problem?

Anonymous user

2 years ago

*sufficient

Anonymous user

2 years ago

Maybe the voltage isn't sufficent enough.... What Board Are You Using

Anonymous user

2 years ago

I am get the temperature as 0 and even the humidity as 0.i have checked the circuit but nothing is wrong. I think there some issue with the ohm value. please tell the ohm value and how to prepare if I don`t have the exact one.

Anonymous user

2 years ago

Is it possible 80% humidity and temperature 28 celcius ? is it correct or wrong ?

Anonymous user

2 years ago

Somehow my sensor always says 0 degrees and 0 humidity, what could be the problem?

arcaegecengiz

2 years ago

Try checking the wiring

Anonymous user

2 years ago

Nice project, i am thinking about a similair project. In my bathroom i have humidity controlled ventilation, while/after taking a shower humidity rises and fan starts to run. Problem is the big difference between natural RH in summer and winter. To understand this some explanation about Relative Humidity may help. The amount of water the air can contain depends on the temperature. Take one cubic meter of air 20ºC and 60% RH. This contains about 0,009kg water. Cool this down to 12ºC and RH shall be 100% with the same amount of water. Cooling deeper shall result in condensing water. Heating the same air to 25ºC and RH is around 45%. Therefore RH in the winter is much lower, every house needs fresh air from outside. In the winter this is heated to a comfortable temperature with low RH as result. The bath room fan wont start in the winter or keeps running in the summer. I want to use two DHT11 sensors, one in the bathroom and the other as reference outside the bathroom. If the bathroom RH rises 5-10% above the reference RH fan starts running.

Anonymous user

2 years ago

Why do you put 2 here :"Serial.println((float)DHT11.humidity, 2)" and also here :"Serial.println((float)DHT11.temperature, 2)" ? Please also tell me how exactly should I convert the temperature from celsius to fahrenheit ?

Anonymous user

2 years ago

The 2 is to tell the serial function how many decimal points it should print From the official reference: Serial.print(1.23456, 2) gives "1.23" this is the reference page https://www.arduino.cc/reference/en/language/functions/communication/serial/print/

Anonymous user

2 years ago

Just add this: Serial.print("Temperature (F): "); Serial.println((float)(DHT11.temperature*1.8)+32, 2);

Anonymous user

2 years ago

Just one thing is bothering me. 100% humidity doesn't mean you're underwater. If it says 60% humidity, the air is not 60% percent water, it has just absorbed 60% of the total amount of water it can hold. If it is 100% humidity it just means the air cant absorb any more water without the water condensing.

arcaegecengiz

2 years ago

That was only supposed to be a joke.

Anonymous user

2 years ago

i had follow the connection of the diagram.. and I had install the library that u giving... why I still have this error... avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20 An error occurred while uploading the sketch

Anonymous user

2 years ago

I've downloaded the library but IDE still can't find it. What else should I do in order to recognize it?

IoT_hobbyist

2 years ago

you can install DHT sensor library by Adafruit. See full instruction here: https://arduinogetstarted.com/tutorials/arduino-temperature-humidity-sensor

Anonymous user

2 years ago

great explanation of things. This answered a few questions I've been wondering about. I do have on question I.m having trouble finding an answer to though. I hope you can take a moment to help. what does the line "dht11 DHT11;" do ? is this just renaming dht11 to DHT11? could this line say "dht11 ABCTEMP;" instead?

Anonymous user

2 years ago

Hello, I would like to request permission to use some of the information and pictures in this project for my senior design project.

Anonymous user

2 years ago

Why is it that it only shows zero even my pins are in the right place?

Anonymous user

2 years ago

I don't have the "dht11.h" library where I can get it

Anonymous user

2 years ago

You have to download the .zip (it's at the end of this article, scroll back up) and then add it (Sketch > Include Library > Add .ZIP Library).

Anonymous user

2 years ago

Hi, I have uploaded the code, installed the library and wired the sensor correct as labelled. However, it is giving me an error code. avrdude: error: programmer did not respond to command: exit bootloader. That is the error code that i get. What do i do?

mariotastic_mango

2 years ago

Thank you for the help😀

Anonymous user

3 years ago

Thanks so much for the code, i am currently creating a clock with temperature and humidity readings, I have used other code that sometimes gives negative values and incorrect numbers, and this is the first bit of code that works very well Thanks! :)

Anonymous user

3 years ago

i have a dht11 sensor and i did everything correctly and copy-pasted the code but is shows 0.0. btw I'm a begginer and i dont understand everything correctly.

Anonymous user

2 years ago

Just bought my starter kit and was struggling with figuring out why it was returning zero. Swaped the VCC and Signal wires and voila, it works! Thank you!

norang

2 years ago

I had the same issue. Do you use the three-pin version of dht11? Then, you should change wiring since the configuration of the pins is different. Check this link below. https://www.circuitbasics.com/wp-content/uploads/2015/12/DHT11-Pinout-for-three-pin-and-four-pin-types-2.jpg

Anonymous user

4 years ago

What's are the pins are used to connect data pin of dht11 to Arduino nano reply immediately

Anonymous user

4 years ago

i had follow the connection of the diagram.. and I had install the library that u giving... why I still have this error... avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20 avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30 avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20 An error occurred while uploading the sketch

Anonymous user

4 years ago

Hi, I have uploaded the code, installed the library and wired the sensor correct as labelled. However, it is giving me an error code. avrdude: error: programmer did not respond to command: exit bootloader. That is the error code that i get. What do i do?

Anonymous user

4 years ago

I am get the temperature as 0 and even the humidity as 0.i have checked the circuit but nothing is wrong. I think there some issue with the ohm value. please tell the ohm value and how to prepare if I don`t have the exact one.

Anonymous user

4 years ago

I wanna advise users of this particular breakout board shown in the first picture that I found a big issue on the pcb.The Vcc line is connected with the NC pin because someone supposed that the latter wasn't connected. Instead, the NC pin is connected to the GND pin and this will cause an short-circuit at Vcc line (5 or 3,3 Volt). To solve this problem, simply cut the NC pin of DHT11 from the pcb. I hope this will help.

Anonymous user

4 years ago

Is it possible 80% humidity and temperature 28 celcius ? is it correct or wrong ?

Anonymous user

4 years ago

Why is it that it only shows zero even my pins are in the right place?

Anonymous user

4 years ago

Hello, I would like to request permission to use some of the information and pictures in this project for my senior design project.

Anonymous user

4 years ago

Thanks, arcaegecengiz. Simple and great article

Anonymous user

4 years ago

I get dht11.h:No such file or directory when I compile sketch. ???

arcaegecengiz

2 years ago

Have you installed the library correctly?

Anonymous user

5 years ago

Somehow my sensor always says 0 degrees and 0 humidity, what could be the problem?

arcaegecengiz

2 years ago

Try checking the wiring

Anonymous user

5 years ago

I'm using the DHT11 sensor to check if it is raining, everything works when the Serial Monitor is on, but when I connect the arduino to a battery or to my computer the DHT11 sensor doesn't work anymore. What could be the problem?

Anonymous user

2 years ago

*sufficient

Anonymous user

2 years ago

Maybe the voltage isn't sufficent enough.... What Board Are You Using

Anonymous user

5 years ago

I've downloaded the library but IDE still can't find it. What else should I do in order to recognize it?

IoT_hobbyist

2 years ago

you can install DHT sensor library by Adafruit. See full instruction here: https://arduinogetstarted.com/tutorials/arduino-temperature-humidity-sensor

Anonymous user

5 years ago

I have always wanted to do something like this, but how do you see what the sensor reads?

Anonymous user

5 years ago

I don't have the "dht11.h" library where I can get it

Anonymous user

2 years ago

You have to download the .zip (it's at the end of this article, scroll back up) and then add it (Sketch > Include Library > Add .ZIP Library).

Anonymous user

5 years ago

IAM getting a value from sensor nan for temperature and humidy also nan

jmppts

5 years ago

great explanation of things. This answered a few questions I've been wondering about. I do have on question I.m having trouble finding an answer to though. I hope you can take a moment to help. what does the line "dht11 DHT11;" do ? is this just renaming dht11 to DHT11? could this line say "dht11 ABCTEMP;" instead?

titanic123

5 years ago

When i upload the code and verify it it says dht11.h does not represent a name or type what should i do? thanks!!!

arcaegecengiz

2 years ago

I'm guessing you haven't got the dht library installed.

KrypticCoconut

5 years ago

mine has 3 pins what do i do?

arcaegecengiz

2 years ago

You connect the pin labelled '-' to GND, the pin labelled 'S' is the sensor pin, and you connect the pin in the middle to 5V

7iambatmany

2 years ago

What is the sensor pin?

pickaxmax

2 years ago

wow i didnt know that your here :0

Anonymous user

5 years ago

Hello, I have the 4 Pin version. But as a beginner I can't identify the resistor - waht is the Ohm value? Regards, Kai

arcaegecengiz

2 years ago

4.7 KΩ ±5%

mastercoder1234

2 years ago

the SI unit of electrical resistance, expressing the resistance in a circuit transmitting a current of one ampere when subjected to a potential difference of one volt.

Anonymous user

6 years ago

Just one thing is bothering me. 100% humidity doesn't mean you're underwater. If it says 60% humidity, the air is not 60% percent water, it has just absorbed 60% of the total amount of water it can hold. If it is 100% humidity it just means the air cant absorb any more water without the water condensing.

arcaegecengiz

2 years ago

That was only supposed to be a joke.

Anonymous user

6 years ago

Nice project, i am thinking about a similair project. In my bathroom i have humidity controlled ventilation, while/after taking a shower humidity rises and fan starts to run. Problem is the big difference between natural RH in summer and winter. To understand this some explanation about Relative Humidity may help. The amount of water the air can contain depends on the temperature. Take one cubic meter of air 20ºC and 60% RH. This contains about 0,009kg water. Cool this down to 12ºC and RH shall be 100% with the same amount of water. Cooling deeper shall result in condensing water. Heating the same air to 25ºC and RH is around 45%. Therefore RH in the winter is much lower, every house needs fresh air from outside. In the winter this is heated to a comfortable temperature with low RH as result. The bath room fan wont start in the winter or keeps running in the summer. I want to use two DHT11 sensors, one in the bathroom and the other as reference outside the bathroom. If the bathroom RH rises 5-10% above the reference RH fan starts running.

Anonymous user

2 years ago

Just add this: Serial.print("Temperature (F): "); Serial.println((float)(DHT11.temperature*1.8)+32, 2);

Anonymous user

2 years ago

Why do you put 2 here :"Serial.println((float)DHT11.humidity, 2)" and also here :"Serial.println((float)DHT11.temperature, 2)" ? Please also tell me how exactly should I convert the temperature from celsius to fahrenheit ?

Anonymous user

2 years ago

The 2 is to tell the serial function how many decimal points it should print From the official reference: Serial.print(1.23456, 2) gives "1.23" this is the reference page https://www.arduino.cc/reference/en/language/functions/communication/serial/print/