{"id":4589,"date":"2019-11-29T00:01:58","date_gmt":"2019-11-28T16:01:58","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=4589"},"modified":"2023-04-14T09:16:28","modified_gmt":"2023-04-14T01:16:28","slug":"esp8266-%e6%87%89%e7%94%a8%e4%b8%80%ef%bc%9a%e6%99%ba%e8%83%bd%e6%8f%92%e5%ba%a7-3-dht-11-%e6%ba%ab%e6%bf%95%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=4589","title":{"rendered":"ESP8266 \u61c9\u7528\u4e00\uff1a\u667a\u80fd\u63d2\u5ea7 .3 DHT-11 \u6eab\u6fd5\u5ea6"},"content":{"rendered":"<p>\u7d42\u65bc\u8981\u628a\u73fe\u5be6\u4e16\u754c\u548c\u6578\u4f4d\u4e16\u754c\u9023\u63a5\u4e86\uff0c\u4e00\u958b\u59cb\u7684\u73fe\u5be6\u5c0d\u8c61\u662f\u74b0\u5883\u6eab\u3001\u6fd5\u5ea6\uff0c\u6240\u4ee5\u8981\u4f7f\u7528\u6eab\u3001\u6fd5\u5ea6\u76e3\u6e2c\u5668\u6216\u662f\u8aaa\u76e3\u6e2c\u6a21\u7d44\u3002<\/p>\n<p>\u6a21\u7d44\u4e00\u822c\u90fd\u662f\u5c07\u4e3b\u529f\u80fd\u96fb\u5b50\u96f6\u4ef6\u52a0\u4e0a\u5fc5\u8981\u7684\u914d\u5957\u96fb\u8def\u6210\u70ba\u7368\u7acb\u96f6\u4ef6\uff0c\u975e\u96fb\u5b50\u5c08\u696d\u4f7f\u7528\u6703\u6bd4\u8f03\u65b9\u4fbf\uff0cHoyo \u4f7f\u7528\u7684\u6a21\u7d44\u662f DHT-11<\/p>\n<ul>\n<li><a href=\"https:\/\/goods.ruten.com.tw\/item\/show?21529119560483\" target=\"_blank\" rel=\"noopener\">\u3010TNA168\u8ce3\u5834\u3011YS-31 \u55ae\u532f\u6d41\u6392\u6578\u4f4d\u6eab\u6fd5\u5ea6\u611f\u6e2c\u5668 DHT11\u6a21\u7d44 Arduino \u96fb\u5b50\u7a4d\u6728(A023)<\/a><\/li>\n<\/ul>\n<p>(\u975e\u696d\u914d\uff0c\u8ce3\u5834\u5167\u9084\u6709\u53e6\u4e00\u500b\u662f\u53ea\u6709\u76e3\u6e2c\u5668\uff0c\u6bd4\u8f03\u4fbf\u5b9c\u53ef\u662f\u6c92\u6709\u61c9\u7528\u96fb\u8def)<\/p>\n<p>--<\/p>\n<h2>\u52a0\u5165\u7a0b\u5f0f\u5eab<\/h2>\n<p>\u70ba\u4e86\u8b80\u53d6 DHT11 \u6578\u64da\uff0c\u6240\u4ee5\u76f4\u63a5\u7528\u5176\u4ed6\u5927\u5927\u5206\u4eab\u7684\u7a0b\u5f0f\u5eab\u662f\u6bd4\u8f03\u5feb\u901f\u7684\u65b9\u5f0f<\/p>\n<ul>\n<li><a href=\"https:\/\/www.makerblog.at\/2014\/08\/dht11-sensor-fuer-temperatur-und-luftfeuchtigkeit-am-arduino\/\" target=\"_blank\" rel=\"noopener\">DHT11 Sensor f\u00fcr Temperatur und Luftfeuchtigkeit am Arduino<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/adidax\/dht11\" target=\"_blank\" rel=\"noopener\">dht11<\/a> (Hoyo \u7528\u9019\u500b)<\/li>\n<li><a href=\"https:\/\/cdn-shop.adafruit.com\/datasheets\/DHT11-chinese.pdf\" target=\"_blank\" rel=\"noopener\">\u6570\u5b57\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668DHT11<\/a> (\u4e2d\u6587 Datasheet)<\/li>\n<\/ul>\n<p>\u5f9e GitHub \u4e0b\u8f09 zip \u6253\u958b Arduino IDE\uff0c\u8349\u7a3f\u6a94 \u2192 \u532f\u5165\u7a0b\u5f0f\u5eab \u2192 dht11-master.zip<\/p>\n<p>--<\/p>\n<h2>\u7a0b\u5f0f\u7bc4\u4f8b - \u5f9e\u4e32\u5217\u57e0\u89c0\u770b\u6eab\u3001\u6fd5\u5ea6<\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true \">#include &lt;dht11.h&gt;\r\n\r\ndht11 DHT11;\r\n#define DHT11PIN 12\r\n\r\nvoid setup(){\r\n    Serial.begin(115200);\r\n    Serial.print( \"Start...\" );\r\n}\r\n\r\nvoid loop(){\r\n    int chk = DHT11.read(DHT11PIN);\r\n    Serial.print( (float)DHT11.temperature, 2 );\r\n    Serial.print(\" : \");\r\n    Serial.println( (float)DHT11.humidity, 2 );\r\n\r\n    delay(2000);\r\n}<\/pre>\n<p>\u4e0b\u5716\u4e2d\u7684 delay \u6642\u9593\u70ba 200 \uff0c\u4e26\u975e\u4e0a\u9762\u8a2d\u5b9a\u7684 2000<\/p>\n<figure id=\"attachment_6429\" aria-describedby=\"caption-attachment-6429\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/ESP8266_DHT11_Serial.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"wp-image-6429 size-medium\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/ESP8266_DHT11_Serial-300x207.png\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/ESP8266_DHT11_Serial-300x207.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/ESP8266_DHT11_Serial-435x300.png 435w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/ESP8266_DHT11_Serial.png 656w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-6429\" class=\"wp-caption-text\">ESP8266 DHT11 \u4e32\u5217\u57e0\u8f38\u51fa<\/figcaption><\/figure>\n<p>--<\/p>\n<h2>\u5c07 DHT11 \u8b80\u53d6\u6eab\u3001\u6fd5\u5ea6\u4e0a\u50b3\u5230\u4e3b\u6a5f<\/h2>\n<p>\u5148\u5047\u8a2d\u4f60\u5df2\u7d93\u6709\u4e00\u500b\u53ef\u4ee5\u4f7f\u7528 HTTP API \u4e0a\u50b3\u8cc7\u6599\u7684\u4e3b\u6a5f\uff0c\u7136\u5f8c\u63a5\u4e0b\u4f86\u5c31\u662f\u5982\u4f55\u628a\u8cc7\u6599\u4e1f\u4e0a\u53bb\uff0c\u5728\u6b64\u5047\u8a2d\u7684\u898f\u683c\u662f\u4f7f\u7528 GET \u50b3\u905e<\/p>\n<pre class=\"lang:default decode:true \">#include &lt;dht11.h&gt;\r\n#include &lt;ESP8266WiFi.h&gt;\r\n\r\n\/\/\r\nconst char* ssid = \"ssid name\";\r\nconst char* password = \"ssid password\";\r\n\r\ndht11 DHT11;\r\n#define DHT11PIN 12\r\nfloat t;\r\nfloat h;\r\n\r\nWiFiClient client;\r\n\r\nString serverURL = \"iot.hoyo.idv.tw\";\r\nString url = \"\";\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  Serial.print( \"Start...\" );\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(500);\r\n    Serial.println(\".\");\r\n  }\r\n}\r\n\r\nvoid loop() {\r\n\r\n  int chk = DHT11.read(DHT11PIN);\r\n  t = DHT11.temperature;\r\n  h = DHT11.humidity;\r\n\r\n  delay(1000);\r\n\r\n  Serial.print( (float)DHT11.temperature );\r\n  Serial.print(\" : \");\r\n  Serial.println( (float)DHT11.humidity );\r\n\r\n  url = \"\/iot.php?t=\" +  String(t) + \"&amp;h=\" +  String(h);\r\n\r\n  if (client.connect(serverURL, 80)) {\r\n    client.println(\"GET \" + url + \" HTTP\/1.1\");\r\n    client.println(\"Host: \" + serverURL);\r\n    client.println(\"Connection: close\");\r\n    client.println();\r\n    client.stop();\r\n  }\r\n\r\n  delay(2000);\r\n}<\/pre>\n<p>--<\/p>\n<h2>\u4e0a\u50b3\u5230\u5176\u4ed6 IoT \u5e73\u53f0 - \u4ee5 Ubidots \u70ba\u4f8b<\/h2>\n<ul>\n<li>\u5b89\u88dd <a href=\"https:\/\/github.com\/ubidots\/ubidots-esp8266\/#setup\" target=\"_blank\" rel=\"noopener\">ubidots\/ubidots-esp8266: Library for uploading ESP8266 devices to Ubidots<\/a><a id=\"user-content-setup\" class=\"anchor\" href=\"https:\/\/github.com\/ubidots\/ubidots-esp8266\/#setup\" aria-hidden=\"true\"><\/a><a id=\"user-content-setup\" class=\"anchor\" href=\"https:\/\/github.com\/ubidots\/ubidots-esp8266\/#setup\" aria-hidden=\"true\"><\/a><\/li>\n<li>\u7a0b\u5f0f\u7bc4\u4f8b <a id=\"0d9a56a50371a032748d3cc84154e8ec-be40b90eb5568a174d6728aaf930d031c9082a7d\" class=\"js-navigation-open\" title=\"SendValuesHttp.ino\" href=\"https:\/\/github.com\/ubidots\/ubidots-esp8266\/blob\/master\/examples\/SendValuesHttp\/SendValuesHttp.ino\" target=\"_blank\" rel=\"noopener\">SendValuesHttp.ino<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">#include \"Ubidots.h\"\r\n#include &lt;dht11.h&gt;\r\n\r\nconst char* UBIDOTS_TOKEN = \"BBFF-abFB2KelTXxxxxxxxxxHo5eORjEy\";\r\nconst char* ssid = \"wifi name\";\r\nconst char* password = \"wifi password\";\r\n\r\ndht11 DHT11;\r\n#define DHT11PIN 12\r\n\r\nUbidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  ubidots.wifiConnect(ssid, password);\r\n}\r\n\r\nvoid loop() {\r\n  int chk = DHT11.read(DHT11PIN);\r\n  Serial.print( (float)DHT11.temperature, 2 );\r\n  Serial.print(\" : \");\r\n  Serial.println( (float)DHT11.humidity, 2 );\r\n\r\n  float t = DHT11.temperature;\r\n  float h = DHT11.humidity;\r\n\r\n  ubidots.add(\"Temperature\", t);\r\n  ubidots.add(\"Humidity\", h);\r\n\r\n  bool bufferSent = false;\r\n  bufferSent = ubidots.send();\r\n\r\n  delay(5000);\r\n}<\/pre>\n<p>\u5f9e Devices \u67e5\u770b\u4e0a\u50b3\u6578\u64da<\/p>\n<p><a href=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-6508\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154-300x140.png\" alt=\"\" width=\"300\" height=\"140\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154-300x140.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154-768x358.png 768w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154-1024x477.png 1024w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154-500x233.png 500w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094154.png 1348w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u9ede\u9078\u55ae\u4e00\u76e3\u6e2c\u6578\u64da\u53ef\u4ee5\u770b\u5230\u8a73\u7d30\u6578\u64da<\/p>\n<p><a href=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350.png\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-6509\" src=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350-300x183.png\" alt=\"\" width=\"300\" height=\"183\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350-300x183.png 300w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350-768x468.png 768w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350-493x300.png 493w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2019\/11\/Image-20191130-094350.png 923w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>--<\/p>\n<h2>\u63a5\u8173\u63a5\u53cd\u6703\u71d2\u58de\uff01<\/h2>\n<p>\u5176\u5be6\u96fb\u5b50\u96f6\u4ef6\u5927\u591a\u662f\u9019\u6a23\u7684\u4e0b\u5834\uff0c\u4ee5\u524d\u641e\u97f3\u97ff DIY \u71d2\u7684\u66f4\u6158 ...<\/p>\n<p>--<\/p>\n<h2>\u512a\u3001\u7f3a\u9ede<\/h2>\n<p>\u6975\u9650\u503c\u4ee5\u53ca\u6e96\u78ba\u5ea6\u662f DHT11 \u7684\u786c\u50b7\uff0c\u6240\u4ee5\u5728\u719f\u6089 DHT11 \u4e4b\u5f8c\u53ef\u4ee5\u9078\u64c7\u66f4\u9ad8\u968e\u7684\u540c\u985e\u7522\u54c1\uff0c\u4f8b\u5982 DHT2x \u7cfb\u5217<\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4589\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;12,253&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7d42\u65bc\u8981\u628a\u73fe\u5be6\u4e16\u754c\u548c\u6578\u4f4d\u4e16\u754c\u9023\u63a5...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4589\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;12,253&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[273,306,272],"tags":[275,331],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4589"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4589"}],"version-history":[{"count":12,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4589\/revisions"}],"predecessor-version":[{"id":6511,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4589\/revisions\/6511"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}