VL53L0X 飛行時間微型激光雷達距離感測器 Arduino 使用教學
台灣智能感測科技2024-11-04T16:02:32+08:00 由 台灣智能感測科技 模組技術文件 Adafruit VL53L0X, Arduino 教學, Arduino 距離感測, Arduino 距離測量, VL53L0X 距離感測器, 序列監控器顯示距離, 微型雷達模組, 激光雷達感測器, 距離測量模組, 飛行時間感測器 0 則討論
步驟與項目
VL53L0X 飛行時間微型激光雷達距離感測器 Arduino 使用教學
您將學習如何使用 VL53L0X 飛行時間距離感測器搭配 Arduino Uno。我們會介紹如何連接感測器來測量毫米級的距離,並在序列監控器上顯示讀數。這個專案將提供您實際操作先進感測器的經驗,並了解其在真實場景中的應用,進一步提升您的 Arduino 技能。
- Arduino Uno 開發板
- VL53L0X 飛行時間距離感測器模組
- 面包板
- 跳線
購買整組套件會更方便,以下是 VL53L0X 連結:https://www.taiwansensor.com.tw/sku/SNG-006282
接線圖
函數庫與範例
函數庫:請使用 Arduino Library Manager 安裝程式庫,搜尋「Adafruit_VL53L0X」,並安裝它。
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
/* This program tests the Adafruit VL53L0X Time of Flight Distance Sensor. It initializes the sensor, reads a distance measurement, and prints the distance in millimeters to the serial monitor. Note: The VL53L0X can handle about 50 - 1200 mm of range distance. Board: Arduino Uno R4 (or R3) Component: Time of Flight Distance Sensor (GY-530 base on VL53L0X) Library: https://github.com/adafruit/Adafruit_VL53L0X (Adafruit_VL53L0X by Adafruit) */ #include <Adafruit_VL53L0X.h> //Create an object of the Adafruit_VL53L0X class Adafruit_VL53L0X lox = Adafruit_VL53L0X(); void setup() { Serial.begin(115200); // wait until serial port opens for native USB devices while (!Serial) { delay(1); } //Initialize the sensor Serial.println("Adafruit VL53L0X test"); if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while (1) //Stop the program if the sensor cannot be initialized ; } Serial.println(F("VL53L0X API Simple Ranging example\n\n")); } void loop() { VL53L0X_RangingMeasurementData_t measure; Serial.print("Reading a measurement... "); lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout! if (measure.RangeStatus != 4) { // phase failures have incorrect data Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter); } else { Serial.println(" out of range "); } delay(100); } |
程式碼分析
包括必要的庫和初始化感測器物件。我們首先包含 VL53L0X 感測器的函式庫並建立 Adafruit_VL53L0X 類別的實例。
1 2 |
#include <Adafruit_VL53L0X.h> Adafruit_VL53L0X lox = Adafruit_VL53L0X(); |
函數中的初始化
setup()
。在這裡,我們設定串行通訊並初始化距離感測器。如果感測器無法初始化,程式將停止。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void setup() { Serial.begin(115200); while (!Serial) { delay(1); } Serial.println("Adafruit VL53L0X test"); if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while (1) ; } Serial.println(F("VL53L0X API Simple Ranging example\n\n")); } |
捕獲並顯示函數中的測量值
loop()
。 Arduino 使用此rangingTest()
方法持續捕捉距離測量結果。如果測量有效,則會將其列印到串行監視器。
1 2 3 4 5 6 7 8 9 10 11 12 |
void loop() { VL53L0X_RangingMeasurementData_t measure; Serial.print("Reading a measurement... "); lox.rangingTest(&measure, false); if (measure.RangeStatus != 4) { Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter); } else { Serial.println(" out of range "); } delay(100); } |
發佈留言
很抱歉,必須登入網站才能發佈留言。