{"id":2123,"date":"2018-05-18T18:42:30","date_gmt":"2018-05-18T10:42:30","guid":{"rendered":"https:\/\/drho.club\/?p=2123"},"modified":"2018-05-18T18:42:30","modified_gmt":"2018-05-18T10:42:30","slug":"arduino-unit-13","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2018\/05\/18\/arduino-unit-13\/","title":{"rendered":"\u3010Arduino\u3011\u6eab\u6fd5\u5ea6\u611f\u6e2c\u5668\u8207LCD\u6a21\u7d44"},"content":{"rendered":"<p>\u5728Arduino\u7684DHT11\u6a21\u7d44\u4e2d\u6709\u63d0\u4f9b\u6eab\u5ea6\u8207\u6fd5\u5ea6\u7684\u611f\u6e2c\u5668\uff0c\u6709\u4e09\u96bb\u63a5\u8173\u5206\u5225\u70ba\u6578\u4f4d\u8a0a\u865f\u8173(S)\u3001VCC\u3001GND\u3002<\/p>\n<figure id=\"attachment_2124\" aria-describedby=\"caption-attachment-2124\" style=\"width: 185px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/DHT11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2124 size-medium\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/DHT11-185x300.png\" alt=\"\" width=\"185\" height=\"300\" \/><\/a><figcaption id=\"caption-attachment-2124\" class=\"wp-caption-text\">DHT11\u6a21\u7d44<\/figcaption><\/figure>\n<p>\u8981\u4f7f\u7528\u7a0b\u5f0f\u4f86\u63a7\u5236\u6b64\u6a21\u7d44\u6642\u5fc5\u9808\u5148\u4e0aArduino\u7684\u7db2\u7ad9\u4e0b\u8f09\u5b98\u65b9\u6240\u63d0\u4f9b\u7684\u51fd\u5f0f\u5eab <a href=\"https:\/\/github.com\/adafruit\/DHT-sensor-library\">DHT.h\u51fd\u5f0f\u5eab\u4e0b\u8f09<\/a>\uff0c\u9032\u5165\u7db2\u7ad9\u5f8c\u9ede\u9078 &#8220;Clone or download&#8221; &gt;&gt; &#8220;Download ZIP&#8221;\uff0c\u4ee5\u53ca<a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\">Adafruit\u7684\u9a45\u52d5\u7a0b\u5f0f<\/a>\u4e5f\u662f\u8981\u4f7f\u7528\u540c\u6a23\u7684\u65b9\u5f0f\u4e0b\u8f09\u5b8c\u6210\u89e3\u58d3\u7e2e\u624d\u884c\u3002<\/p>\n<p>\u4e0b\u8f09\u5b8c\u6210\u5f8c\u89e3\u58d3\u7e2e\uff0c\u5c07 &#8220;DHT-sensor-library-master&#8221; \u8cc7\u6599\u593e\u653e\u5165 \/\u6587\u4ef6\/Arduino\/libraries \u76ee\u9304\u5e95\u4e0b\u5373\u53ef\uff0c\u5982\u4e0b\u5716\u6240\u793a\uff0c\u5728\u9019\u500b\u76ee\u9304\u4e4b\u4e0b\u8981\u6709\u5169\u500b\u76f8\u95dc\u7684\u9a45\u52d5\u7a0b\u5f0f\u8cc7\u6599\u593e\u624d\u884c\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/unnamed-file-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2126 size-full\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/unnamed-file-1.png\" alt=\"\" width=\"712\" height=\"179\" \/><\/a><\/p>\n<p>\u63a5\u7dda\u90e8\u5206\u53ea\u9700\u8981\u5c07DHT11\u6a21\u7d44\u4e2dS\u8173\u4f4d\u63a5\u81f3Arduino \u7684\u7b2c2\u8173(\u5fc5\u9808\u548c\u7a0b\u5f0f\u4e2d\u9078\u64c7\u7684\u8173\u4f4d\u76f8\u540c)\uff0cVCC\u8207GND\u5206\u5225\u63a5\u81f35V\u8207GND\u3002<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/456.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2127 size-medium\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/456-289x300.png\" alt=\"\" width=\"289\" height=\"300\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/456-289x300.png 289w, https:\/\/104.es\/wp-content\/uploads\/2018\/05\/456.png 586w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/a><\/p>\n<p>\u63a5\u7dda\u5b8c\u6210\u5f8c\u5c31\u53ef\u4ee5\u958b\u59cb\u5beb\u7a0b\u5f0f\u4e86\uff0c<\/p>\n<p>[code]<\/p>\n<p>#include &quot;DHT.h&quot;\u00a0 \u00a0 \/\/\u8f09\u5165\u51fd\u5f0f\u5eab<br \/>\n#define DHTPIN 2 \/\/\u9078\u64c7\u8b80\u53d6\u8cc7\u6599\u7684\u8173\u4f4d<br \/>\n#define DHTTYPE DHT11 \/\/ \u5728\u6b64\u7bc4\u4f8b\u4e2d\u9078\u7528DHT 11<\/p>\n<p>DHT dht(DHTPIN, DHTTYPE); \/\/Initialize DHT sensor<\/p>\n<p>void setup() {<br \/>\n    Serial.begin(9600); \/\/\u8a2d\u5b9a\u9b91\u7387\u70ba9600<br \/>\n    Serial.println(&quot;DHT11 test!&quot;);<br \/>\n    dht.begin(); \/\/\u555f\u52d5DHT<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n    delay(2000); \/\/\u6bcf2\u79d2\u9418\u66f4\u65b0\u4e00\u6b21<br \/>\n    float h = dht.readHumidity(); \/\/\u8b80\u53d6\u6fd5\u5ea6<br \/>\n    float t = dht.readTemperature(); \/\/\u8b80\u53d6\u651d\u6c0f\u6eab\u5ea6<br \/>\n    float f = dht.readTemperature(true); \/\/\u8b80\u53d6\u83ef\u6c0f\u6eab\u5ea6<\/p>\n<p>    if (isnan(h) || isnan(t) || isnan(f)) {<br \/>\n        Serial.println(&quot;\u7121\u6cd5\u5f9eDHT\u6a21\u7d44\u8b80\u53d6\u8cc7\u6599!&quot;);<br \/>\n        return;<br \/>\n    }<br \/>\n    Serial.print(&quot;Humidity: &quot;); \/\/\u5728\u5e8f\u5217\u76e3\u63a7\u8996\u7a97\u986f\u793a\u6eab\u5ea6\u8207\u6fd5\u5ea6<br \/>\n    Serial.print(h);<br \/>\n    Serial.print(&quot; %\\t&quot;);<br \/>\n    Serial.print(&quot;Temperature: &quot;);<br \/>\n    Serial.print(t);<br \/>\n    Serial.print(&quot; *C &quot;);<br \/>\n    Serial.print(f);<br \/>\n    Serial.println(&quot; *F\\t&quot;);<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>\u4e0a\u50b3\u5b8c\u6210\u5f8c\u6253\u958b\u5e8f\u5217\u76e3\u63a7\u8996\u7a97\uff0c\u4e26\u5c07\u9b91\u7387\u9078\u64c7\u70ba9600(\u5fc5\u9808\u548c\u7a0b\u5f0f\u4e2d\u76f8\u540c)\uff0c<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/unnamed-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2125 size-full\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/unnamed-file.png\" alt=\"\" width=\"780\" height=\"443\" \/><\/a><\/p>\n<p>\u6210\u529f\u5728\u5e8f\u5217\u76e3\u63a7\u8996\u7a97\u89c0\u770b\u6eab\u6ebc\u5ea6\u8cc7\u6599\u5f8c\uff0c\u7d50\u5408<a href=\"https:\/\/drho.club\/2017\/12\/arduino-unit-11\/\"> Unit11:LCD\u9ede\u9663\u6db2\u6676\u986f\u793a\u6a21\u7d44\u64cd\u4f5c\u5be6\u7fd2<\/a>\u00a0\uff0c\u5c07\u6eab\u6ebc\u5ea6\u7684\u8cc7\u8a0a\u986f\u793a\u5728LCD\u6a21\u7d44\u4e0a\u3002<\/p>\n<p>\u6574\u5408\u5f8c\u7684\u7a0b\u5f0f\u78bc\u5982\u4e0b:<\/p>\n<p>[code]<\/p>\n<p>#include &quot;DHT.h&quot;<br \/>\n#define DHTPIN 2 \/\/\u9078\u64c7\u8b80\u53d6\u8cc7\u6599\u7684\u8173\u4f4d<br \/>\n#define DHTTYPE DHT11 \/\/ \u5728\u6b64\u7bc4\u4f8b\u4e2d\u9078\u7528DHT 11<br \/>\n#include &quot;Wire.h&quot;<br \/>\n#include &quot;LiquidCrystal_I2C.h&quot;<\/p>\n<p>LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);<br \/>\nDHT dht(DHTPIN, DHTTYPE); \/\/Initialize DHT sensor<\/p>\n<p>void setup() {<br \/>\n    Serial.begin(9600); \/\/\u8a2d\u5b9a\u9b91\u7387\u70ba9600&lt;\/strong&gt;<br \/>\n    Serial.println(&quot;DHTxx test!&quot;);<br \/>\n    dht.begin(); \/\/\u555f\u52d5DHT&lt;\/strong&gt;<br \/>\n    lcd.begin(16,2);<br \/>\n    lcd.backlight();<br \/>\n    delay(2000);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n    delay(2000); \/\/\u6bcf2\u79d2\u9418\u66f4\u65b0\u4e00\u6b21<br \/>\n    float h = dht.readHumidity(); \/\/\u8b80\u53d6\u6fd5\u5ea6<br \/>\n    float t = dht.readTemperature(); \/\/\u8b80\u53d6\u651d\u6c0f\u6eab\u5ea6<br \/>\n    float f = dht.readTemperature(true); \/\/\u8b80\u53d6\u83ef\u6c0f\u6eab\u5ea6<\/p>\n<p>    if (isnan(h) || isnan(t) || isnan(f)) {<br \/>\n        Serial.println(&quot;\u7121\u6cd5\u5f9eDHT\u6a21\u7d44\u8b80\u53d6\u8cc7\u6599!&quot;);<br \/>\n        return;<br \/>\n    }<br \/>\n    Serial.print(&quot;Humidity: &quot;); \/\/\u5728\u5e8f\u5217\u76e3\u63a7\u8996\u7a97\u986f\u793a\u6eab\u5ea6\u8207\u6fd5\u5ea6<br \/>\n    Serial.print(h);<br \/>\n    Serial.print(&quot; %\\t&quot;);<br \/>\n    Serial.print(&quot;Temperature: &quot;);<br \/>\n    Serial.print(t);<br \/>\n    Serial.print(&quot; *C &quot;);<br \/>\n    Serial.print(f);<br \/>\n    Serial.println(&quot; *F\\t&quot;);<br \/>\n    \/\/&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.\u5728LCD\u4e0a\u986f\u793a\u6eab\u6fd5\u5ea6\u8cc7\u8a0a<br \/>\n    lcd.setCursor(0, 0);<br \/>\n    lcd.print(String(&quot;&quot;) + &quot;H:&quot; + h + &quot;%&quot;);<br \/>\n    lcd.setCursor(0, 1);<br \/>\n    lcd.print(String(&quot;&quot;) + &quot;T:&quot;+ t + (char)223 + &quot;C&quot;);<br \/>\n}<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Arduino\u7684DHT11\u6a21\u7d44\u4e2d\u6709\u63d0\u4f9b\u6eab\u5ea6\u8207\u6fd5\u5ea6\u7684\u611f\u6e2c\u5668\uff0c\u6709\u4e09\u96bb\u63a5\u8173\u5206\u5225\u70ba\u6578\u4f4d\u8a0a\u865f\u8173(S)\u3001VCC\u3001GND\u3002&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2123","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2123"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2123\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}