Issue with HC-SR04 Rangefinder

no the arduino does not go between them, everything is powered from the flight controller, the Arduino is taking control of the sensors, changing the address and then letting the flight controller take control of them. The reason this works is that ardupilot takes much longer to startup than this little program so it can change them before ardupilot looks for them.

you connect the splitter into your flight controller, that provides, 5v SCL SDA and GROUND signals

the lidars and the arduino all plug into the splitter, each getting a 5v, SCL SDA and ground

you add 1 extra wire between the arduino A0 A1 A2 A3 pins and each lidar.

you can buy the connectors prewired, the are jst 1.25 4pin.

Ok, understood. thank you for the explanation! I tried tilting my sensors up but no luck, so i will buy the lidars. Appreciate your help!

I tried those cheap ultrasonic sensors some years ago and quickly concluded they were worthless on a Rover.

1 Like

i have the same conclusion now…

Hi, its been a while.

I bought 2 vl53l0x, and 2 vl53l1x lidars (and the rest of things:arduino and splitter)

After wiring everything up, plugging it into the flight controller (to I2C port that was initially desingned for airspeed sensor), and turning it on, the board is stuck on boot loop, and won’t turn on, what could possibly be wrong? I checked the wiring but everything seemed ok.

Also, before wiring everything together, i plugged in a single sensor straight to I2C port, and everything worked fine.

you need the arduino board to change their addresses. They all have the same i2c address so conflict with each other, The Arduino board starts them one at a time and changes their addresses before the flight controller starts so they can all be detected with different addresses.

if your looking for a cheap 360 degree lidar i got one working here

I think i am having issues with the arduino and its code, maybe its because there are 2 different sensor models? Might need to add the library for the 0X sensor, but dont really know how…

With the help of AI i created the custom code, that should work with both types of sensors:

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

#define XSHUT_pin1 A0
#define XSHUT_pin2 A1
#define XSHUT_pin3 A2
#define XSHUT_pin4 A3

#define Sensor1_newAddress 41
#define Sensor2_newAddress 42
#define Sensor3_newAddress 43
#define Sensor4_newAddress 44

VL53L1X Sensor1;
VL53L1X Sensor2;
VL53L0X Sensor3;
VL53L0X Sensor4;

void setup()
  pinMode(XSHUT_pin1, OUTPUT);
  pinMode(XSHUT_pin2, OUTPUT);
  pinMode(XSHUT_pin3, OUTPUT);
  pinMode(XSHUT_pin4, OUTPUT);

  Serial.println("Serial communication started.");


  pinMode(XSHUT_pin4, INPUT);
  Sensor4.setAddress(Sensor4_newAddress); // Change this to the desired new address for VL53L0X
  Serial.println("VL53L0X Sensor 4 address change successful");

  pinMode(XSHUT_pin3, INPUT);
  Sensor3.setAddress(Sensor3_newAddress); // Change this to the desired new address for VL53L0X
  Serial.println("VL53L0X Sensor 3 address change successful");

  pinMode(XSHUT_pin2, INPUT);
  Serial.println("VL53L1X Sensor 2 address change successful");

  pinMode(XSHUT_pin1, INPUT);
  Serial.println("VL53L1X Sensor 1 address change successful");

  Serial.println("Setup completed. Code will not loop anymore.");

void loop()
  // The loop function is empty, code will only run once.

But for some reason the code stops at: “Serial communication started” so it doesn’t change the addresses at all, any reason why? (as i said the wiring is as described, checked 3 times)

just try the code as i posted it , it will probably work for both.
Don’t post AI stuff, its never correct. no one has yet come in here with any information gave to them by an AI that was correct.

nope, your original code doesn’t work, its still on boot loop.

I tried unplugging one of the sensors out of the splitter and the FC turned on, but ardupilot wasn’t detecting anything… :cry:

are you using the i2c scanner lua script to detect the sensors?

when its running you should see all the range finders show up with different addresses. 41 42 43 44

if it’s not turned on originally, most likely i dont have it turned on, how to do it?

you need to download the i2c scanner script from the lua examples copy it to the scripting folder on the flight controller sd card then enable scripting

by the sounds of it you have the SCL and SDA mixed up on the arduino board.

what board are you using?

I am using a Speedybee F405 Wing FC.

i think i have scripting already enabled on my custom firmware, because i thought it might be useful at some point, so i will load the script to the SD card and see if it finds the sensors.

what are you using to run the arduino code.

i am sure it is a clone of Arduino nano v3.0 with an old bootloader, at least that what it said when i was buying it

setup 4x type 16 sensors with address 41 42 43 44 and see if any get data when you have just 2 sensors that are the same either the vl53l1x or the vl53l0x

try setting BRD_BOOT_DELAY to 1000 to give the arduino time to run incase its starting up too fast, it was a pixahawk that i tested it on not a f405.

tried the LUA script, but it is not possible on my side because my fc is only 1mb of memory, and it does not work, it says: “Scripting: out of memory”.

after swapping the SCL and SDA, the FC still does not turn on, and still turns on after unplugging one (any) senosr from the splitter, but i don’t think my FC is receiving any data from the rest of the senosrs…

Today’s example of the F4 lacking. Even if you have an F4 with 2mb, like a Pixracer, the maximum heap size available isn’t good for much. Been there, done that, replaced the Flight Controller.

After setting up 3 sensors (cant do 4 because boot loop) and plugging them into the FC, one of them was giving data for a while, but then stopped…