Codey OnlineLibreria di componenti Arduino ed ESP32 › TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm
TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm
Sensori

TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm

Il TOF400C-VL53L1X è un modulo sensore di distanza time-of-flight che misura la distanza da un oggetto in un intervallo di circa 4–400 cm. Comunica con un microcontrollore tramite un’interfaccia I2C e viene in genere usato in robotica e automazione per rilevamento ostacoli e misurazione delle distanze.

Larghezza: 21.5 mm

Pinout — TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm

Pin Segnale Descrizione
VIN power Module supply input for the VL53L1X board, typically 3.3–5 V depending on module regulator.
GND ground Ground reference for power and I2C signals.
SDA SDA I2C serial data line for distance readings and configuration.
SCL SCL I2C serial clock line driven by the host controller.
INT interrupt Interrupt output from the VL53L1X, used to signal measurement/data-ready events.
SHUT reset XSHUT shutdown/reset input; drive low to disable or reset the sensor.

Schema di cablaggio di esempio — TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm

Da A Filo
board:5V x1:VIN red
board:GND x1:GND black
board:A4 x1:SDA green
board:A5 x1:SCL blue

Codice Arduino di esempio — TOF400C-VL53L1X Distance sensor Time-Of-Flight very accurate 4-400cm

Questo esempio è stato scritto e verificato in compilazione per arduino-uno. Codey Online lo adatta a qualsiasi altra scheda supportata.

#include <Wire.h>

const uint8_t SENSOR_I2C_ADDR = 0x29;
const uint8_t REG_SOFT_RESET = 0x0000;
const uint8_t REG_START = 0x000E;
const uint8_t REG_RANGE_STATUS = 0x0089;
const uint8_t REG_DISTANCE = 0x0096;

void write8(uint16_t reg, uint8_t value) {
  Wire.beginTransmission(SENSOR_I2C_ADDR);
  Wire.write((uint8_t)(reg >> 8));
  Wire.write((uint8_t)(reg & 0xFF));
  Wire.write(value);
  Wire.endTransmission();
}

uint8_t read8(uint16_t reg) {
  Wire.beginTransmission(SENSOR_I2C_ADDR);
  Wire.write((uint8_t)(reg >> 8));
  Wire.write((uint8_t)(reg & 0xFF));
  Wire.endTransmission(false);
  Wire.requestFrom(SENSOR_I2C_ADDR, (uint8_t)1);
  return Wire.available() ? Wire.read() : 0;
}

uint16_t read16(uint16_t reg) {
  Wire.beginTransmission(SENSOR_I2C_ADDR);
  Wire.write((uint8_t)(reg >> 8));
  Wire.write((uint8_t)(reg & 0xFF));
  Wire.endTransmission(false);
  Wire.requestFrom(SENSOR_I2C_ADDR, (uint8_t)2);
  uint16_t value = 0;
  if (Wire.available() >= 2) {
    value = (uint16_t)Wire.read() << 8;
    value |= Wire.read();
  }
  return value;
}

bool sensorPresent() {
  Wire.beginTransmission(SENSOR_I2C_ADDR);
  return Wire.endTransmission() == 0;
}

void setupSensor() {
  // VL53L1X-style boot sequence: soft reset, then start ranging.
  write8(REG_SOFT_RESET, 0x00);
  delay(10);
  write8(REG_SOFT_RESET, 0x01);
  delay(10);
  write8(REG_START, 0x01);
  delay(50);
}

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ;
  }

  Wire.begin();
  Serial.println("TOF400C VL53L1X distance sensor example");

  if (!sensorPresent()) {
    Serial.println("Sensor not found at I2C address 0x29. Check wiring.");
    while (true) {
      delay(1000);
    }
  }

  setupSensor();
  Serial.println("Sensor initialized.");
}

void loop() {
  uint8_t status = read8(REG_RANGE_STATUS);
  uint16_t distanceMm = read16(REG_DISTANCE);

  Serial.print("Range status: ");
  Serial.print(status);
  Serial.print("  Distance: ");
  Serial.print(distanceMm);
  Serial.println(" mm");

  delay(200);
}

Componenti correlati

18650 Battery Shield with USB-C Charger and 5V Boost Converter

18650 Battery Shield with USB-C Charger and 5V Boost Converter

2.4 inch OLED Display I2C 3.3V

2.4 inch OLED Display I2C 3.3V

3.5 inch TFT LCD Shield

3.5 inch TFT LCD Shield

50kg Load Cell Weight Sensor

50kg Load Cell Weight Sensor

Crea il tuo progetto Arduino o ESP32 con l'AI

Descrivi cosa vuoi realizzare. Codey Online scrive il codice, disegna lo schema di collegamento, lo compila e programma la tua scheda direttamente dal browser.

Inizia gratis