(0,1) indicates (Character position from left, Row 0=1 1=2) Print Humidity on line 2 (use 1 to indicate line 2) Lcd.print(DHT.temperature * 1.8 + 32, 0) //Fahrenheit conversion Lcd.setCursor(0,0) //next print line shows on LCD line 1 (0,0) indicates (Character position from left, Row 0=1 1=2) Print temp on line 1 (use 0 to indicate line 1) Lcd.clear() //Clears any previous message on LCD Lcd.begin(16,2) //16 by 2 character displayĭelay(1000) //wait a sec (recommended for DHT11)
#define DHT11_PIN 8 //DHT11 Signal wire to pin 8 *-–( Declare Constants, Pin Numbers )-–*/ DHT11 sensor power is 5V (middle pin on sensor) Signal wire of DHT11 to Arduino Digital pin 8 DHT11 Temp and humidity sensor in Celsius ***** Works for temp and humid display on LCD I2C ***** Make sure you have the 3 libraries noted #include
Here is some simple code to output the DHT11 to a 16×2 LCD (with built in controller)
You can watch how to set up the DHT11 and see how it works in this video: To see an example of using the DHT11 sensor outputs as variables in other functions, check out our article How to Set Up an Ultrasonic Range Finder on an Arduino, where we use the DHT.humidity and DHT.temperature variables in a formula that improves the accuracy of an ultrasonic range finder. You can add this to existing programs and use DHT.humidity and DHT.temperature as variables in any function. What if you don’t want to output the actual humidity and temperature readings, but need them to calculate or control other things? The code below is the bare minimum needed to initialize the sensor. To do this, first follow our tutorial on How to Set Up an LCD Display on an Arduino, then upload this code to the Arduino: #include Display Humidity and Temperature on an LCDĪ nice way to display the humidity and temperature readings is on a 16X2 LCD. If you don’t want to use pin 7 for the data signal, you can change the pin number in line 5 where it says #define DHT11_PIN 7. You should see the humidity and temperature readings displayed at one second intervals.
ZIP Library and select the DHTLib.zip file.Īfter it’s installed, upload this example program to the Arduino and open the serial monitor: #include
It’s easy to install, just download the DHTLib.zip file below and open up the Arduino IDE. It has all the functions needed to get the humidity and temperature readings from the sensor.
Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.ĭisplay Humidity and Temperature on the Serial Monitorīefore you can use the DHT11 on the Arduino, you’ll need to install the DHTLib library.
The change in resistance between the two electrodes is proportional to the relative humidity. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. How the DHT11 Measures Humidity and Temperature At 100% RH, condensation occurs, and at 0% RH, the air is completely dry. Relative humidity is expressed as a percentage. The formula to calculate relative humidity is: Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated. The saturation point changes with air temperature. At the saturation point, water vapor starts to condense and accumulate on surfaces forming dew. the saturation point of water vapor in air. Relative humidity is the amount of water vapor in air vs. Here are the ranges and accuracy of the DHT11:ĭHT11 Datasheet What is Relative Humidity? It covers all of the steps, diagrams, and code you need to get started. BONUS: I made a quick start guide for this tutorial that you can download and go back to later if you can’t set this up right now.