arduino and dht11 output to lcd module manufacturer
Here is the simple code that will make it work correctly. I had the same issue and just figured it out. I put some comments about the changes I made and stuff I figured out…. Make sure you have the 3 libraries that are noted “#include”
Hello friends! Welcome back to ElectroDuino. This blog is based on DHT11 Temperature and Humidity Sensor Arduino Code with LCD Display. Here we will discuss Introduction Temperature and Humidity Monitoring System, Circuit diagram, Working and DHT11 Temperature and Humidity sensor Arduino Code with LCD Display.
In the previous blog posts, we were learning about the “DHT11 Temperature and Humidity Sensor Module” and “Interfacing DHT11 with Arduino”. In this project, we will discuss how to make a Temperature and Humidity Monitoring System. Where we will print the Temperature and Humidity value on a 16×2 LCD display using DHT11 and Arduino. DHT11 is the cheapest humidity and temperature sensor, it provides high reliability and long-term stability output. This is a very small and portable Temperature and Humidity Monitoring system so we can use it at home, office, school, etc. places. It gives us the Temperature and Humidity value of around it 24 x7. Here we will build this system and learn how to write the DHT11 Temperature and Humidity Sensor Arduino Code with LCD Display.
Before writing the Arduino Code we need to install two Libraries in our Arduino IDE Software, one is ” dht.h ” DHT11 sensor Library and Another one is “LiquidCrystal.h” 16×2 LCD Display Library You can Download the Library file by click on the Download Button.
Welcome to ProteShea – in this project, we’re going to interface a DHT11 temperature and humidity sensor, and display the data on a 16×2 LCD. If you haven’t read
ProteShea, LLC is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Some links may be affiliate links, in which ProteShea, LLC earns a commission if you use that affiliate link. Please note that this is at no additional cost to you and helps us in creating more content.
Please see Project 9 on how to interface the 16×2 LCD in 4-bit mode. You should have pins 4, 6, and 11 – 14 of the LCD connected to Uno pins 2, 3, and 4 – 7, respectively.
The 20×4 LCD adds two extra rows and four extra columns per row compared to the 16×2 LCD. Similar to the 16×2, the 20×4 LCD uses the Hitachi controller so the commands and interfaces are the same. It also has the same 16-pin header, allowing you to unplug the 16×2 LCD and plug in the 20×4 without changing any wiring. The only thing we have to change is one line of code, lcd.begin(20, 4), which specifies the columns (first argument) and rows (second argument) of the LCD.
There are different types of DHT sensors such as the DHT11, DHT21, DHT22, DHT33, and DHT44. They all measure both temperature and humidity, but the difference lies mostly in their accuracy and sampling rate. For example, we show a side-by-side comparison in the table below of the two most popular DHT sensors, DHT11 and DHT22. The DHT22 has a better accuracy and range, but it has a slower sampling rate, it’s bigger in size, and double the cost of the DHT11.
To measure the temperature and humidity, a thermistor and a capacitive humidity sensor are used, respectively. The resistance of a thermistor changes with a change in temperature – as the temperature increases, the resistance decreases. For the humidity sensor, the resistance between the two electrodes changes with a change in humidity. Both of these changes in resistance are measured by the IC on the sensor and sent to the host via a 1-wire interface. Each sample consists of a 40-bit data packet.
We are using a 3-pin DHT11 sensor as shown in the image below. The pins are “+”, “OUT”, and “-.” The sensor can be supplied with both +5Vdc or +3.3Vdc – we’ll be supplying +5Vdc to it.
We are mounting the DHT11 sensor to the 2.54mm pitch section of Modulus with a right-angle (R/A) female header, as shown in the image below. Solder the 4-pin R/A female header to the edge of the board. Next, solder a 4-pin male header adjacent to the female header. Once you have the headers soldered on, flip the board over and make a solder bridge between the adjacent pins of the headers.
Wire-wrap the “+” pin to +5Vdc which is any of the pins in column 20 on the 4×26-pin breakout. Then wire-wrap the “-” pin to the GND vector just below the 4×26-pin breakout. Use a 12″ F/M jumper to connect the “OUT” pin to pin 8 of the Uno.
First, place the breadboard in the bottom storage compartment to limit the length of the jumper wires. You’ll need to supply +5V and GND to the power and ground rails on the breadboard by using the provided banana jack to test-lead clip cables. You will need two male header pins to mount the test-lead clips on the breadboard side. Plug the Type A side of the USB cable into USB1 receptacle and the Type B side into the Uno’s receptacle. Power up the FuelCan with the AC-DC power adapter.
Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The first sketch is used with the 16×2 LCD. The second sketch is used with the 20×4 LCD. The DHT11 sensor is sampled every two seconds since sampling faster causes errors.
Want to keep a log of the climate in your greenhouse, build a humidor control system, or track temperature and humidity data for a weather station project? AOSONG’s DHT11 or DHT22 Temperature and Humidity Sensor could be the perfect fit for you!
These sensors are factory-calibrated and do not require any external components to function. With just a few connections and a bit of Arduino code, you can begin measuring relative humidity and temperature right away.
They provide temperature and humidity readings accurate to within one decimal place, which is a plus. The only drawback is that they only provide new data every second or two, but for the price and performance, it’s hard to complain.
The DHT11 and the DHT22 are the two most widely used sensors in the DHTxx series. They look kind of the same and have the same pinout, but their specs are different.
Of the two, the DHT22 is more expensive and, undoubtedly, has better specifications. The DHT22 can measure temperatures from -40°C to +125°C with an accuracy of ±0.5°C, while the DHT11 can measure temperatures from 0°C to 50°C with an accuracy of ±2°C. In addition, the DHT22 sensor can measure relative humidity from 0 to 100% with an accuracy of 2-5%, while the DHT11 sensor can only measure relative humidity from 20 to 80% with an accuracy of 5%.
Despite the fact that the DHT22 is more accurate, precise, and capable of operating in a wider range of temperature and humidity, there are three areas where the DHT11 completely outperforms the DHT22 – It is more affordable, more compact, and has a higher sampling rate. DHT11 takes a reading once per second (or 1Hz sampling rate), while DHT22 takes a reading once every two seconds (or 0.5Hz sampling rate).
Despite these differences, the operating voltage of both sensors ranges from 3 to 5 volts, with a maximum current of 2.5mA (during conversion). The best part is that DHT11 and DHT22 sensors are swappable, which means that if you build your project with one, you can simply unplug it and replace it with another. Your code may need to be tweaked slightly, but the wiring remains the same!
The humidity sensing component has two electrodes with a moisture-holding substrate (usually a salt or conductive plastic polymer) in between. As the humidity rises, the substrate absorbs water vapor, resulting in the release of ions and a decrease in the resistance between the two electrodes. This change in resistance is proportional to the humidity, which can be measured to estimate relative humidity.
Technically, all resistors are thermistors in the sense that their resistance changes slightly with temperature, but the change is typically very small and difficult to measure.
Thermistors are designed so that their resistance changes dramatically with temperature (by 100 ohms or more per degree). The term “NTC” stands for “Negative Temperature Coefficient,” which means that resistance decreases as temperature rises.
The sensor also includes an 8-bit SOIC-14 packaged IC. This IC measures and processes the analog signal using stored calibration coefficients, converts the analog signal to digital, and outputs a digital signal containing the temperature and humidity.
VCC pin provides power to the sensor. Despite the fact that the supply voltage ranges from 3.3V to 5.5V, a 5V supply is recommended. With a 5V power supply, the sensor can be placed up to 20 meters away. With 3.3V supply voltage, the sensor can be placed up to 1 meter away; otherwise, the line voltage drop will cause measurement errors.
Connecting DHT sensors to Arduino is straightforward. They have fairly long 0.1′′-pitch pins, allowing them to be easily plugged into any breadboard. Connect the VCC pin to the Arduino’s 5V and the GND pin to ground. Finally, connect the Data pin to digital pin #8.
To ensure proper communication between the sensor and MCU, you must also add a 10K pull-up resistor between the Data line and VCC (to keep the signal HIGH). If you have a breakout board for the sensor, you do not need to add an external pull-up resistor, as it already contains one.
The DHTxx sensors have their own proprietary single-wire data transfer protocol. This protocol requires precise timing. We don’t have to worry too much about this, though, because we’ll be using the DHTlib library, which handles almost everything.
To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries.
After installing the library, copy and paste this sketch into the Arduino IDE. The following test sketch will print the temperature and relative humidity values to the serial monitor. Try out the sketch, and then we’ll go over it in more detail.
The sketch begins by including the DHT library. Following that, we specify the Arduino pin number to which our sensor’s Data pin is connected and create a DHT object.
In the loop, we use the read22(dataPin) function to read the DHT22. This function takes as a parameter the sensor’s Data pin number. When working with DHT11, you must use the read11() function; to do so, you just need to uncomment the second line.
If you’re constructing your own incubator or a similar project, you’ll need a 16×2 character LCD rather than a serial monitor to display the current temperature and humidity levels. So, in this example, we’ll also connect the LCD to the Arduino in addition to the DHT11 and DHT22 sensors.
The sketch below will display the temperature and relative humidity values on the 16×2 character LCD. This sketch is similar to the previous one, except that the values are printed on the LCD.
I have the dht11 reading and printing to lcd and serial monitor.I have the dht11 controlling two relays one for temp and one for humidity.When the relay turns on the dht11 stops sending readings and freezes and stops reading? Any way I can fix that ?thanks
From what I’ve read from the datasheet it can’t be read from more than once every 2 seconds. Changing the delay to 2000 cleared the issue up right away for me
The output is to the serial monitor, unless you have connected an LCD. The video will show you how to open the serial monitor if you don’t already know how to.
A quick question tho, do you have a tutorial on how to connect this to a wireless transceiver?? also in theory could i connect more then one humidity detector to an arduino in order to detect humidity from more then one spot? Thank you again and i’ve subscribed!
Hi Jose, you can definitely connect more than one sensor to a single Arduino. You would basically duplicate the code, and have a separate pins read the data from each sensor. As for connecting them to a wireless tranceiver, I’m sure it’s possible, but you would probably need to use another microcontroller as a hub to transmit the data. I haven’t tried it yet though, so don’t take my word for it!
Hello, I built my first arduino project (measuring the room temperature and humidity with the DHT11) during Christmas holidays. The readings of the values were shown on the screen of my laptop. The measured room temperature was correct, but the measured humidity was much too low (about 20%RH). What can be the reason for ithe low humidity? And how can the sensor (if needed) be recalibrated?
I haven’t tried connecting multiple sensors, but it should be fairly easy. You would just duplicate the code and use a separate pin to read the data for each sensor
Probably not, since the signal is at the same voltage as Vcc. If you swap the Vcc and signal pins, the output will just read -999.00 for temp and humidity.
vcc is the left one, signal the middle one and ground is the round one, in case of a 3 pin DHT11. the diagram above is not right. i was getting the same problem here.
IN MY CASE IN THE DHT-11 BOARD WRONG RESISTOR WAS SOLDERED, WITHOUT KNOWING TAT I HAD TRIED ALL STUFF, GIVEN 10K PULL UP ADDITIONALLY.. DIDN’T WORKED FINALLY TRACED THE RESISTANCE BETWEEN PINS IT WAS 5 OHMS.. THEN BACK TRACED & REMOVED TAT & PULLED UP WITH 10k SOLVED MY ISSUE.. GUESS U TOO HAVE THE SAME ISSUE.. JUST CHK OUT..
The diagram is correct for most three pin DHT11 modules. Depending on the manufacturer, the pins on the PCB might be different though. The pins should be labelled with S for signal and “-” or “GND” ground.
Then i understood, that the breadboard has not 2 power circuits (top and bottom), but four (top left, top right, bottom left, bottom right). This is the thing which was never said on youtube)
See the section “Output Humidity and Temperature Readings to an LCD Display” on a desktop… If you are viewing it on mobile, the full code might not display. Hope this helps
Can you guys help me in this. All I want is to design a circuit that could predict a rainfall or water and send a message to the user to his phone.Also keeping in mind about the humidity and temperature factors.
It sounds like you want to control the heater with the DHT11 and have the readings output to an LCD too… You can use the DHT11 to control the signal to a 5V relay, similar to what’s done in this article: https://www.circuitbasics.com/build-an-arduino-controlled-power-outlet/
Then you just need to add the code to initialize the LCD, include the LiquidCrystal library, and change the “serialprint()” functions to “lcd.print(). We have another article on setting up an LCD on the Arduino if you need help with it: https://www.circuitbasics.com/how-to-set-up-an-lcd-display-on-an-arduino/
i didnt have any trouble interfacing the arduino, lcd and the dht11 sensor and my codes were quite right since when i run it, nothing’s odd in the output. but when i connect the relay,in which an ac device is connected, as an output that turns on after a couple of minutes, the temperature and humidity dislayed on the lcd becomes odd, like chinese and numbers, after some time. i checked my codes but i cant figure out whats wrong with it.
please help me.. i won’t get Alarm temperature and humidity..and show in lcd display 16×2.. and changeing temperature, humidity alarm set point HOW IS DO… PLEASE HELP ME.
So curiously, I had already downloaded and installed the latest version of DHTLib (v0.1.21) versus the older version (v0.1.14) that is provided here. And I kept getting 0.00 values for the temp and humidity readings as Alex reported on April 20, 2016 in a posting above. I scratched my head for a while until I remembered I had the newer version of the library installed. So I removed that, installed the older v0.1.14 version, and bam, lo and behold, I started getting real values back. So this may be the same problem that Alex had, too.
I’ve looked at the brief changelog history in dht.cpp file, and I’m seeing no obvious reason that might allow v0.1.14 to work, but not the newer v0.1.21. Anyone have thoughts about this?
Any comments about DHTLib v0.1.14 vs. v0.1.21, and why this simple Arduino sketch works in the former, but not the latter? The brief history in the cpp file header for v0.1.21 looks like it took care of a few issues so my first instinct is to use that, but again, it results in all zero readings. Anyway, if no comments, well, I’ll have to take a look through the diffs between the two versions to see what might be causing the issue.
vcc is the left one, signal the middle one and ground is the right one, in case of a 3 pin DHT11. the diagram above is not right. i was getting the same problem here.
The diagram is correct, but your particular DHT11 could have a different pinout depending on the manufacturer. The DHT11 I used is from Keyes, what type do you have?
Are you using the four pin DHT11? If so you’ll need to put a 10K Ohm resistor between the Signal line and Vcc. I just added another diagram to the post to make it a bit clearer. That may be causing your issue.
Thanks a lot, may you please help me out, I am using a Mega 2560 with a DHT11 sensor, my problem is that both temperature and humidity reading is just being reed as 0.00 and they are not changing. What might i be doing wrongly, I have even tried the code that accompanies these tutorials
This seems like a really simple setup, but I’ve been having a lot of trouble setting this up. Have there been changes to this library? I have downloaded it, but arduino still refuses to recognize dht or any of the related functions, like temperature/humidity. It had a lot of trouble with line 3, dht DHT;. Any advice?
Yes, the library was updated recently (v. 0.1.21) and doesn’t seem to work. If you download the zip file I put in the post, it should work. It’s the older version 0.1.14.
Hi, you mentioned you added a piece of code to show the “degree” symbol,” lcd.print((char)223)”, can you tell me if the number 223 is from the ASCII table.
vcc is the left one, signal the middle one and ground is the right one, in case of a 3 pin DHT11. the diagram above is not right. i was getting the same problem here.
i am doing fire alarm system using dht and lcd and GSM sim800l how can i make argument to send message from gsm if the sensor reading is higher that the set temp and how to declare it thanks for your response
After uploading a code my dht-11 keeps reading zero ‘0’ for both humidity and temperature as the output on my serial monitor. please what could be the problem?
I am very happy to inform you that I fixed successfully the temp and humidity project with LCD display. I would like to subscribe but cannot find the link.Many thanks
C:\Users\mhine\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\cores\esp8266/Arduino.h:227:63: error: cannot convert ‘volatile uint32_t* {aka volatile unsigned int*}’ to ‘volatile uint8_t* {aka volatile unsigned char*}’ in initialization
Hi. I have the same issue with the same board. Did you get it to succeed in the end? I would be interested, but I feel that it may be a compatibility issue with a 3rd-party board. I have tried the exact code with other Arduinos that I have and it works just fine.
I get this same error when I try to use the Arduino 101 instead of the Uno. I think the library doesn’t support the board. I would try finding a different DHT library, there are several others out there.
I Have issues with the Arduino recognizing the file dht.h. Was told no such file exist, meanwhile I have uploaded the zip file into the Arduino IDE, which showed in the file directory.
Did you use the library in the zip file from the post, or did you download it from the Arduino.cc page? Version 0.1.21 has some issues and doesn’t appear to work. The zip file in the post is version 0.1.14, and it does work. Also, are you using the Uno, or another board? I couldn’t get the library to work on my Arduino 101…
In this language, does declaring an object variable (as in “dht DHT;”) automatically instantiate it? I am more used to other languages that would need to follow the declaration with something along the lines of “DHT = new dht(params, for, constructor);” Does this normally go without saying in C++, or is this something the Arduino environment automatically adds at the preprocessing** stage?
**: If not “preprocessing,” then whatever else Arduino parlance calls the process of converting/expanding the “Processing” (??) or “Wiring” (???) code into standard C/C++ ????
hey can you pls help me how to use rf module with the above project. i am using two arduino uno, DHT11, LCD, RF transmitter and receiver. please can u give me a code to display temperature and humidity on the receiver side lcd…
to start the cummunication the ardduino will give LOW to the data line,after the dht finished the transmition of data,the line will return to HIGH,IS THAT CORRECT???
Thanks for the mod, skyfox66. Being in America among the holdouts, I am of course still using degrees F. After days of struggling and searching I finally got this combination of parts and code to work right. (After I found this website).
I connected the LCD and the DHT11 and copied and pasted the code. It uploaded and then I look at my LCD and all I see are white boxes on the top of the display. Can anyone help me?
I copied this exactly and got it to display temperature and humidity, but it flashes -999 for temp and -999 for humidity every other second. For example, it will display correct readings for one second, then the -999 for both readings the next second.. Flashing between the two. Any ideas why it might be doing this. I have been playing with the code, rechecking pins, etc, but I cant seem to pinpoint the problem. Any input is appreciated.
hello, i need some help, i want code for, if i m sending message from mobile (e.g. ABC) to arduino via gsm module then the values of temperature and humidity receiving specific number
I have arn Arduino y module that I am using to trgger an extractor fan in a shower. I was wondering whether this humidity sensor could be used to simply close the 5v circuit so teh fan runs on until teh humidity is below a set vaue. Is that possible simply?
Hi.recently i conduct sensor circuitry.in source code,i notice that it use \xF8 to display temperature in degree celcius.what is the function of that?
I followed the instructions exactly, wiring was good, code was an exact replica of that given. Everything was correct, but I got -999 error message every time. I was using a three pin sensor, triple checked my wiring against the diagram. I increased the delay time to 3000ms. I was definitely using the correct older version of the library. After throwing out the sensor thinking it faulty, I have since discovered that the diagram above is does not apply to every dht11, that there are some where the pins are in a different order.
What does this mean? in every other arduino program I can find that uses additional libraries, the library is called first, then the code goes straight on to initialising the variables and describing the setup. I have not been able to find any other mention of the library name mentioned twice like this. A few people have asked about this, with no answers given. I cant even search for it because I dont know what to search by.
Awesome website – every content is superb – We have a huge collection of branded Electronics product please have a look here https://webearnorg.blogspot.com/2018/05/electronics-supply-stores-near-me.html
Clear, informative and knowledgeable. Moisture from the air collects on the film and causes changes in the voltage levels between the two plates. This change is then converted into a digital measurement of the air’s relative humidity after taking the air temperature into account.
You will get 100% humidity if you put the sensor in water and it works. Use an SHT31-D breakout board to detect humidity and temperature. I’m sure you didn’t mean you are going to submerge the sensor. The SHT31-D is more accurate and easier to install and costs about the same as the DHT11 /22 both of which really aren’t accurate at all.
i have changed the sensor, checked voltages at each junction,switched pull up resistor, included the exact library available here but couldn’t get the accurate result,
Ine is set up exactly as you show. I get -999.00 for both humidity and temperature. I have 2 different sensors (both DHT11) and I get the same readings. I even set this up on an RPI 3B+ and the readings were similar. 1.0 temp and humidity. What am I doing wrong?
I’m a bit new to audrino and i started my first project. I found that this tutorial was the most comprehensive out there, which is awesome. One thing that i’m running into a bit of issue on is that im an “400 invalid_request” while attempting to import the DTH library. I was wondering if you could provide a little assistance to get pass this issue. Please see the full error message below.
I’m wondering if there’s a way to have this working intermittently? I want to moderate the humidity levels in food containers to prevent mould. If this was running off a battery would it last long enough?
I can not keep my display from blinking the temp and humidity values. It displays the value but blinks back and forth to -999.00. Thanks for the help I’m new
Your so awesome dude. I owe you a lot! Thanks for the tutorial dude. you’d help many people. keep going! God bless more power. Im from philippines ^_^
Still getting -999.00 on both temperature and humidity with LCD. If I connects ONLY DTH11 to Arduino with serial monitor it works fine, BUT if I connect it to LCD as described above it shows -999.00 In both LCD and serial monitor. It looks like it disables the DTH11 when connected to LCD. It does not work with dely(2000); or any other value.
i don’t know why but the LCD shows me white circles and within them the text is written also the temp and humidity are a constant 0 even with the serial monitor
It’s good idea for projects. I am thinking of building my own weather unit soon. Please can someone help me with a simulation circuit that will show the response graphs of dht11 for temperature and humidity
How would you configure Celsius to Fahrenheit when doing the LCD version? I read others commenting how with out the LCD but not with the code for using the LCD.
I’m looking to couple this humidity sensor with a 5V relay to actuate a small on/off valve depending on the humidity level. Essentially, I’d like valve to open when the humidity reading from the sensor goes above, say, 75%, and closes when the reading goes below 60%. Do you have any recommendations?
I am a hobbyist and has certain experience in electronics and wish to adopt programming. So kindly some one can help me to achieve the above goal with codes and probable sketches for the connections.Hope to receive a reply in this respect from your side.
HELLO, thank you for the big assistance. I’d like to share to u the screenshoot of my serial monitor output… Atleast let me show how it looks like & help me to debug. Big thanks to you
You have to adjust the wait time to less to count for the fact that the sensor Only gives an output for a small amount of time so play around with that to get it to work
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
If you do not know about DHT11, DHT22 temperature sensor and LCD (pinout, how it works, how to program ...), learn about them in the following tutorials:
The above code also work for Arduino Nano. A grandfather, who learns through this tutorial to guide his grandchild has tested this code with Arduino Nano and send us the result like below:
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
※ OUR MESSAGESYou can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
ArduinoGetStarted.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com, Amazon.it, Amazon.fr, Amazon.co.uk, Amazon.ca, Amazon.de, Amazon.es and Amazon.co.jp
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
This article is a guide for the popular DHT11 and DHT22 temperature and humidity sensors with the Arduino. We’ll explain how it works, show some of its features and share an Arduino project example that you can modify to use in your own projects.
These sensors contain a chip that does analog to digital conversion and spit out a digital signal with the temperature and humidity. This makes them very easy to use with any microcontroller.
The DHT11 and DHT22 are very similar, but differ in their specifications. The following table compares some of the most important specifications of the DHT11 and DHT22 temperature and humidity sensors. For a more in-depth analysis of these sensors, please check the sensors’ datasheet.
The DHT22 sensor has a better resolution and a wider temperature and humidity measurement range. However, it is a bit more expensive, and you can only request readings with 2 seconds interval.
Despite their differences, they work in a similar way, and you can use the same code to read temperature and humidity. You just need to select in the code the sensor type you’re using.
DHT sensors have four pins as shown in the following figure. However, if you get your DHT sensor in a breakout board, it comes with only three pins and with an internal pull-up resistor on pin 2.
Note: if you’re using a module with a DHT sensor, it normally comes with only three pins. The pins should be labeled so that you know how to wire them. Additionally, many of these modules already come with an internal pull up resistor, so you don’t need to add one to the circuit.
To read from the DHT sensor, we’ll use the DHT library from Adafruit. To use this library you also need to install the Adafruit Unified Sensor library. Follow the next steps to install those libraries.
After installing the DHT library from Adafruit, type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library and install it.
In the loop(), at the beginning, there’s a delay of 2 seconds. This delay is needed to give enough time for the sensor to take readings. The maximum sampling rate is two seconds for the DHT22 and one second for the DHT11.
Reading temperature and humidity is very simple. To get humidity, you just need to use the readHumidity() method on the dht object. In this case, we’re saving the humidity in the h variable. Note that the readHumidity() method returns a value of type float.
After uploading the code to the Arduino, open the Serial Monitor at a baud rate of 9600. You should get sensor readings every two seconds. Here’s what you should see in your Arduino IDE Serial Monitor.
If you’re trying to read the temperature and humidity from the DHT11/DHT22 sensor and you get an error message in your Serial Monitor, follow the next steps to see if you can make your sensor work (or read our dedicated DHT Troubleshooting Guide).
Wiring: when you’re building an electronics project, you need to double-check the wiring or pin assignment. After checking and testing that your circuit is properly connected, if it still doesn’t work, continue reading the next troubleshooting tips.
Power: the DHT sensor has an operating range of 3V to 5.5V (DHT11) or 3V to 6V (DHT22). If you’re powering the sensor from the a 3.3V pin, in some cases powering the DHT with 5V solves the problem.
Bad USB port or USB cable: sometimes powering the Arduino directly from a PC USB port is not enough. Try to plug it to a USB hub powered by an external power source. It might also help replacing the USB cable with a better or shorter one. Having a USB port that supplies enough power or using a good USB cable often fixes this problem.
Power source: as mentioned in the previous tip, your Arduino might not be supplying enough power to properly read from the DHT sensor. In some cases, you might need to power the Arduino with a power source that provides more current.
Sampling rate: the DHT sensor is very slow getting the readings (the sensor readings may take up to 2 seconds). In some cases, increasing the time between readings solves the problem.
DHT sensor is fried or broken: unfortunately, these cheap sensors sometimes look totally fine, but they are fried/broken. So, even though you assembled the right circuit and code, it will still fail to get the readings. Try to use a different sensor to see if it fixes your problem.
Wrong baud rate or failed to upload code: if you don’t see anything in your Arduino IDE Serial Monitor double-check that you’ve selected the right baud rate, COM port or that you’ve uploaded the code successfully.
While building our projects, we’ve experienced similar issues with the DHT and it was always solved by following one of the methods described earlier.
You need to install the Adafruit Unified Sensor driver library. In your Arduino IDE, type in the search box “Adafruit Unified Sensor“, scroll all the way down to find the library and install it.
The DHT11 and DHT22 sensors provide an easy and inexpensive way to get temperature and humidity measurements with the Arduino. The wiring is very simple – you just need to connect the DHT data pin to an Arduino digital pin.
Writing the code to get temperature and humidity is also simple thanks to the DHT library. Getting temperature and humidity readings is as simple as using the readTemperature() and readHumidity() methods.
This tutorial shows how to use the DHT11 and DHT22 temperature and humidity sensors with the ESP32 using Arduino IDE. We’ll go through a quick introduction to these sensors, pinout, wiring diagram, and finally the Arduino sketch.
These sensors contain a chip that does analog to digital conversion and spit out a digital signal with the temperature and humidity. This makes them very easy to use with any microcontroller.
The DHT11 and DHT22 are very similar, but differ in their specifications. The following table compares some of the most important specifications of the DHT11 and DHT22 temperature and humidity sensors. For a more in-depth analysis of these sensors, please check the sensors’ datasheet.
The DHT22 sensor has a better resolution and a wider temperature and humidity measurement range. However, it is a bit more expensive, and you can only request readings with 2 seconds interval.
Despite their differences, they work in a similar way, and you can use the same code to read temperature and humidity. You just need to select in the code the sensor type you’re using.
DHT sensors have four pins as shown in the following figure. However, if you get your DHT sensor in a breakout board, it comes with only three pins and with an internal pull-up resistor on pin 2.
To read from the DHT sensor, we’ll use the DHT library from Adafruit. To use this library you also need to install the Adafruit Unified Sensor library. Follow the next steps to install those libraries.
After installing the DHT library from Adafruit, type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library and install it.
To read temperature and humidity from the DHT sensor, we’ll use an example based on the Adafruit DHT library. Copy the following code to your Arduino IDE.
There are many comments throughout the code with useful information. So, you might want to take a look at the comments. Continue reading to learn how the code works.
Then, you need to select the DHT sensor type you’re using. The library supports DHT11, DHT22, and DHT21. Uncomment the sensor type you’re using and comment all the others. In this case, we’re using the DHT22 sensor.
The temperature and humidity are returned in float format. We create float variables h, t, and f to save the humidity, temperature in Celsius and temperature in Fahrenheit, respectively.
After getting the humidity and temperature, the library has a method that computes the heat index. You can get the heat index both in Celsius and Fahrenheit as shown below:
After uploading the code, open the Serial Monitor at a baud rate of 9600. You should get the latest temperature and humidity readings in the Serial Monitor every two seconds.
If you’re trying to read the temperature and humidity from the DHT11/DHT22 sensor and you get an error message in your Serial Monitor, follow the next steps to see if you can make your sensor work (or read our dedicated DHT Troubleshooting Guide).
Wiring: when you’re building an electronics project, you need to double-check the wiring or pin assignment. After checking and testing that your circuit is properly connected, if it still doesn’t work, continue reading the next troubleshooting tips.
Power: the DHT sensor has an operating range of 3V to 5.5V (DHT11) or 3V to 6V (DHT22). If you’re powering the sensor from the ESP32 3.3V pin, in some cases powering the DHT with 5V solves the problem.
Bad USB port or USB cable: sometimes powering the ESP32 directly from a PC USB port is not enough. Try to plug it to a USB hub powered by an external power source. It might also help replacing the USB cable with a better or shorter one. Having a USB port that supplies enough power or using a good USB cable often fixes this problem.
Power source: as mentioned in the previous tip, your ESP might not be supplying enough power to properly read from the DHT sensor. In some cases, you might need to power the ESP with a power source that provides more current.
Sampling rate: the DHT sensor is very slow getting the readings (the sensor readings may take up to 2 seconds). In some cases, increasing the time between readings solves the problem.
DHT sensor is fried or broken: unfortunately, these cheap sensors sometimes look totally fine, but they are fried/broken. So, even though you assembled the right circuit and code, it will still fail to get the readings. Try to use a different sensor to see if it fixes your problem.
Wrong baud rate or failed to upload code: if you don’t see anything in your Arduino IDE Serial Monitor double-check that you’ve selected the right baud rate, COM port or that you’ve uploaded the code successfully.
While building our projects, we’ve experienced similar issues with the DHT and it was always solved by following one of the methods described earlier.
You need to install the Adafruit Unified Sensor driver library. In your Arduino IDE, type in the search box “Adafruit Unified Sensor“, scroll all the way down to find the library and install it.
With this tutorial you’ve learned how to get temperature and humidity readings from a DHT11 or DHT22 sensor using the ESP32 with Arduino IDE. Getting temperature and humidity readings with the Adafruit DHT library is very simple, you just use the readTemperature() and readHumidity() methods on a DHT object.
Now, you can take this project to the next level and display your sensor readings in a web server that you can consult using your smartphone’s browser. Learn how to build a web server with the ESP32 to display your sensor readings: ESP32 DHT11/DHT22 Web Server – Temperature and Humidity using Arduino IDE.
DHT11 is a Humidity and Temperature Sensor, which generates calibrated digital output. DHT11 can be interface with any microcontroller like Arduino, Raspberry Pi, etc. and get instantaneous results. DHT11 is a low cost humidity and temperature sensor which provides high reliability and long term stability.
In this project, we will build a small circuit to interface Arduino with DHT11 Temperature and Humidity Sensor. One of the main applications of connecting DTH11 sensor with Arduino is weather monitoring.
We will see the circuit design of DHT11 interfacing with Arduino. The DHT11 Humidity and Temperature sensor comes in two variants: just the sensor or a module.
The main difference is that the module consists of the pull – up resistor and may also include a power on LED. We have used a module in this project and if you wish to use the sensor itself, you need to connect a 5K Ω pull – up resistor additionally.
Coming to the design, the data pin of the DHT11 Sensor is connected to the Pin 11 of Arduino. A 16 x 2 LCD display is used to display the results. The control pins of LCD i.e. RS and E (Pins 4 and 6 on LCD) are connected to pins 4 and 5 of Arduino. The data pins of LCD i.e. D4 to D7 (pins 11 to 14 on LCD) are connected to pins 0 to 3 on LCD.
NOTE: For ease of connection, we have connected the DHT11 Sensor Module at the ICSP pins of the Arduino as it provides adjacent VCC, DATA and GND pins. This type of connection is not necessary and you can connect the data pin of sensor to normal Digital I/O pins.
DHT11 is a part of DHTXX series of Humidity sensors. The other sensor in this series is DHT22. Both these sensors are Relative Humidity (RH) Sensor. As a result, they will measure both the humidity and temperature. Although DHT11 Humidity Sensors are cheap and slow, they are very popular among hobbyists and beginners.
The DHT11 Humidity and Temperature Sensor consists of 3 main components. A resistive type humidity sensor, an NTC (negative temperature coefficient) thermistor (to measure the temperature) and an 8-bit microcontroller, which converts the analog signals from both the sensors and sends out single digital signal.
DHT11 Humidity Sensor consists of 4 pins: VCC, Data Out, Not Connected (NC) and GND. The range of voltage for VCC pin is 3.5V to 5.5V. A 5V supply would do fine. The data from the Data Out pin is a serial digital data.
The following image shows a typical application circuit for DHT11 Humidity and Temperature Sensor. DHT11 Sensor can measure a humidity value in the range of 20 – 90% of Relative Humidity (RH) and a temperature in the range of 0 – 500C. The sampling period of the sensor is 1 second i.e.
Also, the length of the cable can be as long as 20 meters. The data from the sensor consists of integral and decimal parts for both Relative Humidity (RH) and temperature.
8 – Bit data for integral RH value, 8 – Bit data for decimal RH value, 8 – Bit data for integral Temperature value, 8 – Bit data for integral Temperature value and 8 – Bit data for checksum.
In order to check whether the received data is correct or not, we need to perform a small calculation. Add all the integral and decimals values of RH and Temperature and check whether the sum is equal to the checksum value i.e. the last 8 – bit data.
This value is same as checksum and hence the received data is valid. Now to get the RH and Temperature values, just convert the binary data to decimal data.
A simple project is built using Arduino UNO and DHT11 Humidity and Temperature Sensor, where the Humidity and Temperature of the surroundings are displayed on an LCD display.
After making the connections, we need not do anything as the program will take care of everything. Although there is a special library for the DHT11 module called “DHT”, we didn’t use it. If you want to use this library, you need to download this library separately and add it to the existing libraries of Arduino.
The program written is based on the data timing diagrams provided in the datasheet. The program will make the Arduino to automatically read the data from the sensor and display it as Humidity and Temperature on the LCD Display.
This module integrates DHT11 sensor and other required components on a small PCB. The DHT11 sensor includes a resistive-type humidity measurement component, an NTC temperature measurement component and a high-performance 8-bit microcontroller inside, and provides calibrated digital signal output. It has high reliability and excellent long-term stability, thanks to the exclusive digital signal acquisition technique and temperature & humidity sensing technology.
The DHT11 sensors usually require external pull-up resistor of 10KΩ between VCC and Out pin for proper communication between sensor and the Arduino. However, the module has a built-in pull-up resistor, so you need not add it.
+ (VCC) pin supplies power for the sensor. 5V supply is recommended, although the supply voltage ranges from 3.3V to 5.5V. In case of 5V power supply, you can keep the sensor as long as 20 meters. However, with 3.3V supply voltage, cable length shall not be greater than 1 meter. Otherwise, the line voltage drop will lead to errors in measurement.
The DHT11 sensor can either be purchased as a sensor or as a module. Either way, the performance of the sensor is same. The sensor will come as a 4-pin package out of which only three pins will be used whereas the module will come with three pins as shown above.
The only difference between the sensor and module is that the module will have a filtering capacitor and pull-up resistor inbuilt, and for the sensor, you have to use them externally if required.
The DHT11is a commonly used Temperature and humidity sensor. The sensor comes with a dedicated NTC to measure temperature and an 8-bit microcontroller to output the values of temperature and humidity as serial data. The sensor is also factory calibrated and hence easy to interface with other microcontrollers.
The sensor can measure temperature from 0°C to 50°C and humidity from 20% to 90% with an accuracy of ±1°C and ±1%. So if you are looking to measure in this range then this sensor might be the right choice for you.
The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.
DHt11 also contains a NTC/Thermistor to measure temperature. A thermistor is a thermal resistor whose resistance changes drastically with temperature. The term “NTC” means “Negative Temperature Coefficient”, which means that the resistance decreases with increase of the temperature.
On the other side, there is a small PCB with an 8-bit SOIC-14 packaged IC. This IC measures and processes the analog signal with stored calibration coefficients, does analog to digital conversion and spits out a digital signal with the temperature and humidity.
Connections are fairly simple. Start by connecting + (VCC) pin to the 5V output on the Arduino and connect – (GND) to ground. Finally, connect the Out pin to the digital pin #8.
DHT11 sensors have their own single wire protocol for transferring the data. This protocol requires precise timing. Fortunately, DHT Library was written to hide away all the complexities so that we can issue simple commands to read the temperature and humidity data.
The following test sketch will print the temperature and relative humidity values on the serial monitor. Try the sketch out; and then we will explain it in some detail.
#include
The sketch starts by including DHT library and defining the Arduino pin number to which our sensor’s Out pin is connected. Then we create a DHT object to access special functions related to the library.
Sometimes you come up with an idea where you want to monitor temperature and humidity levels in your DIY incubator. Then you’ll probably need 16×2 character LCD to display prevailing conditions in your incubator, instead of a serial monitor. So, in this example, we’ll hook the LCD up to the Arduino along with the DHT11 module.
Want your Arduino projects to display status messages or sensor readings? Then these LCD displays might be the perfect fit. They are extremely common and...
The following sketch will print the temperature and relative humidity values on the 16×2 character LCD. It uses the same code except we print values on LCD.
A few years back, I created a new home automation course at Santiago Canyon College in Orange, Calif. where I taught Computer Science and Robotics. I wanted to introduce my programming students to microcontrollers so they could have some fun controlling things around their home. The students never built anything like that so I came up with a couple introductory level lab projects for them to try out. I decided to make a simple "weather station" project so they could learn how to build a circuit on a breadboard, learn to program an Arduino, and how to write some code that could read multiple sensors and display the readings on a small LCD display.
The activity was the first time the class ever used electronic components. Once more, they had no idea of how to make them do something cool. It turned out to be great fun. I thought some of you might also enjoy building this. So, if this sounds like something you would like to explore for yourself, you are invited to come along with us on this adventure!
You will discover that you must have the correct Arduino libraries installed for your particular sensor. This is especially true when working with LCD displays. The one we use in this project is version 1.2 so be sure to download both the LCD and the DHT-11 temperature libraries from my websitehere. Unzip them on your desktop and copy each folder to your Documents | Arduino | Library folder. Be sure to delete any existing libraries with the same name.
I added some photos of the finished project so you can see how it is wired up. Please take your time and make sure all the connections are secure. I use a small set of needle nose pliers to help me insert resistors and wires into the breadboard. Sometimes, a new breadboards connections are very tight.
Always choose wire colors that make sense to you. Use red for power, black for ground, and another color for the output of your sensors. Be very careful when you wire up the LCD. On the connector, you must connect wires to the right place. For some reason, LCD"s even from the same manufacturer have the connector pins in different positions. Look at my comments under the LCD section below to see how I wired it. I also added a closeup photo of my connections.
Notice how I added the resistors to the breadboard and how the green and yellow wires go from the LCD connector to those resistors and THEN connect to the Arduino. The SCL & SDA pins on the LCD each need a pull--up resistor or it won"t display properly! The resistors provide a small amount of current to the LCD so the Arduino signals are interpreted correctly.
If you understand the schematic and use the photos, I feel confident you can build this. Make sure to use the libraries from my website by using the link in the previous section. Please let me know if you need some help. I will be happy to assist you. Have fun!
Humidity and temperature are common parameters to measure environmental conditions. In this Arduino based project we are going to measure ambient temperature and humidity and display it on a 16x2 LCD screen. A combined temperature and himidity sensor DHT11 is used with Arduino uno to develop this Celsius scale thermometer and percentage scale humidity measurement project. In one of my previous project, I have also developed a digital thermometer using temperature sensor LM35.
This project consists of three sections - one senses the humidity and temperature by using humidity and temperature sensor DHT11. The second section reads the DHTsensor module’s output and extracts temperature and humidity values into a suitable number in percentage and Celsius scale. And the third part of the system displays humidity and temperature on LCD.
Working of this project is based on single wire serial communication. First arduino send a start signal to DHT module and then DHT gives a response signal containing temperature and humidity data. Arduino collect and extract in two parts one is humidity and second is temperature and then send them to 16x2 LCD.
Here in this project we have used a sensor module namely DHT11. This module features a humidity and temperature complex with a calibrated digital signal output means DHT11 sensor module is a combined module for sensing humidity and temperature which gives a calibrated digital output signal. DHT11 gives us very precise value of humidity and temperature and ensures high reliability and long term stability. This sensor has a resistive type humidity measurement component and NTC type temperature measurement component with an 8-bit microcontroller inbuilt which has a fast response and cost effective and available in 4-pin single row package.
DHT11 module works on serial communication i.e. single wire communication. This module sends data in form of pulse train of specific time period. Before sending data to arduino it needs some initialize command with a time delay. And the whole process time is about 4ms. A complete data transmission is of 40-bit and data format of this process is given below:
First of all arduino sends a high to low start signal to DHT11 with 18µs delay to ensure DHT’s detection. And then arduino pull-up the data line and wait for 20-40µs for DHT’s response. Once DHT detects starts signal, it will send a low voltage level response signal to arduino of time delay about 80µs. And then DHT controller pull up the data line and keeps it for 80µs for DHT’s arranging of sending data.
When data bus is at low voltage level it means that DHT11 is sending response signal. Once it is done, DHT again makes data line pull-up for 80µs for preparing data transmission.
Data format that is sending by DHT to arduino for every bit begins with 50µs low voltage level and length of high voltage level signal determines whether data bit is “0” or “1”.
One important thing is to make sure pull up resistor value because if we are placing DHT sensor at <20 meter distance, 5k pull up resistor is recommended. If placing DHT at longer the 20 meter then use appropriate value pull up resistor.
A liquid crystal display is used for displaying temperature and humidity which is directly connected to arduino in 4-bit mode. Pins of LCD namely RS, EN, D4, D5, D6 and D7 are connected to arduino digital pin number 2, 3, 4, 5, 6 and 7. And a DHT11 sensor module is also connected to digital pin 12 of arduino with a 5k pull-up resistor.
Then we haved defined pins for LCD and DHT sensor and initialized all the things in setup. Then in a loop by using dht function reads DHT sensor and then using some dht functions we extract humidity and temperature and display them on LCD.
DHT11 Module features a temperature & humidity sensor complex with a calibrated digital signal output. The exclusive digital-signal-acquisition technique and temperature & humidity sensing technology ensure high reliability and excellent long-term stability. This sensor includes an NTC for temperature measurement and a resistive-type humidity measurement component for humidity measurement. These are connected to a high-performance 8-bit microcontroller, offering excellent quality, fast response, anti-interference ability, and cost-effectiveness.
The DHT11 module has only a very low number of parts that includes the DHT11, pullup resistor, bypass capacitor, and power led with a current limiting resistor.
The schematic diagram for the DHT11 module is given below. As mentioned earlier, the board has a very low components count. The VCC and GND are directly connected to the DHT11 and a pullup resistor is added to the DATA pin. Sufficient filtering is provided with the tantalum and multilayer capacitors. An LED with a current limit resistor is used as a power indicator.
The DHT11 is a basic, ultra-low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and sends data through a 1-wire protocol.
As already mentioned, DHT11 has an NTC thermistor and humidity sensing components. When the temperature changes, the resistance of the NTC also changes. This change in resistance is measured and the temperature is calculated from it. We have already discussed how to use the NTC thermistor with Arduino.
The humidity sensing component consists of a moisture-holding substrate sandwiched in between two electrodes. When the substrate absorbs water content, the resistance between the two electrodes decreases. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes. This change in resistance is measured with the onboard MCU’s ADC and the relative humidity is calculated.
Each DHT11 element is strictly calibrated in the laboratory which is extremely accurate in humidity calibration. The calibration coefficients are stored as programmes in the OTP memory, which are used by the sensor’s internal signal detecting process.
Single-bus data format is used for communication and synchronization between MCU and DHT11 sensor. One communication process is about 4ms. Data consists of decimal and integral parts. Complete data transmission is 40bit, and the sensor sends higher data bit first. Data format is as follows: 8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data + 8bit checksum. If the data transmission is right, the check-sum should be the last 8bit of "8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data".
When MCU sends a start signal, DHT11 changes from the low-power-consumption mode to the running mode, waiting for MCU to complete the start signal. Once it is completed, DHT11 sends a response signal of 40-bit data that include the relative humidity and temperature information to the MCU. Users can choose to collect (read) some data. Without the start signal from MCU, DHT11 will not give the response signal to MCU. Once data is collected, DHT11 will change to the low power-consumption mode until it receives a start signal from MCU again.
Now that we have completely understood how a DHT11 Sensor works, we can connect all the required wires to Arduino and write the code to get all the data out from the sensor. The following image shows the circuit diagram for interfacing the DHT11 sensor module with Arduino.
Connections are pretty simple and only require three wires. Connect the VCC and GND of the module to the 5V and GND pins of the Arduino. Then connect the DATA pin to the Arduino’s digital pin 2. We communicate with DHT11 through this pin.
Now let’s look at the code for interfacing the DHT11 sensor. For that first install the Adafruit’s DHT sensor library and Adafruit Unified Sensor Driver through the library manager. Then create a blank sketch and paste the code at the end of this article into it.
In the starting, we have included all the necessary libraries and defined the sensor type as DHT11 and the sensor pin as digital pin 2. And then created an instance for the DHT library. Also created a variable to declare the minimum delay.
In the loopfunction, we have created an event and using this event the temperature and humidity data is read from the DHT11 sensor. Then this value is printed to the serial monitor. The below GIF shows the DHT11 interface.
In this project, we will measure Humidity, Temperature and Pressure parameters and display them on the web server, which makes it a IoT based Weather Station where the weather conditions can be monitored from anywhere using the Internet.
In this project, we are going to make a small Automatic Temperature Control Circuit that could minimize the electricity charges by varying the AC temperature automatically base