코드 검색

레이저 VL53L0X 6핀 모듈과 LCD1602-I2C를 이용한 거리 측정 for Arduino

레이저 VL53L0X 6핀 모듈과 LCD1602-I2C를 이용한 거리 측정 for Arduino

이 튜토리얼에서는 VL53L0X 레이저 센서를 사용하여 거리를 측정하고 I2C 인터페이스가 있는 LCD1602에 결과를 표시하는 방법을 배웁니다. 이 프로젝트를 통해 밀리미터 또는 센티미터 단위로 정밀한 거리 측정이 가능하며, Arduino 기반 프로젝트에 다용도로 활용할 수 있습니다. 이 튜토리얼이 끝나면 설정과 사용이 쉬운 완전한 기능의 거리 측정 시스템을 갖추게 됩니다.

VL53L0X 200cm range sensor

이를 위해 I2C를 통해 Arduino와 통신하는 VL53L0X 레이저 거리 센서를 활용합니다. LCD1602 디스플레이는 측정된 거리를 명확하게 시각적으로 표시합니다. 코딩 과정에 대한 자세한 내용은 비디오(비디오 00:00 부분)를 참조하세요.

하드웨어 설명

이 프로젝트의 주요 구성 요소는 VL53L0X 레이저 거리 센서와 LCD1602 디스플레이입니다. VL53L0X는 레이저를 사용하여 거리를 정확하게 측정하므로 로봇 공학 및 자동화를 포함한 다양한 응용 분야에 적합합니다. I2C 통신을 사용하여 Arduino와 쉽게 통합할 수 있습니다.

LCD1602 디스플레이는 I2C 지원 문자 디스플레이로 두 줄에 최대 16자를 표시할 수 있습니다. 기존 LCD보다 적은 핀을 사용하므로 데이터 표시 과정이 간단해집니다. 이 구성 요소들이 함께 강력하고 사용자 친화적인 거리 측정 시스템을 만듭니다.

데이터시트 세부 정보

제조업체STMicroelectronics
부품 번호VL53L0X
로직/IO 전압1.8 V ~ 2.8 V
공급 전압2.6 V ~ 3.5 V
출력 전류(채널당)
피크 전류(채널당)
PWM 주파수 가이드
입력 로직 임계값
전압 강하 / RDS(on) / 포화
열 제한
패키지
참고 사항 / 변형

  • 적절한 공급 전압(2.6 V ~ 3.5 V)을 확인하세요.
  • 필요한 경우 SDA 및 SCL 라인에 풀업 저항을 사용하세요.
  • 오류 판독을 방지하려면 센서를 반사 표면에서 멀리 유지하세요.
  • I2C 주소를 확인하세요(VL53L0X의 기본값은 0x29).
  • 고온 환경에서 사용하는 경우 방열을 고려하세요.

배선 지침

Arduino wiring for VL53L0X and LCD1602 I2C (4 wires LCD)

VL53L0X 센서와 LCD1602 디스플레이를 배선하려면 먼저 전원과 접지를 연결하세요. VL53L0X의 VCC 핀을 Arduino의 5V 핀에 연결하고 GND 핀을 Arduino의 접지에 연결합니다. LCD1602의 경우 VCC를 동일한 5V에, GND도 접지에 연결합니다.

다음으로 I2C 통신 라인을 연결합니다. VL53L0X의 SDA 핀은 Arduino의 A4 핀에 연결하고 SCL 핀은 A5에 연결해야 합니다. XSHUT 핀은 Arduino의 D12에 연결할 수 있지만 연결하지 않아도 됩니다. LCD1602의 경우 SDASCL도 VL53L0X 센서와 동일한 핀에 연결해야 합니다.

코드 예제 및 설명

VL53L0X sensor;

#include 
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  sensor.init();
  sensor.setTimeout(500);
  sensor.startContinuous();
  lcd.begin();
  lcd.backlight(); 
}

