{"id":601,"date":"2022-11-21T17:31:38","date_gmt":"2022-11-21T09:31:38","guid":{"rendered":"http:\/\/wordpress.loc\/?p=601"},"modified":"2023-02-22T20:48:20","modified_gmt":"2023-02-22T12:48:20","slug":"esp32_ch1-14","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/11\/21\/601\/","title":{"rendered":"\u7b2c08\u7bc7 \u8d85\u97f3\u6ce2\u6e2c\u8ddd\u53ca\u8702\u9cf4\u5668\u88fd\u4f5c\u5012\u8eca\u96f7\u9054"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u73fe\u5728\u7684\u6c7d\u8eca\u5927\u90e8\u5206\u90fd\u6709\u914d\u5099\u5012\u8eca\u96f7\u9054\uff0c\u5c31\u662f\u5012\u8eca\u6642\uff0c\u6703\u4f9d\u64da\u8eca\u5b50\u8207\u969c\u7919\u7269\u4e4b\u9593\u7684\u8ddd\u96e2\u767c\u51fa\u4e0d\u540c\u983b\u7387\u7684\u55f6\u55f6\u8072\uff0c\u7528\u4f86\u6307\u5f15\u99d5\u99db\u907f\u514d\u649e\u5230\u5225\u4eba\u7684\u8eca\u5b50\uff0c\u800c\u9019\u5957\u5012\u8eca\u96f7\u9054\u6211\u5011\u4e5f\u53ef\u4ee5\u4f7f\u7528ESP32\u4f86\u5be6\u505a\u3002<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">Table of Contents<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-\">\u5be6\u505a\u8aaa\u660e<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1\">\u8d85\u97f3\u6ce2\u8207\u8702\u9cf4\u5668\uff1a\u5012\u8eca\u96f7\u9054<\/a><\/li><li class=\"\"><a href=\"#htoc-11\">\u8d85\u97f3\u6ce2\u8ddd\u96e2\u611f\u6e2c\u539f\u7406<\/a><\/li><li class=\"\"><a href=\"#htoc-111\">\u90a3\u9ebc\u56de\u97f3\u8207\u8d85\u97f3\u6ce2\u8ddd\u96e2\u611f\u6e2c\u5668\u6709\u4ec0\u9ebc\u95dc\u4fc2\u5462\uff1f<\/a><\/li><\/ul><\/li><li class=\"\"><a href=\"#htoc-1111\">\u4e00\u3001\u8d85\u97f3\u6ce2\u6e2c\u91cf\u8ddd\u96e2<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-11111\">\u8d85\u97f3\u6ce2\u8ddd\u96e2\u6e2c\u91cf\u7a0b\u5f0f\u8aaa\u660e<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1-n-delaymicroseconds-n\">1. \u66ab\u505cn\u5fae\u79d2\uff1adelayMicroseconds(n);<\/a><\/li><li class=\"\"><a href=\"#htoc-2-pulsein\">2. \u8a08\u7b97\u8173\u4f4d\u7684\u6536\u5230\u7b26\u5408\u96fb\u58d3\u7684\u6642\u9593\u5dee\uff1apulseIn(\u8173\u4f4d,\u96fb\u58d3);<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"\"><a href=\"#htoc-111111\">\u4e8c\u3001\u5012\u8eca\u96f7\u9054<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1111111\">\u7121\u6e90\u8702\u9cf4\u5668\u7a0b\u5f0f\u8aaa\u660e<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1-tone-pin-frequency-ms\">1. \u767c\u51fa\u4e00\u6bb5\u6642\u9593\u7684\u8072\u97f3\uff1atone(pin, frequency, ms);<\/a><\/li><li class=\"\"><a href=\"#htoc-2\">2. \u983b\u7387\u97f3\u968e\u5c0d\u7167\u8868<\/a><\/li><\/ul><\/li><li class=\"\"><a href=\"#htoc-11111111\">\u5012\u8eca\u96f7\u9054\u7a0b\u5f0f\u8aaa\u660e<\/a><\/li><\/ul><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u5be6\u505a\u8aaa\u660e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-1\">\u8d85\u97f3\u6ce2\u8207\u8702\u9cf4\u5668\uff1a\u5012\u8eca\u96f7\u9054<\/h3>\n\n\n\n<p>\u73fe\u5728\u7684\u6c7d\u8eca\u5927\u90e8\u5206\u90fd\u6709\u914d\u5099\u5012\u8eca\u96f7\u9054\uff0c\u5c31\u662f\u5012\u8eca\u6642\uff0c\u6703\u4f9d\u64da\u8eca\u5b50\u8207\u969c\u7919\u7269\u4e4b\u9593\u7684\u8ddd\u96e2\u767c\u51fa\u4e0d\u540c\u983b\u7387\u7684\u55f6\u55f6\u8072\uff0c\u7528\u4f86\u6307\u5f15\u99d5\u99db\u907f\u514d\u649e\u5230\u5225\u4eba\u7684\u8eca\u5b50\uff0c\u800c\u9019\u5957\u5012\u8eca\u96f7\u9054\u6211\u5011\u4e5f\u53ef\u4ee5\u4f7f\u7528ESP32\u4f86\u5be6\u505a\u3002\u672c\u7ae0\u5206\u6210\u5169\u500b\u90e8\u4efd\uff0c\u7b2c\u4e00\u7bc0\u6211\u5011\u5148\u4f86\u4e86\u89e3\u8d85\u97f3\u6ce2\u6e2c\u8ddd\u7684\u539f\u7406\uff0c\u7b2c\u4e8c\u7bc0\u518d\u5be6\u505a\u8702\u9cf4\u5668\u8207\u5012\u8eca\u96f7\u9054\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-11\">\u8d85\u97f3\u6ce2\u8ddd\u96e2\u611f\u6e2c\u539f\u7406<\/h3>\n\n\n\n<p>\u722c\u5c71\u6642\uff0c\u5982\u679c\u6211\u5011\u5c0d\u8457\u9060\u8655\u7684\u5c71\u982d\u5927\u558a\u300c\u4f60\u597d\u300d\uff0c\u904e\u4e86\u5e7e\u79d2\u5c31\u6703\u807d\u5230\u6709\u4eba\u4e5f\u5c0d\u4f60\u558a\u8457\u300c\u4f60\u597d\u300d\uff0c\u7b46\u8005\u5c0f\u6642\u5019\u4e00\u76f4\u4ee5\u70ba\u662f\u5c0d\u9762\u7684\u767b\u5c71\u5ba2\u8ddf\u4f60\u5728\u6253\u62db\u547c\uff0c\u5f8c\u4f86\u624d\u77e5\u9053\u9019\u53eb\u505a\u56de\u97f3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.nmking.io\/wp-content\/uploads\/2022\/11\/image.png?resize=840%2C396&#038;ssl=1\" alt=\"\" class=\"wp-image-610\" width=\"840\" height=\"396\" srcset=\"https:\/\/i0.wp.com\/www.nmking.io\/wp-content\/uploads\/2022\/11\/image.png?w=450&amp;ssl=1 450w, https:\/\/i0.wp.com\/www.nmking.io\/wp-content\/uploads\/2022\/11\/image.png?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.nmking.io\/wp-content\/uploads\/2022\/11\/image.png?resize=200%2C94&amp;ssl=1 200w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><figcaption class=\"wp-element-caption\">\u56de\u97f3\u7684\u539f\u7406\u793a\u610f\u5716<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-111\">\u90a3\u9ebc\u56de\u97f3\u8207\u8d85\u97f3\u6ce2\u8ddd\u96e2\u611f\u6e2c\u5668\u6709\u4ec0\u9ebc\u95dc\u4fc2\u5462\uff1f<\/h3>\n\n\n\n<p>\u6240\u8b02\u7684\u56de\u97f3\u5c31\u662f\u8072\u97f3\u50b3\u905e\u8def\u5f91\u4e0a\u6709\u969c\u7919\u7269\u6642\uff0c\u8072\u97f3\u5c31\u6703\u53cd\u5f48\u5230\u539f\u4f86\u767c\u51fa\u8072\u97f3\u7684\u4eba\uff0c\u800c\u8072\u97f3\u5728\u7a7a\u6c23\u4e2d\u50b3\u905e\u7684\u901f\u5ea6\u7d04340\u516c\u5c3a\/\u79d2\uff0c\u56e0\u6b64\u82e5\u6211\u5011\u8a08\u7b97\u767c\u51fa(trigger)\u6642\u9593\u8207\u807d\u5230\u56de\u97f3(echo)\u7684\u6642\u9593\u5dee\uff0c\u5c31\u53ef\u4ee5\u5927\u81f4\u63a8\u7b97\u51fa\u767c\u8072\u8005\u8207\u969c\u7919\u7269\u4e4b\u9593\u7684\u8ddd\u96e2\u4e86\uff0c\u6211\u5011\u53ef\u4ee5\u5c07\u516c\u5f0f\u8868\u793a\u70ba\uff1a<\/p>\n\n\n\n<p>\u8ddd\u96e2(m)=\uff08\u6642\u9593(s) x 340\uff09 \/ 2<\/p>\n\n\n\n<p>\u6578\u5b57340\u662f\u97f3\u901f\uff0c\u800c\u8981\u96642\u5247\u662f\u56e0\u70ba\u8072\u97f3\u53bb\u4e00\u6b21\u3001\u56de\u4e00\u6b21\uff0c\u4e00\u5171\u8dd1\u4e86\u5169\u6b21\u6240\u4ee5\u8981\u96642\uff0c\u800c\u9019\u4e5f\u5c31\u662f\u5f8c\u4f86\u5728\u4e8c\u6b21\u5927\u6230\u4e2d\u5ee3\u6cdb\u4f7f\u7528\u7684\u96f7\u9054\u7684\u539f\u7406\uff0c\u4e0d\u540c\u7684\u5730\u65b9\u662f\u96f7\u9054\u7528\u7684\u662f\u96fb\u78c1\u6ce2\uff0c\u800c\u6211\u5011\u5728\u672c\u6b21\u5be6\u9a57\u7528\u662f\u8d85\u97f3\u6ce2\uff08Ultrasound\uff09\u6a21\u7d44\uff0c\u6240\u8b02\u7684\u300c\u8d85\u300d\u97f3\u6ce2\u662f\u6307\u300c\u8d85\u51fa\u4eba\u985e\u53ef\u4ee5\u807d\u5230\u7684\u8072\u97f3\u983b\u7387\u300d\uff0c\u4e00\u822c\u4eba\u985e\u7684\u8033\u6735\u53ef\u4ee5\u807d\u5230\u7684\u8072\u97f3\u983b\u7387\u662f\u572816Hz~20KHz\u4e4b\u9593\uff0c\u800c\u8d85\u97f3\u6ce2\u6e2c\u8ddd\u6a21\u7d44\u5247\u8a2d\u8a08\u4f7f\u752820KHz\u4ee5\u4e0a\u7684\u983b\u7387\uff0c\u76ee\u7684\u662f\u4e0d\u8981\u5728\u6e2c\u8ddd\u6642\u767c\u51fa\u60f1\u4eba\u7684\u566a\u97f3\uff0c\u4e5f\u56e0\u70ba\u9019\u6a23\u9019\u500b\u6e2c\u91cf\u8ddd\u96e2\u7684\u6a21\u7d44\u5c31\u7a31\u70ba\u8d85\u97f3\u6ce2\u6e2c\u8ddd\u6a21\u7d44\uff0c\u5e02\u9762\u4e0a\u5e38\u898b\u7684\u578b\u865f\u662fHC-SR04\u5982\u4e0b\u5716\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1602866709-89406067-g.png?resize=364%2C216&#038;ssl=1\" alt=\"\" width=\"364\" height=\"216\"\/><figcaption class=\"wp-element-caption\">HC-SR04\u8d85\u97f3\u6ce2\u6a21\u7d44<\/figcaption><\/figure>\n\n\n\n<p>\u8d85\u97f3\u6ce2\u611f\u6e2c\u5668\u6709\u5169\u500b\u5927\u5927\u7684\u300c\u773c\u775b\u300d\uff0c\u5f88\u591a\u6a5f\u5668\u4eba\u6216\u5c0f\u8eca\u7d50\u69cb\u90fd\u6703\u5229\u7528\u9019\u500b\u611f\u6e2c\u5668\u505a\u907f\u969c\u529f\u80fd\uff0c\u4e0d\u904e\u5176\u5be6\u8207\u5176\u8aaa\u662f\u773c\u775b\uff0c\u4e0d\u5982\u8aaa\u662f\u300c\u8033\u6735\u300d\uff0c\u5de6\u4e0b\u89d2\u6a19\u793a\u7684\u300cT\u300d\u662fTX\u7684\u610f\u601d\uff0c\u4ee3\u8868\u5de6\u908a\u7684\u5b54\u8ca0\u8cac\u50b3\u9001(Transport)\u8d85\u97f3\u6ce2\uff0c\u800c\u53f3\u4e0b\u89d2\u6a19\u793a\u300cR\u300d\u662fRX\u4ee3\u8868\u53f3\u5074\u7684\u8033\u6735\u8ca0\u8cac\u63a5\u6536\uff08Receive\uff09\u8d85\u97f3\u6ce2\u56de\u97f3\uff0c\u4e5f\u5c31\u662f\u5de6\u5074\u662f\u5634\u5df4\u8ca0\u8cac\u767c\u51fa\u8072\u97f3\uff0c\u800c\u53f3\u5074\u662f\u8033\u6735\u8ca0\u8cac\u807d\u56de\u97f3\uff0c\u5169\u8005\u7f3a\u4e00\u4e0d\u53ef\u3002<\/p>\n\n\n\n<p>\u4e0b\u65b9\u56db\u500b\u8173\u4f4d\u5247\u4f9d\u5e8f\u70baVCC\u3001Trig\u3001Echo\u3001GND\uff0c\u5176\u4e2dTrig\u4ee3\u8868\u5634\u5df4\uff0c\u6c7a\u5b9a\u4f55\u6642\u767c\u51fa\u8072\u97f3\uff0cEcho\u5247\u4ee3\u8868\u8033\u6735\uff0c\u7528\u4f86\u8a08\u7b97\u807d\u5230\u56de\u97f3\u7684\u6642\u9593\uff0c\u518d\u900f\u904e\u516c\u5f0f\u5c31\u53ef\u4ee5\u8a08\u7b97\u8ddd\u96e2\u4e86\uff0c\u800cVCC\u8207GND\u5247\u8207\u4ee5\u5f80\u76f8\u540c\uff0c\u63a5\u57285V\u53caGND\u8173\u4f4d\uff0c\u9019\u88e1\u8aaa\u660e\u4e00\u4e0b\u76ee\u524d\u8d85\u97f3\u6ce2\u6709\u591a\u500b\u7248\u672c\uff0c\u6709\u5c11\u6578\u7248\u672c\u50c5\u80fd\u4f7f\u75285V\uff0c\u800c\u5927\u591a\u6578\u662f5V\u30013.3V\u90fd\u53ef\u7528\uff0c\u56e0\u6b64\u500b\u4eba\u5efa\u8b70\u63a5\u57285V\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u4e00\u500b\u8981\u6ce8\u610f\u7684\u5730\u65b9\u662f\u8d85\u97f3\u6ce2\u611f\u6e2c\u5668\u53ef\u91cf\u6e2c\u7684\u7bc4\u570d\u7d04\u57282cm~500cm\u4e4b\u9593\uff0c\u4f4e\u65bc2cm\u5247\u7121\u6cd5\u611f\u6e2c\uff0c\u8d85\u904e500cm\u5247\u6703\u76f8\u7576\u4e0d\u6e96\u78ba\uff0c\u9084\u6709\u5c31\u662f\u5982\u679c\u73fe\u5834\u6709\u591a\u500b\u8d85\u97f3\u6ce2\u611f\u6e2c\u5668\u540c\u6642\u4f5c\u7528\uff0c\u5247\u6703\u9020\u6210\u8072\u6ce2\u4e4b\u9593\u7684\u4e92\u76f8\u5e72\u64fe\uff0c\u56e0\u6b64\u4e0d\u8981\u8b93\u591a\u500b\u8d85\u97f3\u6ce2\u540c\u6642\u9032\u884c\u6e2c\u8ddd\u3002<\/p>\n\n\n\n<p>\u672c\u7bc0\u6211\u5011\u5c31\u4f7f\u7528\u8d85\u97f3\u6ce2\u611f\u6e2c\u5668\u4f86\u88fd\u4f5c\u5012\u8eca\u96f7\u9054\uff0c\u4e5f\u5c31\u662f\u8aaa\uff0c\u5229\u7528\u8d85\u97f3\u6ce2\u6e2c\u91cf\u8ddd\u96e2\uff0c\u4e26\u5229\u7528\u8702\u9cf4\u5668\u767c\u51fa\u8072\u97f3\u4f86\u6307\u5f15\u99d5\u99db\uff0c\u8b93\u99d5\u99db\u77e5\u9053\u8eca\u5b50\u8207\u969c\u7919\u7269\u4e4b\u9593\u7684\u8ddd\u96e2\u3002\u4e0d\u904e\u6211\u5011\u5148\u5206\u5225\u6e2c\u8a66\u8d85\u97f3\u6ce2\u8207\u8702\u9cf4\u5668\u662f\u5426\u6b63\u5e38\uff0c\u7136\u5f8c\u518d\u5c07\u529f\u80fd\u5408\u4f75\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-1111\">\u4e00\u3001\u8d85\u97f3\u6ce2\u6e2c\u91cf\u8ddd\u96e2<\/h2>\n\n\n\n<p>\u672c\u90e8\u4efd\u6211\u5011\u5148\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u8d85\u97f3\u6ce2\u6a21\u7d44\u9032\u884c\u8ddd\u96e2\u6e2c\u91cf\uff0c\u63a5\u7dda\u90e8\u4efd\u8acb\u53c3\u8003\u5716<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1602866717-4269113222-g.png?resize=439%2C454&#038;ssl=1\" alt=\"\" width=\"439\" height=\"454\"\/><figcaption class=\"wp-element-caption\">ESP32\u8207\u8d85\u97f3\u6ce2\u611f\u6e2c\u5668\u7dda\u8def\u5716<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-11111\">\u8d85\u97f3\u6ce2\u8ddd\u96e2\u6e2c\u91cf\u7a0b\u5f0f\u8aaa\u660e<\/h3>\n\n\n\n<p>\u9664\u4e86VCC\u3001GND\u4e4b\u5916\uff0c\u6211\u5011\u5c07Trig\u63a5\u5728GPIO12\uff08\u9eb5\u5305\u7248\u5de6\u50747\uff09\uff0c\u800cEcho\u63a5\u5728GPIO14\uff08\u9eb5\u5305\u7248\u5de6\u50748\uff09\uff0c\u7a0b\u5f0f\u7684\u6982\u5ff5\u5247\u662f\u5728Trig\u767c\u51fa\u4e00\u5c0f\u6bb5\u97f3\u6ce2\u5f8c\uff0c\u5c31\u5728Echo\u7b49\u5019\u56de\u97f3\u56de\u50b3\uff0c\u82e5\u6536\u5230\u56de\u97f3\uff0c\u5247Echo\u8173\u4f4d\u6703\u767c\u51fa\u9ad8\u96fb\u4f4d\uff0c\u56e0\u6b64\u6211\u5011\u6e2c\u91cfEcho\u8f49\u6210\u9ad8\u96fb\u4f4d\u7684\u6642\u9593\uff0c\u6700\u5f8c\u518d\u5229\u7528\u516c\u5f0f\u63db\u7b97\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u672c\u6848\u4f8b\u6709\u5169\u500b\u65b0\u7684\u8a9e\u6cd5\uff0cdelayMicroseconds\u53capulseIn\uff0c\u5206\u5225\u4ecb\u7d39\u5982\u4e0b\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"htoc-1-n-delaymicroseconds-n\">1. \u66ab\u505cn\u5fae\u79d2\uff1adelayMicroseconds(n);<\/h4>\n\n\n\n<p>\u4e4b\u524d\u6211\u5011\u5e38\u7528\u7684\u66ab\u505c\u662fdelay(1000)\uff0c\u5728delay\u5167\u7684\u6578\u5b57\u662f\u6beb\u79d2ms(MilliSeconds)\uff0c\u4e5f\u5c31\u662f1\/1000\u79d2\uff0c\u56e0\u6b64delay(1000)\u662f\u66ab\u505c1\u79d2\uff0c\u4f46\u662f\u82e5\u6211\u5011\u9700\u8981\u66ab\u505c\u6642\u9593\u6bd41\/1000\u9084\u5c0f\u6642\uff0c\u5c31\u8981\u6539\u7528delayMicroseconds(n)\uff0c\u800c\u5167\u90e8\u6578\u5b57n\u4ee3\u8868\u7684\u662f\u5fae\u79d2\uff08\u767e\u842c\u5206\u4e4b\u4e00\u79d2\uff09\uff0c\u901a\u5e38\u7528\u4f86\u9032\u884c\u66f4\u7cbe\u78ba\u6e2c\u91cf\uff0c\u4f8b\u5982\u672c\u6b21\u4f7f\u7528\u8d85\u97f3\u6ce2\u6e2c\u8ddd\uff0c\u5e38\u6eab\u4e0b\u97f3\u901f\u6bcf\u79d2\u7d04340\u516c\u5c3a\uff0c\u82e5\u4f7f\u75281\/1000\u79d2\uff0c\u8aa4\u5dee\u5c07\u6703\u8d85\u904e30cm\uff0c\u56e0\u6b64\u9808\u6539\u7528\u767e\u842c\u5206\u4e4b\u4e00\u79d2\u70ba\u55ae\u4f4d\u9032\u884c\u6e2c\u91cf\u3002\u7bc4\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delayMicroseconds(5);\/\/\u66ab\u505c\u767e\u842c\u5206\u4e4b5\u79d2=5\u5fae\u79d2<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"htoc-2-pulsein\">2. \u8a08\u7b97\u8173\u4f4d\u7684\u6536\u5230\u7b26\u5408\u96fb\u58d3\u7684\u6642\u9593\u5dee\uff1apulseIn(\u8173\u4f4d,\u96fb\u58d3);<\/h4>\n\n\n\n<p>pulseIn\u5c31\u662f\u7528\u4f86\u8a08\u7b97\u6642\u9593\uff0c\u4f8b\u5982\u8aaa\u7576\u7a0b\u5f0f\u57f7\u884c\u5230pulseIn(14, HIGH);\u6642\uff0c\u4ee3\u8868\u6211\u5011\u8981\u8a62\u554f14\u865f\u8173\u4f4d\u4f55\u6642\u6536\u5230\u9ad8\u96fb\u4f4d\uff0c\u4ee5\u672c\u4f8b\u800c\u8a00\uff0c\u7576\u8d85\u97f3\u6ce2\u6a21\u7d44\u6536\u5230\u56de\u97f3\u6642\uff0c\u5c31\u6703\u5c07Echo\u8f49HIGH\uff0c\u56e0\u6b64\u6211\u5011\u5229\u7528\u9019\u500b\u8a9e\u6cd5\uff0c\u5c31\u53ef\u4ee5\u6c42\u5f97\u6536\u5230\u56de\u97f3\u7684\u6642\u9593\uff0c\u6b64\u8a9e\u6cd5\u6240\u53d6\u5f97\u7684\u6642\u9593\u503c\u55ae\u4f4d\u70ba\u5fae\u79d2\u3002\u7bc4\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EchoTime=pulseIn(14, HIGH);\/\/\u8a08\u7b9714\u865f\u8173\u4f4d\u6536\u5230\u9ad8\u96fb\u4f4d\u7684\u6642\u9593<\/code><\/pre>\n\n\n\n<p>\u4e86\u89e3\u672c\u6b21\u7684\u5169\u500b\u65b0\u7a0b\u5f0f\u8a9e\u6cd5\u5f8c\uff0c\u6211\u5011\u5c07\u7a0b\u5f0f\u5b8c\u6210\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int Trig =12;\/\/\u767c\u51fa\u8072\u6ce2\n\nint Echo =14;\/\/\u63a5\u6536\u8072\u6ce2\n\nvoid setup(){\n\n  Serial.begin(115200);\n\n  pinMode(Trig, OUTPUT);\n\n  pinMode(Echo, INPUT);\n\n}\n\n \n\nvoid loop() {\n\n  digitalWrite(Trig, LOW); \/\/\u95dc\u9589\n\n  delayMicroseconds(5);\n\n  digitalWrite(Trig, HIGH);\/\/\u555f\u52d5\n\n  delayMicroseconds(10); \n\n  digitalWrite(Trig, LOW); \/\/\u95dc\u9589\n\n  float EchoTime = pulseIn(Echo, HIGH); \/\/\u50b3\u56de\u6642\u9593\n\n  float CMValue = EchoTime * 34 \/ 1000 \/ 2; \/\/\u8f49\u63db\u6210\u8ddd\u96e2\n\n  Serial.println(CMValue);\n\n  delay(50);\n\n}\n\n <\/code><\/pre>\n\n\n\n<p>\u5728loop\u5167\uff0c\u6211\u5011\u5148\u5c07trig\u95dc\u95895\u5fae\u79d2\uff0c\u7136\u5f8c\u958b\u555f10\u5fae\u79d2\uff0c\u4e4b\u5f8c\u5c31\u7acb\u5373\u95dc\u9589\uff0c\u9019\u500b\u300c\u95dc\u3001\u958b\u3001\u95dc\u300d\u7684\u6b65\u9a5f\u7684\u76ee\u7684\u8b93\u8d85\u97f3\u6ce2\u6a21\u7d44\u521d\u59cb\u5316\u907f\u514d\u53d7\u5230\u5e72\u64fe\uff0c\u5b8c\u6210\u5f8c\u4e4b\u5f8c\u4fbf\u6703\u767c\u51fa\u4e00\u6bb5\u8d85\u97f3\u6ce2\uff0c\u63a5\u4e0b\u4f86\u5c31\u662f\u5229\u7528pulseIn\u8a08\u7b97\u6536\u5230\u56de\u97f3\u7684\u6642\u9593\uff0c\u6700\u5f8c\u518d\u5229\u7528\u516c\u5f0f\u5c07\u6642\u9593\u8f49\u63db\u7a0b\u8ddd\u96e2\u5373\u53ef\u3002<\/p>\n\n\n\n<p>CMValue = EchoTime * 34 \/ 1000 \/ 2<\/p>\n\n\n\n<p>\u9019\u88e1\u7684\u516c\u5f0f\u5167\u7684&#8221;34&#8243;\u662f\u8f49\u63db\u6210\u6bcf1\/1000\u79d2\uff0c\u97f3\u901f\u80fd\u8dd1\u7d0434\u516c\u5206\uff0c\u800c\u96641000\u5247\u662f\u5c07\u767e\u842c\u5206\u4e4b\u4e00\u79d2\u8f49\u62101\/1000\u79d2\uff0c\u6700\u5f8c\u518d\u96642\u5247\u662f\u56e0\u70ba\u8072\u97f3\u53bb\u4e00\u6b21\u3001\u56de\u4e00\u6b21\u82b1\u4e86\u5169\u500d\u8ddd\u96e2\uff0c\u96642\u5c31\u53ef\u4ee5\u5f97\u5230\u771f\u5be6\u7684\u8ddd\u96e2\u3002<\/p>\n\n\n\n<p>\u4e0b\u5716\u70ba\u672c\u6b21\u8a08\u7b97\u7684\u7d50\u679c\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u7528\u624b\u653e\u5728\u8d85\u97f3\u6ce2\u6a21\u7d44\u7684\u524d\u65b9\uff0c\u4e26\u524d\u5f8c\u79fb\u52d5\u4f86\u89c0\u6e2c\u6240\u7372\u5f97\u7684\u8ddd\u96e2\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1602866735-1819931836-g.png?resize=839%2C719&#038;ssl=1\" alt=\"\" width=\"839\" height=\"719\"\/><figcaption class=\"wp-element-caption\">\u8d85\u97f3\u6ce2\u6a21\u7d44\u6e2c\u8ddd\u986f\u793a\u7d50\u679c<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-111111\">\u4e8c\u3001\u5012\u8eca\u96f7\u9054<\/h2>\n\n\n\n<p>\u8981\u5b8c\u6210\u5012\u8eca\u96f7\u9054\u5c31\u5fc5\u9808\u518d\u5b89\u88dd\u4e00\u500b\u65b0\u7684\u611f\u6e2c\u5668\uff0c\u5c31\u662f\u8702\u9cf4\u5668Buzzer\uff0c\u8702\u9cf4\u5668\u5728\u6211\u5011\u65e5\u5e38\u751f\u6d3b\u4e2d\u5f88\u5e38\u898b\uff0c\u4f8b\u5982\u96fb\u8166\u958b\u6a5f\u6642\u6703\u55f6\u4e00\u8072\uff0c\u6216\u8005\u706b\u707d\u6642\u8d85\u7d1a\u5927\u8072\u7684\u8b66\u5831\u4e5f\u662f\u4e00\u7a2e\u8702\u9cf4\u5668\uff0c\u76ee\u524d\u5e02\u9762\u4e0a\u5be6\u9a57\u7528\u7684\u8702\u9cf4\u5668\u53ef\u5206\u6210\u5169\u7a2e\u7121\u6e90\u8702\u9cf4\u5668\u53ca\u6709\u6e90\u8702\u9cf4\u5668\uff0c\u5169\u8005\u7684\u4e3b\u8981\u5dee\u7570\u5728\u65bc\u767c\u51fa\u8072\u97f3\u7684\u7d50\u69cb\u4e0d\u540c\uff0c\u6b64\u8655\u6240\u8b02\u7684\u7121\u300c\u6e90\u300d\u6216\u6709\u300c\u6e90\u300d\u7684\u6e90\u662f\u6307\u300c\u96fb\u6e90\u300d\u7684\u610f\u601d\uff0c\u7121\u6e90\u8702\u9cf4\u5668\u662f\u5229\u7528\u4f9b\u96fb\u7684\u983b\u7387\uff08PWM\uff09\u4f86\u6539\u8b8a\u8702\u9cf4\u5668\u7684\u8072\u97f3\uff0c\u56e0\u70ba\u4e0d\u9808\u63a5VCC\uff0c\u56e0\u6b64\u88ab\u7a31\u70ba\u7121\u6e90\uff0c\u53e6\u4e00\u7a2e\u6709\u6e90\u8702\u9cf4\u5668\u5247\u662f\u63a5\u4e0aVCC\u5c31\u6703\u53eb\uff0c\u8072\u97f3\u983b\u7387\u662f\u56fa\u5b9a\u7684\uff0c\u5169\u7a2e\u5404\u6709\u7528\u9014\uff0c\u800c\u672c\u4f8b\u5247\u662f\u63a1\u7528\u7121\u6e90\u8702\u9cf4\u5668\u3002<\/p>\n\n\n\n<p>\u6709\u6e90\u53ca\u7121\u6e90\u8702\u9cf4\u5668\u5169\u8005\u5916\u89c0\u4e0a\u6c92\u6709\u5dee\u7570\uff0c\u56e0\u6b64\u8cfc\u8cb7\u524d\u8acb\u8ddf\u8ce3\u5bb6\u78ba\u8a8d\u898f\u683c\uff0c\u907f\u514d\u8cb7\u932f\u6750\u6599\u3002\u5176\u5916\u89c0\u5982\u4e0b\u5716\uff0c\u4e00\u822c\u4e0a\u65b9\u53ef\u80fd\u6703\u6709\u4e00\u5f35\u8cbc\u7d19\uff0c\u8a18\u5f97\u5be6\u9a57\u524d\u5148\u7528\u7b46\u6233\u7834\u4e2d\u9593\u7684\u6d1e\u5373\u53ef\uff0c\u82e5\u5b8c\u5168\u6495\u958b\u53ef\u80fd\u6703\u5728\u767c\u4f4e\u97f3\u6642\u7834\u97f3\uff0c\u8702\u9cf4\u5668\u6709\u5169\u96bb\u8173\uff0c\u6709\u4e9b\u8702\u9cf4\u5668\u6703\u900f\u904e\u9577\u77ed\u8173\u4f86\u5340\u5206\u6b63\u8ca0\u6975\uff08\u9577\u6b63\u77ed\u8ca0\uff09\uff0c\u5982\u679c\u60a8\u6240\u8cfc\u8cb7\u7684\u6c92\u6709\u5206\u9577\u77ed\u8173\uff0c\u53ef\u89c0\u5bdf\u6b63\u9762\u6703\u6a19\u793a+\u7684\u7b26\u865f\uff0c\u4e5f\u53ef\u5340\u5206\u6b63\u8ca0\u6975\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1602866752-379166558-g.png?resize=495%2C212&#038;ssl=1\" alt=\"\" width=\"495\" height=\"212\"\/><figcaption class=\"wp-element-caption\">\u7121\u6e90\u8702\u9cf4\u5668\u5916\u89c0<\/figcaption><\/figure>\n\n\n\n<p>\u8981\u63a7\u5236\u8702\u9cf4\u5668\u767c\u51fa\u7684\u8072\u97f3\u5c31\u8981\u4f7f\u7528\u5230\u53e6\u5916\u4e00\u500b\u7a0b\u5f0f\u5eab\uff1aESP32Servo\uff0c\u9019\u4e5f\u662f\u4e00\u500b\u63a7\u5236PWM\u7684\u5de5\u5177\uff0c\u9664\u4e86\u8981\u7528\u4f86\u63a7\u5236\u8702\u9cf4\u5668\u4e4b\u5916\uff0c\u5f8c\u7e8c\u6211\u5011\u4e5f\u6703\u4f7f\u7528\u4ed6\u63a7\u5236\u4f3a\u670d\u99ac\u9054Servo\u4f86\u6a21\u64ec\u958b\u9580\uff0c\u8acb\u9078\u64c7\u4e0a\u65b9\u529f\u80fd\u8868\/\u8349\u7a3f\u78bc\/\u532f\u5165\u7a0b\u5f0f\u5eab\/\u7ba1\u7406\u7a0b\u5f0f\u5eab\uff0c\u958b\u555f\u7a0b\u5f0f\u5eab\u7ba1\u7406\u54e1\u5982\u4e0b\u5716\uff0c\u5728\u4e0a\u65b9\u95dc\u9375\u5b57\u8655\u8f38\u51fa&#8221;ESP32Servo&#8221;\uff0c\u4fbf\u53ef\u627e\u5230\u672c\u7a0b\u5f0f\u5eab\uff0c\u9ede\u9078\u4e0b\u65b9\u7684\u5b89\u88dd\u5f8c\uff0c\u7b49\u5019\u7d04\u4e00\u5206\u9418\u5373\u53ef\u5b8c\u6210\u5b89\u88dd\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1602866762-2127115824-g.png?resize=840%2C474&#038;ssl=1\" alt=\"\" width=\"840\" height=\"474\"\/><figcaption class=\"wp-element-caption\">\u7a0b\u5f0f\u5eab\u7ba1\u7406\u54e1\u5b89\u88ddESP32Servo\u7a0b\u5f0f\u5eab<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-1111111\">\u7121\u6e90\u8702\u9cf4\u5668\u7a0b\u5f0f\u8aaa\u660e<\/h3>\n\n\n\n<p>\u7a0b\u5f0f\u5eab\u5b89\u88dd\u5b8c\u7562\u5f8c\uff0c\u6211\u5011\u5148\u5beb\u4e00\u500b\u7c21\u55ae\u80fd\u767c\u51fa\u300c\u5c0f\u871c\u8702\u300d\u97f3\u6a02\u7684\u7a0b\u5f0f\u9032\u884c\u8072\u97f3\u6e2c\u8a66\uff0c\u5728ESP32Servo\u4e2d\uff0c\u63a7\u5236\u8702\u9cf4\u5668\u7684\u8a9e\u6cd5\u662ftone\uff0c\u8aaa\u660e\u5982\u4e0b<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"htoc-1-tone-pin-frequency-ms\">1. \u767c\u51fa\u4e00\u6bb5\u6642\u9593\u7684\u8072\u97f3\uff1atone(pin, frequency, ms);<\/h4>\n\n\n\n<p>tone\u8a9e\u6cd5\u4e00\u5171\u6709\u4e09\u500b\u53c3\u6578\uff0c\u7b2c\u4e00\u500b\u662f\u8173\u4f4dpin\uff0c\u5c31\u662f\u6307\u8702\u9cf4\u5668\u63a5\u5728ESP32\u7684\u54ea\u4e00\u500b\u8173\u4f4d\uff0c\u7b2c\u4e8c\u500b\u53c3\u6578\u662ffrequency\uff0c\u5247\u4ee3\u8868\u767c\u51fa\u67d0\u500b\u983b\u7387\u7684\u8072\u97f3\uff0c\u4e00\u822c\u6211\u5011\u6703\u7528\u97f3\u6a02\u7684\u97f3\u968eDo Re Mi\u4f86\u4ee3\u8868\uff0c\u95dc\u65bc\u97f3\u968e\u8207\u983b\u7387\u4e4b\u9593\u7684\u8b8a\u63db\uff0c\u53ef\u53c3\u8003\u4e0b\u8868\uff0c\u4f8b\u5982\u4e2d\u97f3Do\u983b\u7387\u5c31\u662f262\uff0cRe\u5c31\u662f294\uff0c\u800cMe\u5247\u662f330\uff0c\u56e0\u6b64\u767c\u51faDo, Re, Mi\u5404\u534a\u79d2\u9418\uff0c\u5176\u7a0b\u5f0f\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tone(pin, 262, 500);\/\/\u767c\u51faDo\n\ntone(pin, 294, 500);\/\/\u767c\u51faRe\n\ntone(pin, 330, 500);\/\/\u767c\u51faMe<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"htoc-2\">2. \u983b\u7387\u97f3\u968e\u5c0d\u7167\u8868<\/h4>\n\n\n\n<figure class=\"wp-block-flexible-table-block-table is-style-default\"><table class=\"has-fixed-layout is-sticky-first-column\" style=\"border-color:#000000;border-style:solid\"><thead><tr><th style=\"vertical-align:middle;text-align:center;border-style:solid;border-color:#000000;border-width:1px;background-color:transparent\">\u97f3\u540d<\/th><th style=\"text-align:center;vertical-align:middle;border-width:1px;background-color:transparent\">C<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">C#<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">D<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">D#<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">E<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">F<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">F#<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">G<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">G#<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">A<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">A#<\/th><th style=\"text-align:center;border-width:1px;background-color:transparent\">B<\/th><\/tr><\/thead><tbody><tr><td style=\"vertical-align:middle;text-align:center;border-style:solid;border-color:#000000;background-color:transparent;border-width:1px\"><strong>\u97f3\u968e<\/strong><\/td><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">Do<\/td><td style=\"text-align:center\"><\/td><td style=\"text-align:center\">Re<\/td><td style=\"text-align:center\"><\/td><td style=\"text-align:center\">Mi<\/td><td style=\"text-align:center\">Fa<\/td><td style=\"text-align:center\"><\/td><td style=\"text-align:center\">So<\/td><td style=\"text-align:center\"><\/td><td style=\"text-align:center\">La<\/td><td style=\"text-align:center\"><\/td><td style=\"text-align:center\">Si<\/td><\/tr><tr><td rowspan=\"2\" style=\"vertical-align:middle;text-align:center;border-style:solid;border-color:#000000;background-color:transparent;border-width:1px\"><strong>\u4f4e\u97f3<\/strong><\/td><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">33<\/td><td style=\"text-align:center\">35<\/td><td style=\"text-align:center\">37<\/td><td style=\"text-align:center\">39<\/td><td style=\"text-align:center\">41<\/td><td style=\"text-align:center\">44<\/td><td style=\"text-align:center\">46<\/td><td style=\"text-align:center\">49<\/td><td style=\"text-align:center\">52<\/td><td style=\"text-align:center\">55<\/td><td style=\"text-align:center\">58<\/td><td style=\"text-align:center\">62<\/td><\/tr><tr><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">65<\/td><td style=\"text-align:center\">69<\/td><td style=\"text-align:center\">73<\/td><td style=\"text-align:center\">78<\/td><td style=\"text-align:center\">82<\/td><td style=\"text-align:center\">87<\/td><td style=\"text-align:center\">93<\/td><td style=\"text-align:center\">98<\/td><td style=\"text-align:center\">104<\/td><td style=\"text-align:center\">110<\/td><td style=\"text-align:center\">117<\/td><td style=\"text-align:center\">123<\/td><\/tr><tr><td rowspan=\"3\" style=\"vertical-align:middle;text-align:center;border-style:solid;border-color:#000000;background-color:transparent;border-width:1px\"><strong>\u4e2d\u97f3<\/strong><\/td><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">131<\/td><td style=\"text-align:center\">139<\/td><td style=\"text-align:center\">147<\/td><td style=\"text-align:center\">156<\/td><td style=\"text-align:center\">165<\/td><td style=\"text-align:center\">175<\/td><td style=\"text-align:center\">185<\/td><td style=\"text-align:center\">196<\/td><td style=\"text-align:center\">208<\/td><td style=\"text-align:center\">220<\/td><td style=\"text-align:center\">233<\/td><td style=\"text-align:center\">247<\/td><\/tr><tr><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">262<\/td><td style=\"text-align:center\">277<\/td><td style=\"text-align:center\">294<\/td><td style=\"text-align:center\">311<\/td><td style=\"text-align:center\">330<\/td><td style=\"text-align:center\">349<\/td><td style=\"text-align:center\">370<\/td><td style=\"text-align:center\">392<\/td><td style=\"text-align:center\">415<\/td><td style=\"text-align:center\">440<\/td><td style=\"text-align:center\">466<\/td><td style=\"text-align:center\">493<\/td><\/tr><tr><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">523<\/td><td style=\"text-align:center\">554<\/td><td style=\"text-align:center\">587<\/td><td style=\"text-align:center\">622<\/td><td style=\"text-align:center\">659<\/td><td style=\"text-align:center\">698<\/td><td style=\"text-align:center\">740<\/td><td style=\"text-align:center\">784<\/td><td style=\"text-align:center\">831<\/td><td style=\"text-align:center\">880<\/td><td style=\"text-align:center\">932<\/td><td style=\"text-align:center\">988<\/td><\/tr><tr><td rowspan=\"3\" style=\"vertical-align:middle;text-align:center;border-style:solid;border-color:#000000;background-color:transparent;border-width:1px\"><strong>\u9ad8\u97f3<\/strong><\/td><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">1046<\/td><td style=\"text-align:center\">1109<\/td><td style=\"text-align:center\">1175<\/td><td style=\"text-align:center\">1245<\/td><td style=\"text-align:center\">1319<\/td><td style=\"text-align:center\">1397<\/td><td style=\"text-align:center\">1480<\/td><td style=\"text-align:center\">1568<\/td><td style=\"text-align:center\">1661<\/td><td style=\"text-align:center\">1760<\/td><td style=\"text-align:center\">1864<\/td><td style=\"text-align:center\">1976<\/td><\/tr><tr><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">2093<\/td><td style=\"text-align:center\">2217<\/td><td style=\"text-align:center\">2349<\/td><td style=\"text-align:center\">2489<\/td><td style=\"text-align:center\">2637<\/td><td style=\"text-align:center\">2794<\/td><td style=\"text-align:center\">2960<\/td><td style=\"text-align:center\">3136<\/td><td style=\"text-align:center\">3322<\/td><td style=\"text-align:center\">3520<\/td><td style=\"text-align:center\">3729<\/td><td style=\"text-align:center\">3951<\/td><\/tr><tr><td style=\"text-align:center;vertical-align:middle;background-color:transparent\">4186<\/td><td style=\"text-align:center\">4435<\/td><td style=\"text-align:center\">4699<\/td><td style=\"text-align:center\">4978<\/td><td style=\"text-align:center\">5274<\/td><td style=\"text-align:center\">5588<\/td><td style=\"text-align:center\">5920<\/td><td style=\"text-align:center\">6272<\/td><td style=\"text-align:center\">6645<\/td><td style=\"text-align:center\">7040<\/td><td style=\"text-align:center\">7459<\/td><td style=\"text-align:center\">7902<\/td><\/tr><\/tbody><\/table><figcaption style=\"text-align:center\">\u983b\u7387\u97f3\u968e\u5c0d\u7167\u8868<\/figcaption><\/figure>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u63a5\u4e0b\u4f86\u6211\u5011\u5c07\u8702\u9cf4\u5668\u63a5\u4e0aESP32\uff0c\u6211\u5011\u5c07\u8702\u9cf4\u5668+\u8173\u63a5\u5728GPIO 17\uff0c\u4e5f\u5c31\u662f\u9eb5\u5305\u7248\u53f3\u5074\u7de8\u865f9\u7684\u4f4d\u7f6e\uff0c\u800c\u53e6\u5916\u4e00\u96bb\u8173\u5247\u63a5\u5728GND\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u6211\u5011\u5148\u900f\u904e\u4e00\u500b\u7c21\u55ae\u7bc4\u4f8b\uff0c\u767c\u51fa\u5c0f\u871c\u8702\u7684\u7b2c\u4e00\u6bb5\u4f86\u6aa2\u67e5\u8702\u9cf4\u5668\u662f\u5426\u6b63\u5e38\uff0c\u5c0f\u871c\u8702\u7684\u7b2c\u4e00\u6bb5\u70ba\uff1a<\/p>\n\n\n\n<p>\uff5cG E E -\uff5cF D D -\uff5cC D E F\uff5cG G G -\uff5c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;ESP32Servo.h&gt;\n\nint buzzer= 17;\n\nvoid setup() {\n\n  Serial.begin(115200);\n\n}\n\n \n\nvoid loop() {\n\n  tone(buzzer, 392, 500);\/\/G(So)\n\n  tone(buzzer, 330, 500);\/\/E(Me)\n\n  tone(buzzer, 330, 500);\/\/E(Me)\n\n  delay(500);\n\n  tone(buzzer, 349, 500);\/\/F(Fa)\n\n  tone(buzzer, 294, 500);\/\/D(Re)\n\n  tone(buzzer, 294, 500);\/\/D(Re)\n\n  delay(500);\n\n  tone(buzzer, 262, 500);\/\/C(Do)\n\n  tone(buzzer, 294, 500);\/\/D(Re)\n\n  tone(buzzer, 330, 500);\/\/E(Me)\n\n  tone(buzzer, 349, 500);\/\/F(Fa)\n\n  tone(buzzer, 392, 500);\/\/G(So)\n\n  tone(buzzer, 392, 500);\/\/G(So)\n\n  tone(buzzer, 392, 500);\/\/G(So)\n\n  delay(3000);\n\n}\n\n <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-11111111\">\u5012\u8eca\u96f7\u9054\u7a0b\u5f0f\u8aaa\u660e<\/h3>\n\n\n\n<p>\u4e0a\u8ff0\u7a0b\u5f0f\u6e2c\u8a66\u6210\u529f\u5f8c\uff0c\u6211\u5011\u5247\u4f86\u6574\u5408\u8d85\u97f3\u6ce2\u611f\u6e2c\u53ca\u8702\u9cf4\u5668\u4f86\u88fd\u4f5c\u5012\u8eca\u96f7\u9054\uff0c\u70ba\u4e86\u7c21\u5316\u5be6\u9a57\uff0c\u6211\u5011\u5c07\u8d85\u97f3\u6ce2\u6240\u6aa2\u6e2c\u7684\u8ddd\u96e2\u5206\u6210\u56db\u7a2e\u72c0\u614b<\/p>\n\n\n\n<p>\u5b89\u5168\uff1a100cm\u5167\u7121\u969c\u7919\u7269\uff0c\u4e0d\u767c\u51fa\u8072\u97f3<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u8ddd\u96e2100~50cm\u4e4b\u9593\uff0c\u767c\u51fa\u4f4e\u97f3Do\u63d0\u9192\u4f7f\u7528\u8005<\/p>\n\n\n\n<p>\u5c0f\u5fc3\uff1a\u8ddd\u96e250~10cm\u4e4b\u9593\uff0c\u767c\u51fa\u4e2d\u97f3Do\u63d0\u9192\u4f7f\u7528\u8005<\/p>\n\n\n\n<p>\u5371\u96aa\uff1a\u8ddd\u96e210\uff5e0cm\u4e4b\u9593\uff0c\u767c\u51fa\u9ad8\u97f3Do\u63d0\u9192\u4f7f\u7528\u8005<\/p>\n\n\n\n<p>\u900f\u904e\u6539\u8b8a\u8072\u8abf\u4f86\u63d0\u9192\u4f7f\u7528\u8005\uff0c\u97f3\u8abf\u8d8a\u9ad8\u4ee3\u8868\u969c\u7919\u7269\u8d8a\u63a5\u8fd1\uff0c\u53ef\u907f\u514d\u649e\u5230\u9020\u6210\u9020\u6210\u640d\u5931\u3002\u672c\u90e8\u4efd\u7684\u7a0b\u5f0f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;ESP32Servo.h&gt;\n\nint Trig = 12; \/\/\u767c\u51fa\u8072\u6ce2\n\nint Echo = 14; \/\/\u63a5\u6536\u8072\u6ce2\n\nint buzzer = 17;\/\/\u8702\u9cf4\u5668\n\nvoid setup() {\n\n  Serial.begin(115200);\n\n  pinMode(Trig, OUTPUT);\n\n  pinMode(Echo, INPUT);\n\n  pinMode(buzzer, OUTPUT);\n\n}\n\n \n\nvoid loop() {\n\n  \/\/\u6b65\u9a5f1\uff1a\u4f7f\u7528\u8d85\u97f3\u6ce2\u6e2c\u91cf\u8ddd\u96e2\n\n  digitalWrite(Trig, LOW); \/\/\u95dc\u9589\n\n  delayMicroseconds(5);\n\n  digitalWrite(Trig, HIGH);\/\/\u555f\u52d5\n\n  delayMicroseconds(10);\n\n  digitalWrite(Trig, LOW); \/\/\u95dc\u9589\n\n  float EchoTime = pulseIn(Echo, HIGH); \/\/\u50b3\u56de\u6642\u9593\n\n  float CMValue = EchoTime * 34 \/ 1000 \/ 2; \/\/\u8f49\u63db\u6210\u8ddd\u96e2\n\n  Serial.println(CMValue);\n\n  \/\/\u6b65\u9a5f2\uff1a\u4f7f\u7528\u8702\u9cf4\u5668\u767c\u51fa\u6307\u5b9a\u8072\u97f3\n\n  if (CMValue &lt; 100 &amp;&amp; CMValue &gt;= 50) {\n\n    tone(buzzer, 33, 100); \/\/\u6ce8\u610f\uff1a\u767c\u51fa\u4f4e\u97f3Do\n\n  }\n\n  if (CMValue &lt; 50 &amp;&amp; CMValue &gt;= 10) {\n\n    tone(buzzer, 523, 100); \/\/\u5c0f\u5fc3\uff1a\u767c\u51fa\u4e2d\u97f3Do\n\n  }\n\n  if (CMValue &lt; 10) {\n\n    tone(buzzer, 4186, 100); \/\/\u5371\u96aa\uff1a\u767c\u51fa\u9ad8\u97f3Do\n\n  }\n\n  delay(50);\n\n}\n\n <\/code><\/pre>\n\n\n\n<p>\u9664\u4e86\u6539\u8b8a\u9ad8\u4f4e\u97f3\u8abf\u63d0\u9192\u4f7f\u7528\u8005\u4e4b\u5916\uff0c\u4e5f\u53ef\u4ee5\u5229\u7528\u8ddd\u96e2\u6539\u8b8a\u767c\u51fa\u8072\u97f3\u7684\u9593\u9694\uff0c\u4f8b\u5982\u8ddd\u96e2\u6bd4\u8f03\u9060\u6642\u5c31\u6bcf\u6b21\u55f6\u8072\u4e4b\u9593\u9593\u9694\u8f03\u4e45\uff0c\u800c\u5f88\u63a5\u8fd1\u6642\uff0c\u767c\u51fa\u7684\u55f6\u8072\u97f3\u8f03\u70ba\u7dca\u6e4a\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p>tone(buzzer, 4186, CMValue);<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u767c\u51fa\u7684\u8072\u97f3\u9593\u9694\u525b\u597d\u662f\u8ddd\u96e2\uff0c\u6b64\u6642\u5f88\u9760\u8fd1\u6642\u5c31\u53ef\u4ee5\u767c\u51fa\u5e7e\u4e4e\u9023\u7e8c\u7684\u55f6\u8072\uff0c\u9019\u4e5f\u662f\u53e6\u5916\u4e00\u7a2e\u5e38\u898b\u7684\u65b9\u5f0f\u3002<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"htoc-111111111\" style=\"font-size:clamp(16.293px, 1.018rem + ((1vw - 3.2px) * 0.68), 25px);\">\u5ef6\u4f38\u95b1\u8b80<\/h5>\n\n\n\n<p class=\"has-background has-medium-font-size\" style=\"background-color:#f2f2f2\">????   <a href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/17\/esp32_ch1-6\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u7b2c\u4e5d\u7bc7 ESP32 \u6eab\u6fd5\u5ea6\u986f\u793a\u5668(DHT11+1602 LCD)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728\u7684\u6c7d\u8eca\u5927\u90e8\u5206\u90fd\u6709\u914d\u5099\u5012\u8eca\u96f7\u9054\uff0c\u5c31\u662f\u5012\u8eca\u6642\uff0c\u6703\u4f9d\u64da\u8eca\u5b50\u8207\u969c\u7919\u7269\u4e4b\u9593\u7684\u8ddd\u96e2\u767c\u51fa\u4e0d\u540c\u983b\u7387\u7684\u55f6\u55f6\u8072\uff0c\u7528\u4f86\u6307\u5f15\u99d5\u99db\u907f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,29],"tags":[],"class_list":["post-601","post","type-post","status-publish","format-standard","hentry","category-esp32","category-esp32-started"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=601"}],"version-history":[{"count":6,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/601\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/601\/revisions\/926"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}