CJMCU VL53L0X 레이저 거리 측정기를 Arduino와 함께 사용하기
이 튜토리얼은 Arduino와 함께 CJMCU VL53L0X 레이저 거리 측정기를 사용하는 방법을 보여줍니다. Texas Instruments VL53L0X 비행시간(ToF) 센서와 TXS0108E 양방향 레벨 시프터(비디오 00:06)를 갖춘 이 모듈은 최대 2미터(비디오 00:52)까지 정밀한 거리 측정을 제공합니다. 다양한 로직 레벨(3.3V, 1.8V, 5V)과의 호환성 덕분에 여러 마이크로컨트롤러와의 통합이 간편합니다(비디오 00:21). 이 프로젝트는 다양한 가능성을 열어줍니다.
프로젝트 아이디어:
- 로봇공학: 로봇에 장애물 회피 기능 구현.
- 자동화: 근접도에 기반한 기계 제어.
- 스마트 홈: 거리에 따른 자동 조명 시스템 구축.
- 보안: 근접 기반 경보 시스템 개발.
하드웨어/부품
이 프로젝트를 구축하려면 다음 부품이 필요합니다:
- Arduino 보드 (모든 모델 호환)
- CJMCU VL53L0X 레이저 거리 측정기 모듈
- 점퍼 와이어
배선 가이드
VL53L0X 모듈은 다음과 같이 Arduino에 연결됩니다:
모듈의 VCC 핀을 Arduino의 5V 핀에 연결합니다. 모듈 내부 레귤레이터가 센서에 필요한 3.3V를 처리합니다. (비디오 01:50)
모듈의 GND 핀을 Arduino의 GND 핀에 연결합니다.
모듈의 SDA 핀을 Arduino의 A4 핀에 연결합니다.
모듈의 SCL 핀을 Arduino의 A5 핀에 연결합니다.
XSHUT 핀은 셧다운 제어에 사용할 필요가 없는 한 연결하지 않은 상태로 둡니다. (비디오 03:50)
코드 설명
제공된 코드는 VL53L0X 라이브러리를 사용합니다. 주요 구성 가능한 부분에 대한 설명은 다음과 같습니다:
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
// ... 기타 설정 코드 ...
sensor.setTimeout(500); // 타임아웃을 500ms로 설정 (비디오 06:40)
sensor.startContinuous(); // 연속 측정 모드 시작 (비디오 06:50)
}
void loop()
{
Serial.print(sensor.readRangeContinuousMillimeters()); // 거리를 mm 단위로 읽기 (비디오 07:01)
// ... 기타 루프 코드 ...
}
sensor.setTimeout(500) 줄은 거리 측정의 타임아웃을 500밀리초로 설정합니다. 필요에 따라 이 값을 조정할 수 있습니다 (비디오 06:40). sensor.startContinuous() 함수는 연속 측정 모드를 시작하여 가능한 한 빠르게 거리 판독값을 제공합니다 (비디오 06:50). sensor.readRangeContinuousMillimeters() 함수는 측정된 거리를 밀리미터 단위로 반환합니다 (비디오 07:01).
실시간 프로젝트/데모
비디오는 센서의 작동을 보여주며, 센서와 대상 사이의 거리가 변함에 따라 거리 판독값이 어떻게 변하는지 보여줍니다. 판독값은 특히 10mm 이상의 거리에서 수 밀리미터 이내로 정확합니다 (비디오 08:20). 매우 가까운 거리(10mm 미만)에서는 정확도가 떨어집니다 (비디오 09:50). 데모는 또한 레이저가 표면에 수직이 아닌 경우 반사 표면이 판독값에 영향을 줄 수 있음을 보여줍니다 (비디오 10:32).
챕터
- [00:00] 소개 및 프로젝트 개요
- [00:48] VL53L0X 센서 세부 정보
- [01:41] 모듈 개요 및 사양
- [02:55] 응용 분야 및 표준
- [03:35] 핀아웃 및 연결
- [05:29] 코드 설명
- [07:45] 배선 및 연결
- [08:18] 실시간 데모
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm.
Updated by Ahmad Shamshiri for Robojax.com on July 23, 2018 in Ajax, Ontario, Canada.
Watch video instructions for this code: https://youtu.be/0PnAyt51IU4
Download the library and get other resources for this code at http://robojax.com
*/
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
Serial.println("Robojax CJMCU VL523L0X laser distance test");
Wire.begin();
sensor.init();
sensor.setTimeout(500);
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor.startContinuous();
}
void loop()
{
Serial.print(sensor.readRangeContinuousMillimeters());// print distance
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
자원 및 참고자료
-
외부Pololu download (GitHub)github.com
-
외부TXS0108E datasheetti.com
파일📁
프리징 파일
-
Adafruit VL6180X Time of Flight Distance SensorFritzing 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.fzpz0.02 MB