Getting 2 VL53L0X sensors to record seperate readings


I am trying to get 2 VL53L0X sensors to give me separate distance readings. However, based on my code, both the VL53L0X sensors give me the same distance reading.

I place an object in front of my left VL53L0x sensor and both my sensor readings drop in value (information is displayed on Serial Monitor using Arduino).

Can you tell me how I can correct my code?

// sensor has a correction of +10mm
// if the actual distance is 40mm, sensor reads 50mm

#include <VL53L0X.h>
#include <Wire.h>
VL53L0X sensor;   // Sensor 1
VL53L0X sensor1;  // Sensor 2

void setup()
  pinMode(12,INPUT_PULLUP);   // Sensor 1
  pinMode(11,INPUT_PULLUP);   // Sensor 2
  digitalWrite(11, HIGH);

  sensor.init();          // Sensor 1

  sensor1.init();       // Sensor 2

void loop()
  int distance =sensor.readRangeContinuousMillimeters();
  int distance1 =sensor1.readRangeContinuousMillimeters();
  //int distance =sensor.startContinuous(100);
  Serial.print("Distance 1 : ");
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.print("   Distance 2 : ");
  if (sensor1.timeoutOccurred()) { Serial.print(" TIMEOUT");



To use multiple I2C devices, like your VL53L0X sensors, each device needs to be configured with a unique I2C address. Both of your VL53L0X senors will boot up with a default 7-bit address of 0101001b (41). It can be changed to any other value by writing one of the device configuration registers, but the new address only applies until the sensor is reset or powered off. This application note describes how to use multiple VL53L0X sensors on the same I²C bus by individually bringing each sensor out of reset and assigning it a unique address.

The simplest procedure if you are using our board and our VL53L0X Arduino library will be to connect the XSHUT pins one each of your VL53L0X senors to your Arduino and at the beginning of your program set those pins as outputs and drive them low. Then, enable each sensor one at a time by reconfiguring the XSHUT pin as an input (make it high impedance) to let the board to pull it high and use the setAddress command from our library to change the I2C device for the corresponding sensor. Do not just drive the XSHUT pins high if you are using an Arduino that operates at 5V; the XSHUT on our VL53L0X carrier is not level shifted so it can only handle 3.3V. When you are done, you could use the getAddress command from our library and print the results to your Serial Monitor to confirm that it worked.

For an example, you could look at the ContinuousMultipleSensors example from our VL53L1X Arduino library, which is for a different ST time-of-flight sensor carrier, but is structured similarly to our VL53L0X library.

- Patrick