








{"id":103,"date":"2020-10-12T21:21:29","date_gmt":"2020-10-12T21:21:29","guid":{"rendered":"https:\/\/osoyoo.info\/?p=103"},"modified":"2020-10-13T22:10:29","modified_gmt":"2020-10-13T22:10:29","slug":"lesson-17-dht11-sensor","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/lesson-17-dht11-sensor\/","title":{"rendered":"Hardware Programming with Arduino IDE &#8211; Lesson 17: DHT11 Sensor"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-16-rgb-led\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-18-osoyoo-relay-module\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/icon\/authorized_retailers.png\" \/><\/div>\n<div align=\"center\"><\/div>\n<table>\n<tbody>\n<tr>\n<td>Buy from US<\/td>\n<td>Buy from UK<\/td>\n<td>Buy from DE<\/td>\n<td>Buy from IT<\/td>\n<td>Buy from FR<\/td>\n<td>Buy from ES<\/td>\n<td>Buy from JP<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/www.amazon.com\/dp\/B08J7DKJK9?ref=myi_title_dp\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/us_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.uk\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/icon\/uk_buy_now.png\" alt=\"\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.de\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/de_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.it\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/it_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.fr\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/fr_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.es\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/es_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.jp\/dp\/B08J7TLP48\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/jp_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><strong>Content<\/strong><\/h2>\n<ol>\n<li><a href=\"#1\">Introduction<\/a><\/li>\n<li><a href=\"#2\">Preparations<\/a>\n<ul>\n<li><a href=\"#2.1\">Hardware<\/a><\/li>\n<li><a href=\"#2.2\">Software<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#3\">About the DHT11<\/a>\n<ul>\n<li><a href=\"#3.1\">WHAT IS RELATIVE HUMIDITY?<\/a><\/li>\n<li><a href=\"#3.2\">HOW THE DHT11 MEASURES HUMIDITY AND TEMPERATURE<\/a><\/li>\n<li><a href=\"#3.3\">Diffrences Between DHT11 and DHT22<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4\">Examples<\/a>\n<ul>\n<li><a href=\"#4.1\">Display Humidity and Temperature on the Serial Monitor<\/a>\n<ul>\n<li><a href=\"#4.1.1\">Circuit Diagram<\/a><\/li>\n<li><a href=\"#4.1.2\">Code Program<\/a><\/li>\n<li><a href=\"#4.1.3\">Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4.2\">Display Humidity and Temperature on the I2C 1602LCD<\/a>\n<ul>\n<li><a href=\"#4.2.1\">Circuit Diagram<\/a><\/li>\n<li><a href=\"#4.2.2\">Code Program<\/a><\/li>\n<li><a href=\"#4.2.3\">Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p>The digital temperature and humidity sensor DHT11 inside contains a chip that does analog to digital conversion and spits out a digital signal with the temperature and humidity, compatible with any MCUs, ideal for those who want some basic data logging stuffs. It&#8217;s very popular for electronics hobbyists because it is very cheap but still providing great performance.<\/p>\n<p>In this lesson, we will first go into a little background about humidity, then we will explain how the DHT11 measures humidity. After that, we will show you how to connect the DHT11 to an Arduino and give you some example code so you can use the DHT11 in your own projects.<\/p>\n<h1 id=\"2\">Preparations<\/h1>\n<h2 id=\"2.1\">Hardware<\/h2>\n<ul>\n<li>Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1<\/li>\n<li>OSOYOO Temp &amp; Humi Module x 1<\/li>\n<li>OSOYOO 1602 I2C LCD Screen x 1<\/li>\n<li>OSOYOO 3-pin PNP cable x 1<\/li>\n<li>OSOYOO 4-pin PNP cable x 1<\/li>\n<li>USB Cable x 1<\/li>\n<li>PC x 1<\/li>\n<\/ul>\n<h2 id=\"2.2\">Software<\/h2>\n<ul>\n<li>Arduino IDE (version 1.6.4+)<\/li>\n<li><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/samplecode\/DHT.zip\" target=\"_blank\" rel=\"noopener noreferrer\">DHT11.h<\/a><\/li>\n<li><a href=\"https:\/\/codeload.github.com\/marcoschwartz\/LiquidCrystal_I2C\/zip\/master\" target=\"_blank\" rel=\"noopener noreferrer\">LiquidCrystal_I2C.h<\/a><\/li>\n<li>Wire.h<\/li>\n<\/ul>\n<h1 id=\"3\">About DHT11 module<\/h1>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"https:\/\/osoyoo.com\/picture\/Micro_bit_STEM\/Temperature_and_humidity_meter\/DSC_6709.jpg\" width=\"1000\" height=\"628\" \/><\/p>\n<h2 id=\"3.1\">WHAT IS RELATIVE HUMIDITY?<\/h2>\n<p>The DHT11 measures <em>relative humidity<\/em>. Relative humidity is the amount of water vapor in air vs. the saturation point of water vapor in air. At the saturation point, water vapor starts to condense and accumulate on surfaces forming dew.<\/p>\n<p>The saturation point changes with air temperature. Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated.<\/p>\n<p>The formula to calculate relative humidity is:<\/p>\n<p><img class=\"latex lazyloaded\" title=\"RH = (\\frac{\\rho_{w}}{\\rho_{s}}) \\ x \\ 100 \\% \\\\ \\\\ RH: \\ Relative \\ Humidity \\\\ \\rho_{w}: \\ Density \\ of \\ water \\ vapor\\\\ \\rho_{s}: \\ Density \\ of \\ water \\ vapor \\ at \\ saturation \" src=\"http:\/\/s0.wp.com\/latex.php?latex=RH+%3D+%28%5Cfrac%7B%5Crho_%7Bw%7D%7D%7B%5Crho_%7Bs%7D%7D%29+%5C+x+%5C+100+%5C%25+%5C%5C++%5C%5C++RH%3A+%5C+Relative+%5C+Humidity+%5C%5C++%5Crho_%7Bw%7D%3A+%5C+Density+%5C+of+%5C+water+%5C+vapor%5C%5C++%5Crho_%7Bs%7D%3A+%5C+Density+%5C+of+%5C+water+%5C+vapor+%5C+at+%5C+saturation+&amp;bg=ffffff&amp;fg=000&amp;s=0\" alt=\"RH = (\\frac{\\rho_{w}}{\\rho_{s}}) \\ x \\ 100 \\% \\\\ \\\\ RH: \\ Relative \\ Humidity \\\\ \\rho_{w}: \\ Density \\ of \\ water \\ vapor\\\\ \\rho_{s}: \\ Density \\ of \\ water \\ vapor \\ at \\ saturation \" \/><\/p>\n<p>Relative humidity is expressed as a percentage. At 100% RH, condensation occurs, and at 0% RH, the air is completely dry.<\/p>\n<h2 id=\"3.2\">HOW THE DHT11 MEASURES HUMIDITY AND TEMPERATURE<\/h2>\n<p>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. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. 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.<\/p>\n<p>The DHT11 measures temperature with a surface mounted NTC temperature sensor (thermistor) built into the unit.<\/p>\n<p>With the plastic housing removed, you can see the electrodes applied to the substrate, an IC mounted on the back of the unit converts the resistance measurement to relative humidity. It also stores the calibration coefficients, and controls the data signal transmission between the DHT11 and the Arduino:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/arduino126-3.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-9077 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/arduino126-3.jpg\" alt=\"\" width=\"430\" height=\"257\" \/><\/a><\/p>\n<h2 id=\"3.3\">Diffrences Between DHT11 and DHT22<\/h2>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/dht11dht22.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-9080 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/dht11dht22.jpg\" alt=\"\" width=\"642\" height=\"250\" \/><\/a><\/p>\n<h1 id=\"4\">Examples<\/h1>\n<p>Before you can use the DHT11 on the Arduino, you\u2019ll need to install the <a href=\"http:\/\/playground.arduino.cc\/Main\/DHTLib\" target=\"_blank\" rel=\"noopener noreferrer\">DHT library<\/a>. It has all the functions needed to get the humidity and temperature readings from the sensor. It\u2019s easy to install, just download the DHT.zip file and open up the Arduino IDE. Then go to Sketch&gt;Include Library&gt;Add .ZIP Library and select the DHT.zip file.<\/p>\n<h2 id=\"4.1\">Display Humidity and Temperature on the Serial Monitor<\/h2>\n<h3 id=\"4.1.1\">Connection<\/h3>\n<p>First, please plug OSOYOO Magic I\/O shield into UNO board:<\/p>\n<p><img loading=\"lazy\" class=\"size-full aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson4\/UNO%2BBase-min.png\" width=\"1000\" height=\"600\" \/><\/p>\n<p>Then connect the OSOYOO Temp &amp; Humi Module to the port D3 of the Magic I\/O shield with 3-pin PNP cables as below:<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"http:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/Lesson18\/Humi.jpg\" width=\"1000\" height=\"476\" \/><\/p>\n<p>This diagram shows how we will connect for the testing sketch. Connect data to pin 3, you can change it later to any pin.<\/p>\n<h3 id=\"4.1.2\">Code Program<\/h3>\n<p>After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled <strong>PWR<\/strong>) should go on. Load up<a href=\"https:\/\/github.com\/osoyoo\/Osoyoo-development-kits\/tree\/master\/Osoyoo%20lessons%20for%20Arduino\/DHT11_basic.zip\" target=\"_blank\" rel=\"noopener noreferrer\"> the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span><span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #000000;\">dht<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span> <span style=\"color: #000000;\">dht<\/span> <b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ if you require to change the pin number, Edit the pin with your arduino pin.<\/span> <span style=\"color: #5e6d03;\">#define<\/span> <span style=\"color: #000000;\">DHT11_PIN<\/span> <span style=\"color: #000000;\">3<\/span> <span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">begin<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">9600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"The real time Temperature and Humidity is :\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">}<\/span> <span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span> <span style=\"color: #434f54;\">\/\/ READ DATA<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">chk<\/span> <span style=\"color: #434f54;\">=<\/span> <b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">read11<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">DHT11_PIN<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\" Humidity: \"<\/span> <span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">humidity<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">'%'<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\" Temparature \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">temperature<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">'C'<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">2000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">}<\/span><\/pre>\n<h3 id=\"4.1.3\">Running Result<\/h3>\n<p>A few seconds after the upload finishes, open the Serial Monitor, you should now see the humidity and temperature readings displayed at one second intervals.<\/p>\n<p>Note: Please make sure you have choosed the correct port and the correct baudrate for you project.<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/LIAGgyJeIpU\" width=\"1280\" height=\"720\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center><\/p>\n<h2 id=\"4.2\">Display Humidity and Temperature on the I2C 1602LCD<\/h2>\n<p>A nice way to display the humidity and temperature readings is on a 1I2C 1602LCD. To do this, first follow our tutorial on <a href=\"https:\/\/osoyoo.com\/2020\/07\/29\/i2c-lcd1602-display\/\">How to Set Up an LCD Display on an Arduino<\/a>, then follow below operations and complete this project.<\/p>\n<h3 id=\"4.2.1\">Connection<\/h3>\n<p>Connect the OSOYOO Temp &amp; Humi Module to the port D3 of the Magic I\/O shield with 3-pin PNP cables and connect the OSOYOO 1602 I2C LCD Screen to the port I2C of the Magic I\/O shield with 4-pin PNP cables as below:<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"http:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/Lesson18\/Humi+1602.jpg\" width=\"1000\" height=\"612\" \/><\/p>\n<h3 id=\"4.2.2\">Code Program<\/h3>\n<p>After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled <strong>PWR<\/strong>) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up <a href=\"https:\/\/github.com\/osoyoo\/Osoyoo-development-kits\/blob\/master\/Osoyoo%20lessons%20for%20Arduino\/DHT11_1602i2c_LCD.zip\" target=\"_blank\" rel=\"noopener noreferrer\">the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #d35400;\">Wire<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span> <span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #434f54;\">&lt;<\/span><b><span style=\"color: #d35400;\">LiquidCrystal_I2C<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span> <span style=\"color: #5e6d03;\">#include<\/span><span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #000000;\">dht<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span> <span style=\"color: #000000;\">dht<\/span> <b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #000000;\">;<\/span> <b><span style=\"color: #d35400;\">LiquidCrystal_I2C<\/span><\/b> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0x27<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">16<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ set the LCD address to 0x27 for a 16 chars and 2 line display<\/span> <span style=\"color: #5e6d03;\">#define<\/span> <span style=\"color: #000000;\">DHT11_PIN<\/span> <span style=\"color: #000000;\">3<\/span> <span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">begin<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">16<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">init<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ initialize the lcd <\/span> <span style=\"color: #434f54;\">\/\/ Print a message to the LCD.<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">backlight<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">clear<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"Humidity &amp; temp\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">3000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">clear<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"Starting.....\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">3000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">}<\/span> <span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span> <span style=\"color: #434f54;\">\/\/ READ DATA<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">chk<\/span> <span style=\"color: #434f54;\">=<\/span> <b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">read11<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">DHT11_PIN<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">clear<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">500<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">setCursor<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">0<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ print from 0 to 9:<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"Temp    : \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">temperature<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\" C\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ set the cursor to (16,1):<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">setCursor<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">0<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"Humidity: \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><b><span style=\"color: #d35400;\">DHT<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">humidity<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #000000;\">1<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">lcd<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\" %\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">2000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">}<\/span><\/pre>\n<h3 id=\"4.2.3\">Running Result<\/h3>\n<p>A few seconds after the upload finishes, you should now see the value of current humidity and temperature displayed on the LCD.<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/cUxb4V_Vx1k\" width=\"1280\" height=\"720\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center>&nbsp;<\/p>\n<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-16-rgb-led\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-18-osoyoo-relay-module\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP Content Introduction Preparations Hardware Software About the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/103"}],"collection":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":3,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions\/111"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/159"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}