{"id":12045,"date":"2016-10-08T22:41:17","date_gmt":"2016-10-09T02:41:17","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=12045"},"modified":"2016-10-08T23:15:08","modified_gmt":"2016-10-09T03:15:08","slug":"esp8266-temperature-humidity-logger-deep-sleep-enabled","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/esp8266-temperature-humidity-logger-deep-sleep-enabled\/","title":{"rendered":"ESP8266 temperature and humidity logger with deep sleep enabled"},"content":{"rendered":"<p>ESP8266 has made it possible for hobbyists and makers to develop IoT applications in simple and inexpensive ways. This article shows an example of making a very simple temperature and humidity logger using ESP8266 that uploads the data directly to a\u00a0cloud service, such as ThingSpeak, and allows\u00a0to\u00a0visualize the data in real time. The ESP8266 module used in this project is <a href=\"https:\/\/www.wemos.cc\/product\/d1-mini.html\" target=\"_blank\">WeMOS&#8217; D1 Mini<\/a> board. Because the D1 board comes with the\u00a0<a href=\"https:\/\/www.wemos.cc\/downloads\">CH340G<\/a>\u00a0USB to UART converter module and a micro USB connector preinstalled on board, all you need is an USB cable to upload your program to the ESP8266. For temperature and humidity measurements, the DHT22 sensor is used. The sensor circuit is soldered on a prototyping circuit board in the form of a shield that plugs directly into the D1 Mini board. Unlike many other similar projects on the internet, this article talks about how to put the ESP8266 into deep sleep mode and configure it to wake up automatically at regular intervals for sensor readings.<\/p>\n<div id=\"attachment_12049\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_140201.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-12049\" class=\"size-full wp-image-12049\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_140201.jpg\" alt=\"IoT temperature\/humidity logger\" width=\"600\" height=\"390\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_140201.jpg 600w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_140201-580x377.jpg 580w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-12049\" class=\"wp-caption-text\">IoT temperature\/humidity logger using WeMOS D1 Mini board and DHT22 sensor<\/p><\/div>\n<p><strong>Circuit setup<\/strong><\/p>\n<p>The connection between the DHT22 and D1 Mini board is shown in the figure below. The DHT22 sensor is powered by the 3.3V power supply coming from the D1 Mini board. A 2.2K resistor pulls the DHT22 data pin to high at default. The DHT22 data pin goes\u00a0to the D4 pin of WeMOS D1 Mini.<\/p>\n<div id=\"attachment_12064\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/dht22.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-12064\" class=\"size-full wp-image-12064\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/dht22.jpg\" alt=\"DHT22 and WeMOS D1 Mini connections\" width=\"600\" height=\"346\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/dht22.jpg 600w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/dht22-580x334.jpg 580w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-12064\" class=\"wp-caption-text\">DHT22 and WeMOS D1 Mini connections<\/p><\/div>\n<p>As I mentioned earlier, this project implements deep sleep mode of ESP8266 to save power as well as to get accurate temperature readings. ESP8266 is power hungry and dissipates considerable amount of heat during\u00a0operation. I have noticed that if the ESP8266 is not put in to sleep during successive sensor\u00a0readings, the heat radiated by\u00a0the ESP8266 can easily affects the DHT22 outputs if the sensor is close to the ESP module. In\u00a0this project, the DHT22 sensor lies on the top shield right above the ESP8266 chip, so it is very important to consider using the deep sleep mode feature. Without using this feature, I have found the temperature readings from DHT22 are 2-3 \u00baF higher than the actual values. ESP8266 can be put into deep sleep mode with a software instruction. But, in order for it\u00a0to automatically wake up from sleep mode after a certain interval, the <em>XPD (D0<\/em>\u00a0in D1 Mini board) pin must be tied to the ESP8266\u2019s reset line as shown in the circuit diagram above. The DHT22 circuit is built on a perf board in the form of\u00a0a D1 Mini shield as shown below.<\/p>\n<div id=\"attachment_12051\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_142651.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-12051\" class=\"wp-image-12051 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_142651.jpg\" alt=\"p_20161008_142651\" width=\"590\" height=\"440\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_142651.jpg 590w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/P_20161008_142651-580x433.jpg 580w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><p id=\"caption-attachment-12051\" class=\"wp-caption-text\">DHT22 sensor shield<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>The ESP8266 program for this project is developed using Arduino IDE. So, you need to install the <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\">ESP8266 core<\/a><\/strong> to enable the Arduino IDE for ESP8266 programming. Instructions can be found in the <a href=\"https:\/\/github.com\/esp8266\/Arduino\" target=\"_blank\">ESP8266 core github page<\/a>. Similarly, you would also need to\u00a0sign up for a ThingSpeak account and obtain\u00a0a\u00a0<strong>Write API Key<\/strong>, which is required to upload data to ThingSpeak. You can find instructions to do that online. The following Youtube video link is one example.<\/p>\n<p><iframe loading=\"lazy\" width=\"860\" height=\"484\" src=\"https:\/\/www.youtube.com\/embed\/rOj-PIqLaMM?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>The complete ESP8266 code for this project can be downloaded from the following link:<\/p>\n<p><strong><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/WeMos_DHT22_ThingSpeak.zip\">Download_Code<\/a><\/strong><\/p>\n<p>Make sure you update the SSID, Wifi password, and ThingSpeak API to match with yours. The temperature and humidity readings are acquired from DHT22 in every 60 seconds and are uploaded to ThingSpeak server. Between two samples, the ESP8266 is put to sleep using\u00a0<em>ESP.deepSleep()<\/em> function in Arduino IDE.<\/p>\n<p>If everything worked fine, you would see the temperature and humidity measurements profiles on your ThingSpeak channel graphs.<\/p>\n<div id=\"attachment_12058\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1t.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-12058\" class=\"wp-image-12058 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1t.jpg\" alt=\"thingspeak1t\" width=\"590\" height=\"401\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1t.jpg 590w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1t-580x394.jpg 580w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><p id=\"caption-attachment-12058\" class=\"wp-caption-text\">ThingSpeak Field 1 (temperature plot)<\/p><\/div>\n<div id=\"attachment_12057\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1h.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-12057\" class=\"wp-image-12057 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1h.jpg\" alt=\"thingspeak1h\" width=\"590\" height=\"396\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1h.jpg 590w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/10\/ThingSpeak1h-580x389.jpg 580w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><p id=\"caption-attachment-12057\" class=\"wp-caption-text\">ThingSpeak Field 1 (humidity plot)<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>ESP8266 has made it possible for hobbyists and makers to develop IoT applications in simple and inexpensive ways. This article shows an example of making a very simple temperature and humidity logger using ESP8266 that uploads the data directly to a\u00a0cloud service, such as ThingSpeak, and allows\u00a0to\u00a0visualize the data in real time. The ESP8266 module used in this project is WeMOS&#8217; D1 Mini board. Because the D1 board comes with the\u00a0CH340G\u00a0USB to UART converter module and a micro USB connector preinstalled on board, all you need is an USB cable to upload your program to the ESP8266. For temperature and<\/p>\n","protected":false},"author":1,"featured_media":12083,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1044,1464,958],"tags":[],"class_list":["post-12045","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266","category-featured","category-internet-of-things"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/12045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=12045"}],"version-history":[{"count":21,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/12045\/revisions"}],"predecessor-version":[{"id":12076,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/12045\/revisions\/12076"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/12083"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=12045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=12045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=12045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}