Search Code

Arduino와 함께 VL53L0X 레이저 거리 측정기 사용

Arduino와 함께 VL53L0X 레이저 거리 측정기 사용

이 튜토리얼에서는 Arduino와 함께 VL53L0X 레이저 거리 측정기를 사용하는 방법을 살펴보겠습니다. 이 장치를 사용하면 레이저를 사용하여 거리를 정확하게 측정할 수 있으므로 로봇 공학 및 자동화와 같은 다양한 응용 분야에 이상적입니다. 이 튜토리얼이 끝나면 거리를 측정하고 직렬 모니터에 표시할 수 있는 기능 설정을 갖게 됩니다.

VL53L0X 200cm range sensor-blue

우리 프로젝트에서는 센서와의 인터페이스 프로세스를 단순화하는 Adafruit VL53L0X 라이브러리를 사용할 것입니다. 이 라이브러리는 센서를 초기화하고, 측정값을 읽고, 발생할 수 있는 오류를 처리하는 데 필요한 기능을 제공합니다. 설정에 대한 시각적 가이드는 비디오를 참조할 수 있습니다(02:15 비디오 참조).

하드웨어 설명

이 프로젝트의 주요 구성 요소에는 VL53L0X 레이저 거리 측정기와 Arduino 보드가 포함됩니다. VL53L0X는 레이저를 사용하여 최대 2미터의 거리를 높은 정확도로 측정하는 비행 시간 센서입니다. I2C 프로토콜을 통해 작동하므로 Arduino와 쉽게 통신할 수 있습니다.

Arduino 보드는 VL53L0X의 데이터를 처리하는 마이크로컨트롤러 역할을 합니다. 센서에 명령을 보내고 거리 측정값을 수신한 다음 다른 응용 프로그램에 표시하거나 활용할 수 있습니다. 센서의 정확한 판독값을 보장하려면 적절한 배선이 중요합니다.

데이터시트 세부 정보

생산자STMicroelectronics
부품 번호VL53L0X
작동 전압2.6V - 3.5V
레인지30 mm - 2000 mm
정밀±3% 일반
인터페이스I2C
온도 범위-40 °C - +85 °C
소비 전류<1mA(대기), 20mA(활성)
패키지VFLGA-8

  • 센서에 전원이 올바르게 공급되는지 확인하십시오(2.6V에서 3.5V).
  • 충돌을 피하기 위해 올바른 I2C 주소 설정을 유지하십시오.
  • 정확한 거리 측정을 위해 센서를 깨끗하게 유지하십시오.
  • 필요한 경우 I2C 라인에 적절한 풀업 저항을 사용하십시오.
  • 신뢰할 수 있는 판독값을 위해 센서에 직사광선을 피하십시오.

배선 지침

Arduino Wiring for VL53L0X
Arduino Wiring for VL53L0X

VL53L0X 센서를 Arduino에 연결하려면 센서의 VCC 핀을 Arduino의 5V 핀에 연결합니다. GND 핀은 Arduino의 접지(GND)에 연결되어야 합니다. I2C 통신의 경우 VL53L0X의 SDA 핀을 Arduino의 A4 핀에 연결하고 SCL 핀을 A5 핀에 연결합니다. 다른 Arduino 모델을 사용하는 경우 해당 보드에 대한 특정 SDA 및 SCL 핀 할당을 참조하십시오.

예를 들어, Arduino Mega에서는 SDA를 핀 20에 연결하고 SCL을 핀 21에 연결합니다. 통신 문제를 방지하려면 모든 연결이 안전한지 확인하십시오. 센서가 응답하지 않으면 배선을 다시 확인하고 Arduino에 제대로 전원이 공급되는지 확인하십시오.

코드 예제 및 연습

다음은 VL53L0X 센서를 초기화하는 설정 함수의 스니펫입니다.

void setup() {
  Serial.begin(9600);
  while (! Serial) {
    delay(1);
  }
  Serial.println("Robojax Test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
}

이 코드는 직렬 통신을 초기화하고 VL53L0X 센서를 시작하려고 시도합니다. 센서가 부팅에 실패하면 오류 메시지가 인쇄되고 프로그램이 중지됩니다.

다음으로, 거리 측정값을 읽는 루프 함수의 스니펫은 다음과 같습니다.

void loop() {
  VL53L0X_RangingMeasurementData_t measure;
  lox.rangingTest(&measure, false);
  if (measure.RangeStatus != 4) {
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }
  delay(100);
}

이 블록은 센서에서 거리 측정값을 지속적으로 읽어 직렬 모니터에 인쇄합니다. 측정값이 범위를 벗어나면 그에 따라 이를 나타냅니다.

데모 / 기대 사항

프로그램을 실행하면 직렬 모니터에 거리 측정값이 표시됩니다. 판독값은 100밀리초마다 업데이트되어야 합니다. 센서가 물체를 가리키고 있으면 거리를 밀리미터 단위로 표시합니다. 개체가 범위를 벗어나면 이를 나타냅니다. 최적의 결과를 위해 지정된 범위 내에서 센서를 테스트해야 합니다(10:00 비디오).

비디오 타임스탬프

  • 00:00-소개
  • 02:15- 배선 설정
  • 05:30- 코드 설명
  • 10:00-논증

이미지

VL53L0X 200cm range sensor-blue
VL53L0X 200cm range sensor-blue
Arduino Wiring for VL53L0X
Arduino Wiring for VL53L0X
15-Using a VL53L0X laser distance meter in Arduino
언어: C++
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X.
// Original source from Adafruit https://github.com/adafruit/Adafruit_VL53L0X
// Modified by Ahmad Shamshiri for RoboJax.com
// Date modified: Sep 26, 2017
// Nejrabi

* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. 

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

   Copyright (c) 2015, Majenko Technologies
   All rights reserved.

   Redistribution and use in source and binary forms, with or without modification,
   are permitted provided that the following conditions are met:

 * * Redistributions of source code must retain the above copyright notice, this
     list of conditions and the following disclaimer.

 * * Redistributions in binary form must reproduce the above copyright notice, this
     list of conditions and the following disclaimer in the documentation and/or
     other materials provided with the distribution.

 * * Neither the name of Majenko Technologies nor the names of its
     contributors may be used to endorse or promote products derived from
     this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
   ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
   ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  Serial.begin(9600);

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }
  
  Serial.println("Robojax Test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  // power 
  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);
}

필요할 수 있는 것들

자원 및 참고자료

파일📁

프리징 파일

  • Adafruit VL6180X Time of Flight Distance Sensor
    Fritzing part for the Adafruit VL6180X Time of Flight distance sensor. This sensor measures absolute distance up to 100mm and ambient light, communicating via I2C. Includes the sensor breakout board and pin connections for use in Fritzing projects.
    Adafruit VL6180X Time of Flight Distance Sensor-1.fzpz 0.02 MB

다른 파일들