{"id":1570,"date":"2019-05-12T21:28:50","date_gmt":"2019-05-12T13:28:50","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=1570"},"modified":"2020-08-02T14:04:30","modified_gmt":"2020-08-02T06:04:30","slug":"how-to-use-a-esp32-development-board-to-read-temperature-and-humidity-from-a-dh11-sensor","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-use-a-esp32-development-board-to-read-temperature-and-humidity-from-a-dh11-sensor\/","title":{"rendered":"How to use a ESP32 development board to read temperature and humidity from a DH11 sensor"},"content":{"rendered":"<p>When you have a <a href=\"https:\/\/www.amazon.com\/Temperature-Humidity-Sensor-Arduino-Raspberry\/dp\/B07T7ZR7MS\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=97430b8e1e09bc16aadb36b138825088&language=en_US\" rel=\"noopener\" target=\"_blank\">DHT11 sensor<\/a>, you will be able to get the temperature and humidity of your environment.<\/p>\n<p>Given that, this post shows how to use <a href=\"https:\/\/www.amazon.com\/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated\/dp\/B0718T232Z\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=6f3273f687f1a1c8cbc042a8d938b17e&language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a> to read temperature and humidity from a DHT11 sensor.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-sensor-connected-to-ESP32-board.jpg\" alt=\"DHT11 sensor connected to ESP32 board\" \/><\/p>\n<h2>Wiring your DHT11 sensor to your ESP32 development board<\/h2>\n<p>When you look at your DHT11 sensor, you can see three pins labeled <strong>+<\/strong>\/<strong>VCC<\/strong>, <strong>OUT<\/strong>\/<strong>S<\/strong>\/<strong>DATA<\/strong> and <strong>-<\/strong>\/<strong>GND<\/strong>. Connect the:<\/p>\n<ul>\n<li><strong>+<\/strong>\/<strong>VCC<\/strong> pin to a <strong>3v3<\/strong> pin on your board<\/li>\n<li><strong>OUT<\/strong>\/<strong>s<\/strong>\/<strong>DATA<\/strong> pin to <strong>GPIO27<\/strong> on your board<\/li>\n<li><strong>-<\/strong>\/<strong>GND<\/strong> pin to a <strong>GND<\/strong> pin on your board<\/li>\n<\/ul>\n<p>For example, this is how I had wired my DHT11 sensor to my ESP32 development board:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-sensor-with-GPIO-cables.jpg\" alt=\"DHT11 sensor with GPIO cables\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/ESP32-with-gpio-wires-connected-to-3v3-gnd-and-gpio27-pins.jpg\" alt=\"ESP32 with gpio wires connected to 3v3 gnd and gpio27 pins\" \/><\/p>\n<h2>Enabling ESP32 Development on Arduino IDE<\/h2>\n<p>At this point in time, you are ready to flash a program into your ESP32 board to read from the DHT11 sensor. In order to do so, we need to use a tool to write our program into the flash memory of the development board.<\/p>\n<p>Since it is easy to write code and flash programs with <a href=\"https:\/\/www.arduino.cc\/en\/main\/software\" rel=\"noopener\" target=\"_blank\">Arduino IDE<\/a>, we can use it to serve our purpose.<\/p>\n<p>In order to use Arduino IDE for this guide, be sure to <a href=\"https:\/\/www.techcoil.com\/blog\/enabling-esp32-development-on-arduino-ide\/\" rel=\"noopener\" target=\"_blank\">enable ESP32 development on Arduino IDE<\/a> before continuing.<\/p>\n<h2>Installing the DHT sensor library for ESPx to read temperature and humidity from DHT11 sensor<\/h2>\n<p>After you had started your Arduino IDE, proceed to install a Arduino Library to read temperature and humidity from DHT11 sensor.<\/p>\n<p>In order to do so, first go to <strong>Tools -> Manage Libraries...<\/strong>. After you had done so, the <strong>Library Manager<\/strong> window will appear. Search for <strong>DHT11<\/strong> and install the <a href=\"https:\/\/github.com\/beegee-tokyo\/DHTesp\" rel=\"noopener\" target=\"_blank\">DHT sensor library for ESPx by beegee_tokyo<\/a>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-IDE-1.8.9-Library-Manager-with-libraries-filtered-by-DHT11-and-DHT-sensor-library-for-ESPx-highlighted.gif\" alt=\"Mac Arduino IDE 1.8.9 Library Manager with libraries filtered by DHT11 and DHT sensor library for ESPx highlighted\" \/><\/p>\n<h2>Arduino sketch example to read temperature and humidity from the DHT11 sensor<\/h2>\n<p>Once you had installed the DHT sensor library for ESPx, upload the following sketch to your ESP32 board:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &quot;DHTesp.h&quot;\r\nDHTesp dht;\r\n  \r\nvoid setup()\r\n{\r\n  Serial.begin(9600);\r\n  dht.setup(27, DHTesp::DHT11);\r\n  Serial.println();\r\n  delay(1000);\r\n}\r\n  \r\nvoid loop()\r\n{\r\n  float temperature = dht.getTemperature();\r\n  float humidity = dht.getHumidity();\r\n  \r\n  Serial.print(&quot;Temperature: &quot;);\r\n  Serial.println(temperature);\r\n  Serial.print(&quot;Humidity: &quot;);\r\n  Serial.println(humidity);\r\n  \r\n  delay(2000);\r\n}\r\n<\/pre>\n<p>After your Arduino IDE had uploaded the above sketch to your ESP32 board, you should see output similar to the following:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-1.8.9-serial-monitor-showing-temperature-and-humidity-from-DHT11-sensor.gif\" alt=\"Mac Arduino 1.8.9 serial monitor showing temperature and humidity from DHT11 sensor\" \/><\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"900\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/How-to-use-a-ESP32-development-board-to-read-temperature-and-humidity-from-a-DH11-sensor.jpg\" alt=\"How to use a ESP32 development board to read temperature and humidity from a DH11 sensor\" class=\"aligncenter size-full wp-image-1943\" \/><\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-pk\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-pk&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-pk&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1570&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>When you have a <a href=\"https:\/\/www.amazon.com\/Universal-Solder-Temperature-Humidity-Interface\/dp\/B075CNS7PS\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=1b1cb7056ec3349b969bdb598d7dd28d&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">DHT11 sensor<\/a>, you will be able to get the temperature and humidity of your environment.<\/p>\n<p>Given that, this post shows how to use <a href=\"https:\/\/www.amazon.com\/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated\/dp\/B0718T232Z\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=6f3273f687f1a1c8cbc042a8d938b17e&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a> to read temperature and humidity from a DHT11 sensor.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-sensor-connected-to-ESP32-board.jpg\" alt=\"DHT11 sensor connected to ESP32 board\" \/><\/p>\n","protected":false},"author":1,"featured_media":1572,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[588,634,555,630,484],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-sensor-connected-to-ESP32-board.jpg","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-pk","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1570"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=1570"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1570\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1572"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}