setup 함수에서 직렬 통신과 I2C 버스를 초기화합니다. sensor.init()는 VL53L0X 센서를 초기화하고 lcd.begin()은 LCD 디스플레이를 초기화합니다. 디스플레이의 백라이트가 켜져 쉽게 볼 수 있습니다.

void loop() {
  int distance = sensor.readRangeContinuousMillimeters();
  Serial.print("Distance: ");
  lcd.clear();
  lcd.print("Robojax VL53L0X");
  lcd.setCursor(0,1); 
  lcd.print("Dist.: ");
  lcd.setCursor(7,1); 
  lcd.print(distance); 
  Serial.println();
  delay(100);
}

loop 내부에서 sensor.readRangeContinuousMillimeters()를 사용하여 거리를 지속적으로 읽고 직렬 모니터에 출력합니다. LCD는 거리 측정값으로 업데이트되어 실시간 피드백을 제공합니다. 100밀리초의 지연은 판독값이 너무 자주 업데이트되지 않도록 하여 쉽게 읽을 수 있게 합니다.

시연 / 예상 결과

전원을 켜면 시스템이 지속적으로 거리를 측정하고 결과를 LCD에 표시합니다. 물체를 센서에 가까이 또는 멀리 이동함에 따라 거리 값이 변경되는 것을 볼 수 있습니다. 타임아웃 오류와 같은 센서 문제가 발생하면 적절한 메시지가 직렬 모니터에 출력됩니다(비디오 03:15 부분).

이미지

VL53L0X 200cm range sensor
VL53L0X 200cm range sensor
Arduino wiring for VL53L0X and LCD1602 I2C (4 wires LCD)
Arduino wiring for VL53L0X and LCD1602 I2C (4 wires LCD)
113-Measure distance with a laser VL53L0X 6-pin module and an LCD1602-I2C for Arduino
언어: C++
/* 

This is Arduino code to measure distance with VL53L0X and display it on LCD1602 with I2C module.
Distance is displayed in mm (millimeter) or cm (centimeter).

Original Laser Sensor source: https://github.com/adafruit/Adafruit_VL53L0X
Modified by Ahmad Shamshiri for RoboJax.com
Date modified: Jun 28, 2018 at 19:06 in Ajax, Ontario, Canada

Watch the video instruction for this code: https://youtu.be/t14ly7Y09oI
You can get this code from RoboJax.com.
Pin connection

VL53L0X Pin  Arduino Pin
VCC         5V
GND         GND
SDA         A4 or SDA if available
SCL         A5 or SCL if available
GPIO1       leave it unconnected
XSHUT       D12 (digital 12 or pin 12)

LCD1602 Pin

*/


#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;


#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int type = 1;// 1=mm , 2= cm
String unit;// variable for unit, mm or cm
void setup()
{

  Serial.begin(9600);
  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();
  
  // initialize the LCD, 
  lcd.begin();
  // Turn on the blacklight and print a message.
  lcd.backlight(); 
}

void loop()
{
  int distance =sensor.readRangeContinuousMillimeters();
  //int distance =sensor.startContinuous(100);

 //distance = distance;
  Serial.print("Distance: ");

  //start of loop Robojax code for LCD with I2C
  lcd.clear();
  lcd.print("Robojax VL53L0X");
  lcd.setCursor (0,1); // go to start of 2nd line
  lcd.print("Dist.: ");
  lcd.setCursor (7,1); // go to start of 2nd line
  if(type ==2){
    float distanceCM = (float) (distance/10.0);
      unit ="cm";
      lcd.print(distanceCM);
      Serial.print(distanceCM);
      Serial.print(unit);      
    }else{
    unit ="mm";
      lcd.print(distance);
      Serial.print(distance);
      Serial.print(unit);       
    }  

  lcd.print(unit);    
  
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  delay(100);
}

필요할 수 있는 것들

자원 및 참고자료

파일📁

프리징 파일

다른 파일들