http://www.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-06-18T04:15:59Z 本wiki的該頁(yè)面的版本歷史 MediaWiki 1.21.2 http://www.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;">通過(guò)紅外線的反射原理,從發(fā)射到接收到回傳信號(hào),傳感器共引出三個(gè)引腳分別接,信號(hào)線S、電源地G、電源正VCC,將信號(hào)線與 Arduino 板的 Analog IN 引腳相連接。通過(guò)對(duì)Arduino編程實(shí)現(xiàn)模擬量讀取,程序簡(jiǎ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;">===性能簡(jiǎn)評(pí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 style="font-weight: bold; text-decoration: none;">GP2D12使用性能個(gè)人簡(jiǎn)評(píng):&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)點(diǎ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;">* 紅外傳感器連接使用簡(jiǎn)單,對(duì)于1米以?xún)?nèi)的中距離測(cè)試精度良好、性能優(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ù)測(cè)量值穩(wěn)定,測(cè)量結(jié)果波動(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 style="font-weight: bold; text-decoration: none;">* 數(shù)據(jù)傳輸穩(wěn)定,程序讀取簡(jiǎn)單不會(huì)在數(shù)據(jù)傳輸過(guò)程中出現(xiàn)卡死的現(xiàn)象,錯(cuò)誤信號(hào)較少。</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測(cè)量范圍有限,最大值80cm,并且從60cm開(kāi)外的距離開(kāi)始測(cè)量值的波動(dòng)較大,與實(shí)際情況偏差增大。(60cm為室內(nèi)環(huán)境的個(gè)人感受,不同環(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時(shí),測(cè)量值將與實(shí)際值出現(xiàn)明顯偏差,當(dāng)距離值從10降至0的過(guò)程中,測(cè)量值將在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;">* 紅外傳感器,使用時(shí)會(huì)受到環(huán)境光的影響,在室內(nèi)使用時(shí),傳感器數(shù)據(jù)接收時(shí)可能會(huì)受到白熾燈光線的印象,產(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)多個(gè)GP2d12同時(shí)連接Arduino板使用時(shí),由于供電量的增加,可能造成電壓不穩(wěn)定而對(duì)測(cè)量結(jié)果產(chǎn)生偏差。從硬件角度可以通過(guò)在VCC與 GND之間接電容的方式來(lái)穩(wěn)定對(duì)GP2d12的供電,減少供電電壓波動(dòng)對(duì)測(cè)量結(jié)果的影響,或者在GND與數(shù)據(jù)線之間接一個(gè)電容減小輸出電壓的波動(dòng)略去可能出現(xiàn)的誤差信號(hào),提高數(shù)據(jù)穩(wěn)定性。(接線見(jià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;">* 針對(duì)測(cè)量時(shí)可能產(chǎn)生的干擾和誤差數(shù)值,可能從軟件的角度進(jìn)行改進(jìn)和防止,通過(guò)多次的測(cè)量記錄,排除一場(chǎng)輸入量后,取均值來(lái)的到一個(gè)較為穩(wěn)定更為接近實(shí)際值的測(cè)量數(shù)據(jù)。其次可以根據(jù)實(shí)際的使用要求,可以進(jìn)行有效值的范圍定義,過(guò)濾超出范圍的測(cè)量結(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;">* 針對(duì)紅外傳感器測(cè)量時(shí),可能受環(huán)境光影響測(cè)量結(jié)果,在安放使用時(shí)竟可能避免傳感器正對(duì)燈光的使用,可以將 GP2d12的發(fā)射接收端水平放置進(jìn)行測(cè)量,盡可能減少環(huán)境光帶來(lái)的干擾。</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;">總體來(lái)說(shuō):&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在對(duì)測(cè)量精度要求不高,測(cè)量范圍在1m以?xún)?nèi)的情況下,對(duì)物體距離值的定位是非常簡(jiǎn)單有效地、操作簡(jiǎn)便、實(shí)用性強(qiá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>將傳感器連接到UNO控制器模擬口A1上,注意對(duì)應(yīng)線序:一般情況下3P線黃色接信號(hào),紅色接電源正,黑色接電源負(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上,注意對(duì)應(yīng)線序:一般情況下3P線黃色接信號(hào),紅色接電源正,黑色接電源負(fù)</div></td></tr> </table> Arduino77 http://www.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上,注意對(duì)應(yīng)線序:一般情況下3P線黃色接信號(hào),紅色接電源正,黑色接電源負(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">打開(kāi) Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測(cè)試到的距離。</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)舵機(jī)轉(zhuǎn)動(dòng)到一個(gè)給定的位置時(shí)測(cè)定距離,將其轉(zhuǎn)換為L(zhǎng)ED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個(gè)位置,然后繼續(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)舵機(jī)轉(zhuǎn)動(dòng)到一個(gè)給定的位置時(shí)測(cè)定距離,將其轉(zhuǎn)換為L(zhǎng)ED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個(gè)位置,然后繼續(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上,注意對(duì)應(yīng)線序:一般情況下3P線黃色接信號(hào),紅色接電源正,黑色接電源負(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;">打開(kāi) Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測(cè)試到的距離。</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|無(wú)框|右]]</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|無(wú)框|右]]</div></td></tr> </table> Arduino77 http://www.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:/* 模擬信號(hào)與測(cè)量距離對(duì)應(yīng)表 */ 2015-12-29T08:06:00Z <p>?<span dir="auto"><span class="autocomment">模擬信號(hào)與測(cè)量距離對(duì)應(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紅外線測(cè)距傳感器的電壓值與距離值的關(guān)系曲線,從這個(gè)曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時(shí)有2.55V輸出,80cm距離時(shí)有0.42V輸出??梢酝ㄟ^(guò)該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個(gè)關(guān)系式里的距離是參考距離值,實(shí)際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對(duì)應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實(shí)際距離與采樣數(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紅外線測(cè)距傳感器的電壓值與距離值的關(guān)系曲線,從這個(gè)曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時(shí)有2.55V輸出,80cm距離時(shí)有0.42V輸出??梢酝ㄟ^(guò)該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個(gè)關(guān)系式里的距離是參考距離值,實(shí)際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對(duì)應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實(shí)際距離與采樣數(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>實(shí)際距離=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>實(shí)際距離=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>===信號(hào)輸出===</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>===信號(hào)輸出===</div></td></tr> </table> Arduino77 http://www.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:/* 模擬信號(hào)與測(cè)量距離對(duì)應(yīng)表 */ 2015-12-29T08:05:29Z <p>?<span dir="auto"><span class="autocomment">模擬信號(hào)與測(cè)量距離對(duì)應(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>===模擬信號(hào)與測(cè)量距離對(duì)應(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>===模擬信號(hào)與測(cè)量距離對(duì)應(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紅外線測(cè)距傳感器的電壓值與距離值的關(guān)系曲線,從這個(gè)曲線可以看出,電壓輸出與距離成反比,而且是非線性關(guān)系。根據(jù)上圖關(guān)系曲線,大約關(guān)系為10cm距離時(shí)有2.55V輸出,80cm距離時(shí)有0.42V輸出??梢酝ㄟ^(guò)該曲線擬合出電壓值與距離值的數(shù)學(xué)關(guān)系式,但是這個(gè)關(guān)系式里的距離是參考距離值,實(shí)際距離值=(參考距離值-0.42)cm,另外由于Arduino的模擬量采樣命令analogRead(),采樣的數(shù)據(jù)范圍是0至1023,對(duì)應(yīng)的電壓范圍是0至5V,每格數(shù)據(jù)代表0.0049V,于是讀取的有效數(shù)據(jù)應(yīng)該由86(0.42V)至520(2.548V)。所以最終可以推導(dǎo)出實(shí)際距離與采樣數(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; 實(shí)際距離=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>===信號(hào)輸出===</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>===信號(hào)輸出===</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可以將模擬信號(hào)轉(zhuǎn)為數(shù)字信號(hào)輸出</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可以將模擬信號(hào)轉(zhuǎn)為數(shù)字信號(hào)輸出</div></td></tr> </table> Arduino77 http://www.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 是日本夏普公司推出的一款性?xún)r(jià)比高、最常用的紅外測(cè)距傳感器...”為內(nèi)容創(chuàng)建頁(yè)面 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 是日本夏普公司推出的一款性?xún)r(jià)比高、最常用的紅外測(cè)距傳感器...”為內(nèi)容創(chuàng)建頁(yè)面</p> <p><b>新頁(yè)面</b></p><div>[[文件:RB-02S041.jpg|500px|縮略圖|右]]<br /> ==產(chǎn)品概述==<br /> GP2D12 IR Sensor 是日本夏普公司推出的一款性?xún)r(jià)比高、最常用的紅外測(cè)距傳感器、其可用來(lái)對(duì)物體的距離進(jìn)行測(cè)量,實(shí)現(xiàn)輪式機(jī)器人的避障功能。它不但體積小、功耗低、價(jià)格便宜,而且測(cè)距效果好,適合廣大機(jī)器人發(fā)燒友使用。<br /> ==規(guī)格參數(shù)==<br /> # 測(cè)量射程范圍:10 to 80 cm <br /> # 最大允許角度:&gt;40° <br /> # 電源電壓:4.5 to 5.5V <br /> # 平均功耗:35mA <br /> # 峰值功耗:約200mA <br /> # 更新頻率/周期:25Hz / 40ms <br /> # 模擬輸出噪聲:&lt;200mV <br /> # 測(cè)量距離與輸出模擬電壓關(guān)系:2.4V~0.4V模擬信號(hào)對(duì)應(yīng)10cm~80cm,輸出與距離成反比非線性關(guān)系<br /> ===產(chǎn)品尺寸圖===<br /> [[文件:RB-02S0411.jpg|700px|縮略圖|居中]]<br /> ===模擬信號(hào)與測(cè)量距離對(duì)應(yīng)表===<br /> [[文件:RB-02S0412.jpg|700px|縮略圖|居中]]<br /> ===信號(hào)輸出===<br /> ADC0831可以將模擬信號(hào)轉(zhuǎn)為數(shù)字信號(hào)輸出<br /> [[文件:RB-02S0413.jpg|700px|縮略圖|居中]]<br /> ==接口定義==<br /> * Vo:輸出引腳<br /> * GND:電源地<br /> * Vcc:電源正極<br /> ==使用方法==<br /> ===例程1===<br /> ====連接示意圖====<br /> [[文件:RB-02S0414.jpg|700px|縮略圖|居中]]<br /> 首先將距離傳感器固定到舵機(jī)上,可以使用熱熔膠或者膠帶。然后使用一個(gè)1uf電解電容和一個(gè)22uf電解電容并聯(lián)在5V穩(wěn)壓芯片L4940V5上。將紅外距離傳感器的信號(hào)線插入0號(hào)模擬引腳。4個(gè)LED通過(guò)1KΩ電阻插入3、5、6、11引腳。最后將舵機(jī)信號(hào)線接在9號(hào)引腳上。<br /> ====例子程序====<br /> &lt;pre style='color:blue'&gt;<br /> #include &lt;Servo.h&gt;<br /> const int SERVO =9; //伺服電機(jī)連接在9號(hào)引腳<br /> const int IR =0; //紅外距離傳感器連接在0號(hào)模擬引腳<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; //伺服電機(jī)對(duì)象<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); //綁定伺服電機(jī)<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 /> //將伺服電機(jī)在4個(gè)區(qū)域中掃描并改變LED亮度<br /> dist1 = readDistance(15); //在15°處進(jìn)行紅外測(cè)距<br /> analogWrite(LED1, dist1); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測(cè)量前的延時(shí)<br /> <br /> dist2 = readDistance(65); //在65°處進(jìn)行紅外測(cè)距<br /> analogWrite(LED2, dist2); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測(cè)量前的延時(shí)<br /> <br /> dist3 = readDistance(115); //在115°處進(jìn)行紅外測(cè)距<br /> analogWrite(LED3, dist3); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測(cè)量前的延時(shí)<br /> <br /> dist4 = readDistance(165); //在165°處進(jìn)行紅外測(cè)距<br /> analogWrite(LED4, dist4); //調(diào)節(jié)LED亮度<br /> delay(300); //下次測(cè)量前的延時(shí)<br /> }<br /> <br /> int readDistance(int pos)<br /> {<br /> myServo.write(pos); //轉(zhuǎn)動(dòng)到指定位置<br /> delay(600); //等待伺服電機(jī)轉(zhuǎn)動(dòng)<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)舵機(jī)轉(zhuǎn)動(dòng)到一個(gè)給定的位置時(shí)測(cè)定距離,將其轉(zhuǎn)換為L(zhǎng)ED的亮度值,改變LED的亮度值,將其轉(zhuǎn)向下一個(gè)位置,然后繼續(xù),如此重復(fù)。<br /> <br /> ===例程2===<br /> ====接線方法====<br /> 將傳感器連接到UNO控制器模擬口A1上,注意對(duì)應(yīng)線序:一般情況下3P線黃色接信號(hào),紅色接電源正,黑色接電源負(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 /> 打開(kāi) Arduino IDE 串口監(jiān)視器可以觀察到當(dāng)前傳感器測(cè)試到的距離。<br /> ==產(chǎn)品相關(guān)推薦==<br /> [[文件:erweima.png|230px|無(wú)框|右]]<br /> ===產(chǎn)品購(gòu)買(mǎi)地址===<br /> [http://www.gharee.com/goods-181.html 夏普GP2D12紅外測(cè)距傳感器]&lt;br/&gt;<br /> ===周邊產(chǎn)品推薦===<br /> [http://www.gharee.com/goods-183.html Arduino IR Sensor GP2Y0A02YK0F夏普紅外測(cè)距傳感器]&lt;br/&gt;<br /> ===相關(guān)問(wèn)題解答===<br /> [http://www.makerspace.cn/forum.php?mod=viewthread&amp;tid=3851&amp;highlight=%E5%A4%8F%E6%99%AE 夏普紅外測(cè)距邊界問(wèn)題]&lt;br/&gt;<br /> ===相關(guān)學(xué)習(xí)資料===<br /> [http://www.makerspace.cn/portal.php 奧松機(jī)器人技術(shù)論壇]&lt;br/&gt;</div> Arduino77