http://m.gharee.com/wiki/index.php?action=history&feed=atom&title=%28SKU%3ARB-02S041%29%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89 123,123 2025-07-03T15:25:52Z 本wiki的該頁面的版本歷史 MediaWiki 1.21.2 http://m.gharee.com/wiki/index.php?title=(SKU:RB-02S041)%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89&diff=4618&oldid=prev Arduino77:/* 使用方法 */ 2015-12-29T08:35:51Z <p>?<span dir="auto"><span class="autocomment">使用方法</span></span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">←上一版本</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">2015年12月29日 (二) 08:35的版本</td> </tr><tr><td colspan="2" class="diff-lineno">第26行:</td> <td colspan="2" class="diff-lineno">第26行:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Vcc:電源正極</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Vcc:電源正極</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==使用方法==</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==使用方法==</div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">===工作原理===</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">通過紅外線的反射原理,從發(fā)射到接收到回傳信號,傳感器共引出三個引腳分別接,信號線S、電源地G、電源正VCC,將信號線與 Arduino 板的 Analog IN 引腳相連接。通過對Arduino編程實現(xiàn)模擬量讀取,程序簡短好用。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">===性能簡評===</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">GP2D12使用性能個人簡評:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">優(yōu)點:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 紅外傳感器連接使用簡單,對于1米以內(nèi)的中距離測試精度良好、性能優(yōu)越。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 數(shù)據(jù)測量值穩(wěn)定,測量結(jié)果波動較小。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 數(shù)據(jù)傳輸穩(wěn)定,程序讀取簡單不會在數(shù)據(jù)傳輸過程中出現(xiàn)卡死的現(xiàn)象,錯誤信號較少。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">缺陷:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* GP2d12測量范圍有限,最大值80cm,并且從60cm開外的距離開始測量值的波動較大,與實際情況偏差增大。(60cm為室內(nèi)環(huán)境的個人感受,不同環(huán)境所產(chǎn)生的干擾不同所以可能達(dá)到的精度也有所不同。)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 當(dāng)障礙物(或目標(biāo))與紅外傳感器之間的距離小于10cm時,測量值將與實際值出現(xiàn)明顯偏差,當(dāng)距離值從10降至0的過程中,測量值將在10~35之間遞增。(電壓值與距離值關(guān)系:如圖)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 紅外傳感器,使用時會受到環(huán)境光的影響,在室內(nèi)使用時,傳感器數(shù)據(jù)接收時可能會受到白熾燈光線的印象,產(chǎn)生一些非真的距離值。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">GP2D12使用注意及使用優(yōu)化方式:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 當(dāng)多個GP2d12同時連接Arduino板使用時,由于供電量的增加,可能造成電壓不穩(wěn)定而對測量結(jié)果產(chǎn)生偏差。從硬件角度可以通過在VCC與 GND之間接電容的方式來穩(wěn)定對GP2d12的供電,減少供電電壓波動對測量結(jié)果的影響,或者在GND與數(shù)據(jù)線之間接一個電容減小輸出電壓的波動略去可能出現(xiàn)的誤差信號,提高數(shù)據(jù)穩(wěn)定性。(接線見附錄圖)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 針對測量時可能產(chǎn)生的干擾和誤差數(shù)值,可能從軟件的角度進(jìn)行改進(jìn)和防止,通過多次的測量記錄,排除一場輸入量后,取均值來的到一個較為穩(wěn)定更為接近實際值的測量數(shù)據(jù)。其次可以根據(jù)實際的使用要求,可以進(jìn)行有效值的范圍定義,過濾超出范圍的測量結(jié)果,該范圍可根據(jù)使用情況自行界定。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* 針對紅外傳感器測量時,可能受環(huán)境光影響測量結(jié)果,在安放使用時竟可能避免傳感器正對燈光的使用,可以將 GP2d12的發(fā)射接收端水平放置進(jìn)行測量,盡可能減少環(huán)境光帶來的干擾。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">總體來說:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">* GP2d12在對測量精度要求不高,測量范圍在1m以內(nèi)的情況下,對物體距離值的定位是非常簡單有效地、操作簡便、實用性強。</ins></div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===接線方法===</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===接線方法===</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>將傳感器連接到UNO控制器模擬口A1上,注意對應(yīng)線序:一般情況下3P線黃色接信號,紅色接電源正,黑色接電源負(fù)</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>將傳感器連接到UNO控制器模擬口A1上,注意對應(yīng)線序:一般情況下3P線黃色接信號,紅色接電源正,黑色接電源負(fù)</div></td></tr> </table> Arduino77 http://m.gharee.com/wiki/index.php?title=(SKU:RB-02S041)%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89&diff=4617&oldid=prev Arduino77:/* 使用方法 */ 2015-12-29T08:16:23Z <p>?<span dir="auto"><span class="autocomment">使用方法</span></span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">←上一版本</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">2015年12月29日 (二) 08:16的版本</td> </tr><tr><td colspan="2" class="diff-lineno">第26行:</td> <td colspan="2" class="diff-lineno">第26行:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Vcc:電源正極</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Vcc:電源正極</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==使用方法==</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==使用方法==</div></td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>===<del class="diffchange diffchange-inline">例程1</del>===</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===<ins class="diffchange diffchange-inline">接線方法===</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">將傳感器連接到UNO控制器模擬口A1上,注意對應(yīng)線序:一般情況下3P線黃色接信號,紅色接電源正,黑色接電源負(fù)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">===例子程序===</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&lt;pre style=&quot;color:blue&quot;&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">#define pin A0</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">void setup () </ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">{</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; Serial.begin (9600);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; pinMode (pin, INPUT);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">}</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">void loop () </ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">{</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; uint16_t value = analogRead (pin);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; uint16_t range = get_gp2d12 (value);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; Serial.println (value);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; Serial.print (range);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; Serial.println (&quot; mm&quot;);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; Serial.println ();</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; delay (500);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">}</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>&#160;</div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">//return distance (mm)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">uint16_t get_gp2d12 (uint16_t value) {</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; if (value &lt; 30)</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; value = 30;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&#160; &#160; &#160; &#160; return ((67870.0 / (value - 3.0)) - 40.0);</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">}</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">&lt;/pre&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">===程序效果===</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">打開 Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測試到的距離。</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">[[文件:02S04110.png|500px|有框|居中]]</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">===應(yīng)用例程</ins>===</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>====連接示意圖====</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>====連接示意圖====</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0414.jpg|700px|縮略圖|居中]]</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0414.jpg|700px|縮略圖|居中]]</div></td></tr> <tr><td colspan="2" class="diff-lineno">第87行:</td> <td colspan="2" class="diff-lineno">第118行:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>當(dāng)舵機轉(zhuǎn)動到一個給定的位置時測定距離,將其轉(zhuǎn)換為LED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個位置,然后繼續(xù),如此重復(fù)。</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>當(dāng)舵機轉(zhuǎn)動到一個給定的位置時測定距離,將其轉(zhuǎn)換為LED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個位置,然后繼續(xù),如此重復(fù)。</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">===例程2===</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">====接線方法====</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">將傳感器連接到UNO控制器模擬口A1上,注意對應(yīng)線序:一般情況下3P線黃色接信號,紅色接電源正,黑色接電源負(fù)</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">====例子程序====</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&lt;pre style=&quot;color:blue&quot;&gt;</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">#define pin A0</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">void setup () </del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; Serial.begin (9600);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; pinMode (pin, INPUT);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">}</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">void loop () </del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; uint16_t value = analogRead (pin);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; uint16_t range = get_gp2d12 (value);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; Serial.println (value);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; Serial.print (range);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; Serial.println (&quot; mm&quot;);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; Serial.println ();</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; delay (500);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">}</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">//return distance (mm)</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">uint16_t get_gp2d12 (uint16_t value) {</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; if (value &lt; 30)</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; value = 30;</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&#160; &#160; &#160; &#160; return ((67870.0 / (value - 3.0)) - 40.0);</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">}</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">&lt;/pre&gt;</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">====程序效果====</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">打開 Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測試到的距離。</del></div></td><td colspan="2">&#160;</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==產(chǎn)品相關(guān)推薦==</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>==產(chǎn)品相關(guān)推薦==</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:erweima.png|230px|無框|右]]</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:erweima.png|230px|無框|右]]</div></td></tr> </table> Arduino77 http://m.gharee.com/wiki/index.php?title=(SKU:RB-02S041)%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89&diff=4616&oldid=prev Arduino77:/* 模擬信號與測量距離對應(yīng)表 */ 2015-12-29T08:06:00Z <p>?<span dir="auto"><span class="autocomment">模擬信號與測量距離對應(yīng)表</span></span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">←上一版本</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">2015年12月29日 (二) 08:06的版本</td> </tr><tr><td colspan="2" class="diff-lineno">第16行:</td> <td colspan="2" class="diff-lineno">第16行:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0412.jpg|700px|縮略圖|居中]]</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0412.jpg|700px|縮略圖|居中]]</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>上圖就是GP2D12紅外線測距傳感器的電壓值與距離值的關(guān)系曲線,從這個曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時有2.55V輸出,80cm距離時有0.42V輸出。可以通過該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個關(guān)系式里的距離是參考距離值,實際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實際距離與采樣數(shù)據(jù)之間的關(guān)系式為:&lt;br/&gt;</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>上圖就是GP2D12紅外線測距傳感器的電壓值與距離值的關(guān)系曲線,從這個曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時有2.55V輸出,80cm距離時有0.42V輸出??梢酝ㄟ^該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個關(guān)系式里的距離是參考距離值,實際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實際距離與采樣數(shù)據(jù)之間的關(guān)系式為:&lt;br/&gt;</div></td></tr> <tr><td class='diff-marker'>?</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">&#160; &#160; </del>實際距離=2547.8/((float)采樣數(shù)據(jù)*0.49-10.41)-0.42&lt;br/&gt;</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">'''&lt;big&gt;</ins>實際距離=2547.8/((float)采樣數(shù)據(jù)*0.49-10.41)-0.42<ins class="diffchange diffchange-inline">&lt;/big&gt;'''</ins>&lt;br/&gt;</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===信號輸出===</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===信號輸出===</div></td></tr> </table> Arduino77 http://m.gharee.com/wiki/index.php?title=(SKU:RB-02S041)%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89&diff=4615&oldid=prev Arduino77:/* 模擬信號與測量距離對應(yīng)表 */ 2015-12-29T08:05:29Z <p>?<span dir="auto"><span class="autocomment">模擬信號與測量距離對應(yīng)表</span></span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">←上一版本</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">2015年12月29日 (二) 08:05的版本</td> </tr><tr><td colspan="2" class="diff-lineno">第15行:</td> <td colspan="2" class="diff-lineno">第15行:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===模擬信號與測量距離對應(yīng)表===</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===模擬信號與測量距離對應(yīng)表===</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0412.jpg|700px|縮略圖|居中]]</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[文件:RB-02S0412.jpg|700px|縮略圖|居中]]</div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">上圖就是GP2D12紅外線測距傳感器的電壓值與距離值的關(guān)系曲線,從這個曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時有2.55V輸出,80cm距離時有0.42V輸出。可以通過該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個關(guān)系式里的距離是參考距離值,實際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實際距離與采樣數(shù)據(jù)之間的關(guān)系式為:&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">&#160; &#160; 實際距離=2547.8/((float)采樣數(shù)據(jù)*0.49-10.41)-0.42&lt;br/&gt;</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===信號輸出===</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>===信號輸出===</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>ADC0831可以將模擬信號轉(zhuǎn)為數(shù)字信號輸出</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>ADC0831可以將模擬信號轉(zhuǎn)為數(shù)字信號輸出</div></td></tr> </table> Arduino77 http://m.gharee.com/wiki/index.php?title=(SKU:RB-02S041)%E5%A4%8F%E6%99%AE_GP2D12_%E7%BA%A2%E5%A4%96%E6%B5%8B%E8%B7%9D%E4%BC%A0%E6%84%9F%E5%99%A8%EF%BC%8810cm_-_80cm%EF%BC%89&diff=4614&oldid=prev Arduino77:以“右 ==產(chǎn)品概述== GP2D12 IR Sensor 是日本夏普公司推出的一款性價比高、最常用的紅外測距傳感器...”為內(nèi)容創(chuàng)建頁面 2015-12-29T08:00:23Z <p>以“<a href="/wiki/index.php/%E6%96%87%E4%BB%B6:RB-02S041.jpg" title="文件:RB-02S041.jpg">右</a> ==產(chǎn)品概述== GP2D12 IR Sensor 是日本夏普公司推出的一款性價比高、最常用的紅外測距傳感器...”為內(nèi)容創(chuàng)建頁面</p> <p><b>新頁面</b></p><div>[[文件:RB-02S041.jpg|500px|縮略圖|右]]<br /> ==產(chǎn)品概述==<br /> GP2D12 IR Sensor 是日本夏普公司推出的一款性價比高、最常用的紅外測距傳感器、其可用來對物體的距離進(jìn)行測量,實現(xiàn)輪式機器人的避障功能。它不但體積小、功耗低、價格便宜,而且測距效果好,適合廣大機器人發(fā)燒友使用。<br /> ==規(guī)格參數(shù)==<br /> # 測量射程范圍:10 to 80 cm <br /> # 最大允許角度:&gt;40° <br /> # 電源電壓:4.5 to 5.5V <br /> # 平均功耗:35mA <br /> # 峰值功耗:約200mA <br /> # 更新頻率/周期:25Hz / 40ms <br /> # 模擬輸出噪聲:&lt;200mV <br /> # 測量距離與輸出模擬電壓關(guān)系:2.4V~0.4V模擬信號對應(yīng)10cm~80cm,輸出與距離成反比非線性關(guān)系<br /> ===產(chǎn)品尺寸圖===<br /> [[文件:RB-02S0411.jpg|700px|縮略圖|居中]]<br /> ===模擬信號與測量距離對應(yīng)表===<br /> [[文件:RB-02S0412.jpg|700px|縮略圖|居中]]<br /> ===信號輸出===<br /> ADC0831可以將模擬信號轉(zhuǎn)為數(shù)字信號輸出<br /> [[文件:RB-02S0413.jpg|700px|縮略圖|居中]]<br /> ==接口定義==<br /> * Vo:輸出引腳<br /> * GND:電源地<br /> * Vcc:電源正極<br /> ==使用方法==<br /> ===例程1===<br /> ====連接示意圖====<br /> [[文件:RB-02S0414.jpg|700px|縮略圖|居中]]<br /> 首先將距離傳感器固定到舵機上,可以使用熱熔膠或者膠帶。然后使用一個1uf電解電容和一個22uf電解電容并聯(lián)在5V穩(wěn)壓芯片L4940V5上。將紅外距離傳感器的信號線插入0號模擬引腳。4個LED通過1KΩ電阻插入3、5、6、11引腳。最后將舵機信號線接在9號引腳上。<br /> ====例子程序====<br /> &lt;pre style='color:blue'&gt;<br /> #include &lt;Servo.h&gt;<br /> const int SERVO =9; //伺服電機連接在9號引腳<br /> const int IR =0; //紅外距離傳感器連接在0號模擬引腳<br /> const int LED1 =3; //LED輸出1<br /> const int LED2 =5; //LED輸出2<br /> const int LED3 =6; //LED 輸出3<br /> const int LED4 =11; //LED 輸出4<br /> <br /> Servo myServo; //伺服電機對象<br /> int dist1 = 0; //第一象限距離<br /> int dist2 = 0; //第二象限距離<br /> int dist3 = 0; //第三象限距離<br /> int dist4 = 0; //第四象限距離<br /> <br /> void setup()<br /> {<br /> myServo.attach(SERVO); //綁定伺服電機<br /> pinMode(LED1, OUTPUT); //將LED設(shè)置為輸出<br /> pinMode(LED2, OUTPUT); //將LED設(shè)置為輸出<br /> pinMode(LED3, OUTPUT); //將LED設(shè)置為輸出<br /> pinMode(LED4, OUTPUT); //將LED設(shè)置為輸出<br /> }<br /> <br /> void loop()<br /> {<br /> //將伺服電機在4個區(qū)域中掃描并改變LED亮度<br /> dist1 = readDistance(15); //在15°處進(jìn)行紅外測距<br /> analogWrite(LED1, dist1); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測量前的延時<br /> <br /> dist2 = readDistance(65); //在65°處進(jìn)行紅外測距<br /> analogWrite(LED2, dist2); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測量前的延時<br /> <br /> dist3 = readDistance(115); //在115°處進(jìn)行紅外測距<br /> analogWrite(LED3, dist3); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測量前的延時<br /> <br /> dist4 = readDistance(165); //在165°處進(jìn)行紅外測距<br /> analogWrite(LED4, dist4); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測量前的延時<br /> }<br /> <br /> int readDistance(int pos)<br /> {<br /> myServo.write(pos); //轉(zhuǎn)動到指定位置<br /> delay(600); //等待伺服電機轉(zhuǎn)動<br /> int dist = analogRead(IR); //讀取紅外傳感器<br /> dist = map(dist, 50, 500, 0, 255); //轉(zhuǎn)換到LED的范圍內(nèi) <br /> dist = constrain(dist, 0, 255); //約束它<br /> return dist; //返回縮放后的距離<br /> }&lt;/pre&gt;<br /> ====程序效果====<br /> 當(dāng)舵機轉(zhuǎn)動到一個給定的位置時測定距離,將其轉(zhuǎn)換為LED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個位置,然后繼續(xù),如此重復(fù)。<br /> <br /> ===例程2===<br /> ====接線方法====<br /> 將傳感器連接到UNO控制器模擬口A1上,注意對應(yīng)線序:一般情況下3P線黃色接信號,紅色接電源正,黑色接電源負(fù)<br /> ====例子程序====<br /> &lt;pre style=&quot;color:blue&quot;&gt;<br /> #define pin A0<br /> void setup () <br /> {<br /> Serial.begin (9600);<br /> pinMode (pin, INPUT);<br /> }<br /> void loop () <br /> {<br /> uint16_t value = analogRead (pin);<br /> uint16_t range = get_gp2d12 (value);<br /> Serial.println (value);<br /> Serial.print (range);<br /> Serial.println (&quot; mm&quot;);<br /> Serial.println ();<br /> delay (500);<br /> }<br /> <br /> //return distance (mm)<br /> uint16_t get_gp2d12 (uint16_t value) {<br /> if (value &lt; 30)<br /> value = 30;<br /> return ((67870.0 / (value - 3.0)) - 40.0);<br /> }<br /> &lt;/pre&gt;<br /> ====程序效果====<br /> 打開 Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測試到的距離。<br /> ==產(chǎn)品相關(guān)推薦==<br /> [[文件:erweima.png|230px|無框|右]]<br /> ===產(chǎn)品購買地址===<br /> [http://m.gharee.com/goods-181.html 夏普GP2D12紅外測距傳感器]&lt;br/&gt;<br /> ===周邊產(chǎn)品推薦===<br /> [http://m.gharee.com/goods-183.html Arduino IR Sensor GP2Y0A02YK0F夏普紅外測距傳感器]&lt;br/&gt;<br /> ===相關(guān)問題解答===<br /> [http://www.makerspace.cn/forum.php?mod=viewthread&amp;tid=3851&amp;highlight=%E5%A4%8F%E6%99%AE 夏普紅外測距邊界問題]&lt;br/&gt;<br /> ===相關(guān)學(xué)習(xí)資料===<br /> [http://www.makerspace.cn/portal.php 奧松機器人技術(shù)論壇]&lt;br/&gt;</div> Arduino77