国产农村妇女精品一二区,国产A级毛片久久久久久精品,久久丫精品忘忧草西安产品,久久丫精品久久丫,久久国产精品波多野结衣AV,国产午夜精品一区二区,日韩精品极品视频在线观看免费,国产SUV精品一区二区,久久久国产精品,欧美精品一区二区,久久久久国产精品,欧美日韩精品久久久免费观看,欧美人妻日韩精品

激光測距傳感器在Arduino項目中的應用

  • 時間:2024-06-07 09:39:15
  • 點擊:0

隨著科技(ji)的(de)(de)(de)發展,越(yue)來(lai)越(yue)多(duo)的(de)(de)(de)創(chuang)新設(she)備(bei)進入了我們的(de)(de)(de)生活(huo)。其(qi)中,激光(guang)測(ce)距傳感器(qi)和Arduino結合在(zai)一起,為我們的(de)(de)(de)生活(huo)帶(dai)來(lai)了極大(da)的(de)(de)(de)便(bian)利(li)。本文將介紹(shao)如何使用Arduino和激光(guang)測(ce)距傳感器(qi)制作一個簡單的(de)(de)(de)距離(li)測(ce)量儀(yi),幫助您了解這種技(ji)術的(de)(de)(de)應用場景及(ji)其(qi)優勢。

一、什(shen)么是激光測距傳感(gan)器?

激(ji)光(guang)(guang)測距(ju)(ju)傳感(gan)器(qi)(qi)是一種可以(yi)測量距(ju)(ju)離(li)的(de)(de)裝置。它通過發射(she)激(ji)光(guang)(guang)脈沖(chong),然后接收(shou)反射(she)回來的(de)(de)激(ji)光(guang)(guang)脈沖(chong),從(cong)而計算(suan)出目標物體與傳感(gan)器(qi)(qi)之間的(de)(de)距(ju)(ju)離(li)。激(ji)光(guang)(guang)測距(ju)(ju)傳感(gan)器(qi)(qi)具有精度(du)高(gao)、抗干(gan)擾(rao)性強、測量范圍廣等優點(dian),因此在(zai)很多領域(yu)都(dou)有廣泛的(de)(de)應用。

二、Arduino簡(jian)介

Arduino是一款(kuan)開(kai)(kai)源電子(zi)原型平臺,專為藝術家(jia)、愛好者和專業人(ren)士設計。它集(ji)成了微控制器(Microcontroller)、編程語(yu)言(Processing)、硬件開(kai)(kai)發板(Arduino Uno)等組(zu)件,使得(de)用戶可以輕(qing)松(song)地制作(zuo)各種交互式設備(bei)。Arduino非常(chang)適合(he)初學者入門,因為它的學習(xi)曲線(xian)較為平緩(huan),而(er)且(qie)有著豐富的社區(qu)支持。

三、激(ji)光(guang)測距(ju)傳感器與Arduino的結合

將激光(guang)測(ce)(ce)(ce)距(ju)傳感(gan)器與(yu)(yu)Arduino結合在一(yi)(yi)起,可以(yi)實現(xian)很(hen)多有(you)趣(qu)的(de)(de)功能(neng)(neng)。例如(ru),我們可以(yi)制(zhi)作一(yi)(yi)個(ge)簡(jian)單的(de)(de)距(ju)離測(ce)(ce)(ce)量(liang)儀,用于測(ce)(ce)(ce)量(liang)人(ren)與(yu)(yu)物品(pin)之間的(de)(de)距(ju)離;還可以(yi)制(zhi)作一(yi)(yi)個(ge)智(zhi)能(neng)(neng)家(jia)居系統,通過激光(guang)測(ce)(ce)(ce)距(ju)傳感(gan)器檢測(ce)(ce)(ce)家(jia)庭成員的(de)(de)位置(zhi),從而實現(xian)自動燈(deng)光(guang)控制(zhi)、智(zhi)能(neng)(neng)門(men)鎖等功能(neng)(neng)。

四、實例:使用Arduino和激光測(ce)(ce)距(ju)傳感器制作距(ju)離測(ce)(ce)量儀

下面我們將(jiang)以一個簡(jian)單的距(ju)離測(ce)量儀為(wei)例(li),演示如何使用(yong)Arduino和(he)激光測(ce)距(ju)傳感器進行編(bian)程(cheng)。在這個例(li)子中,我們將(jiang)使用(yong)V-USB連(lian)接(jie)(jie)器將(jiang)Arduino與電(dian)腦連(lian)接(jie)(jie)起來。

1. 準備材(cai)料:Arduino開發(fa)板、激光測距傳感器、杜邦線若干(gan)。

2. 連接電路:將激光測距傳感(gan)器的(de)VCC引(yin)腳(jiao)連接到(dao)Arduino的(de)5V引(yin)腳(jiao),GND引(yin)腳(jiao)連接到(dao)Arduino的(de)GND引(yin)腳(jiao),Trig引(yin)腳(jiao)連接到(dao)Arduino的(de)數(shu)字(zi)輸入引(yin)腳(jiao)9(如(ru)D2),Echo引(yin)腳(jiao)連接到(dao)Arduino的(de)數(shu)字(zi)輸入引(yin)腳(jiao)10(如(ru)D3)。

3. 編(bian)寫程序:打開Arduino IDE,新建一個項(xiang)目(mu),將以下代(dai)碼粘貼到代(dai)碼編(bian)輯器中:

```cpp

#include

#define TRIGGER_PIN 9  // Arduino pin tied to trigger pin on the ultrasonic sensor.

#define ECHO_PIN  10  // Arduino pin tied to echo pin on the ultrasonic sensor.

#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {  // Runs once when you press reset or power the board.

Serial.begin(9600); // Open serial monitor at 9600 baud to see results below: Serial.begin(9600);

}

void loop() { // runs over and over again forever:

delay(50); // waits 50 milliseconds between each ping for a more accurate measurement. You may change this to be faster if you need the response time to be quicker.

unsigned int uS = sonar.ping_cm(); // Send ping, get ping time in microseconds (uS)

if (uS == MAX_DISTANCE + 1) {  // If we don't get a response from sonar within the timeout period (MAX_TIMEOUT), then return. // See below for an explanation of how to determine whether or not you have encountered an object in your environment.

Serial.println(F("Timeout")); // Say something nice to let us know there was a problem

} else if (uS > 0 && uS <= MAX_DISTANCE) { // If we get a response from the sonar and it is less than the maximum distance (MAX_DISTANCE), then: // The following line tells us that we are getting good data from our sonar! // It will also tell us the distance to the object we are trying to measure! // So we can print out some useful information about our measurements here:

float distance = uS * 0.0343/2; // Convert the distance from cm into meters // We use another constant because the speed of sound in air is different at these two scales (m/s vs cm/s). // This gives us a more accurate conversion than dividing by just one number. // See below for why we divide by both numbers.  // Print out some information: // This will be shown on serial output only. You can change this to put it on the screen like the setup above instead. // Note that this code uses integer math because the "/" operator does integer division on the Arduino Due: Serial.print(uS); Serial.print("cm ("); Serial.print(distance); Serial.println("m)"); // End of message } else if (uS >= MAX_DISTANCE+1){ // If we do not get a reply from our sonar within MAX_TIMEOUT, then there is probably an obstacle in front of the sonar. // This can happen for several reasons such as: objects blocking the path of the sonar, etc. // To fix this problem, try moving your sonar around until it finds an open space to transmit its signal. // You could also try using a longer wire between the sonar and your Arduino if there is interference along the way. Serial.println(F("Obstacle")); } }

```

推薦產品