How do I call the value of reading from VL53LOX and store it to a register?

I have VL53LOX connecting to arduino D1 I use the code find it in the example of IDE (shown below). Its required to read this value to to PLC via Modbus protocol

The problem is the serial stopped reading the value when plc connected to arduino D1 and began to read the distance.

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {


// wait until serial port opens for native USB devices

while (! Serial) {



Serial.println("Adafruit VL53L0X test");

if (!lox.begin()) {

Serial.println(F("Failed to boot VL53L0X"));



// 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 ");


MBHoldingRegister[6] = measure.RangeMilliMeter;



Could anyone help me to solve the problem?

Can you try getting your VL53L0X working with your Arduino D1 by using our VL53L0X library and running either the Single or Continuous example sketch? If either of those sketches work fine, can you then try adding your PLC into the system to see if you get the same serial issue? If so, can you send pictures that clearly show your setup and connections?


Thank you JonathanKosh, for reply. In fact I use VL53LOX library, the circuit read distance successfully but its frozen when plc connected with arduino D1.
The picture of connection as below:O%20water%20intake%20layers_WSN

I was faced the same problem when connecting the ultra sonic senser HC-SR04M with PLC via ESP8266 I was solved it by using the function distance() in right of the command
MBHoldingRegister[6] = measure.RangeMilliMeter;
instead of using distance (found inside Serial.println(distance))
now the code is different :grinning:
its need to A skillful touch in programming :slightly_smiling_face:

It sounds like your VL53L0X is working and that this is an issue with communicating between your PLC and your Arduino D1 board. We are not very familiar with the D1, so the Arduino forums would be a better place to ask for troubleshooting help with that.