Servers by jDrones

How to Install Dual Sonars on a Pixhawk

Hi All,
I just completed installing dual Maxbotix MB1240 sonars on one of my Pixhawk equipped rovers.
Since the sonars were from an APM equipped rover they already had single pair shielded cables terminated with three pin servo connectors providing power, rtn, and the sonar output signal.
You will need a DF13 five pin connector cable to connect to the Pixhawk ADC3.3vdc Analog Input. The cable should be wired as follows:
Pin 1 5vdc (red)
Pin 2 Left Sonar Signal Input (Sonar)
Pin 3 RTN
Pin 4 Right Sonar Signal Input (Sonar2)
Pin 5 RTN

Since I am using two sonars, I had to trigger them sequentially to avoid having them see each other. Therefore I used two of the Aux Servo pins as Digital Outputs:
Aux Servo pin 5 (Virtual pin 54) Right sonar trigger
Aux Servo pin 4 (Virtual pin 53) Left sonar trigger
These two outputs go to the Left and Right sonar trigger pins.

Then go to the MP’s Full Parameter List and set up the Sonar and Sonar2 parameters. For the Maxbotix MB1240 setup described above use the following parameters:
BRD_PWM_CNT 0 (Makes all the Aux Servo pins digital)
Sonar Function 0
Sonar Enable 1
Sonar Debounce 2
Sonar Max Cm 700
Sonar Min Cm 20
Sonar Offset 0
Sonar Pin 14 (Left sonar)
Sonar Scaling 2.04 (Adjust as necessary to display the correct distance to the target)
Sonar Settling Ms 50
Sonar Stop Pin 53 (Left sonar trigger)
Sonar Trigger Cm Whatever distance you want in cm
Sonar Turn Angle Whatever angle you want in deg
Sonar Turn Time Whatever time you want in sec
Sonar2 Function 0
Sonar2 Enable 1
Sonar2 Debounce 2
Sonar2 Max Cm 700
Sonar2 Min Cm 20
Sonar2 Offset 0
Sonar2 Pin 13 (Right sonar)
Sonar2 Scaling 2.04 (Adjust as necessary to display the correct distance to the target)
Sonar2 Settling Ms 50
Sonar2 Stop Pin 54 (Right sonar trigger)

TCIII ArduRover2 Developer

[quote=“TCIII”]Hi All,
I just completed installing dual Maxbotix MB1240 sonars on one of my Pixhawk equipped rovers.[/quote]

Thanks Tom for this guide!

I think this great tutorial should be pretty usefull for the AVC attendees.


After looking at the MAxBotix Datasheet, you can wire the sensors so that when you trigger the first in line, it will trigger the next sensor sequentially, as long as the sensor is trigger for 20us. Have you tried this method? Instead of using the aux servo pins?


No I never made use of this feature because the ArduRover code was written for just two sequential MaxBotix sonars. To use this feature you might have to modify and recompile the ArduRover code.

@TCIII I cannot seem to find sonar_enable (RNGFND_ENABLE) in Mission Planner I also do not see an option for the sonar pin, 13 and 14 are not mentioned in the description for admissible options. Sonar has also been replaced with RNGFND now btw. We are not getting any change in return voltage from the two sonars. nor are we getting a distance readout. Have 4.9-5 volts to sensors. Wired correctly. Any suggestions? Is this an ardurover issue? Also, what is the correct setting for RNGFND_ADDR?

Update: after reconnecting the sonars and double checking the settings, the sonars are triggering. I am getting a range and a voltage reading, but I am not sure if it is accurate. Is there a way I can check each sensor for range? I only see a “sonarrange” and a "sonarvoltage:

Glad to hear the sensors are triggering.

Find a flat wall with no obstacles between the range findar (sonar in your case) and the wall. With a tape measure measure the distance between the wall and the range finder. Now check what distance is in sonarrange. Adjust SONAR_SCALING up or down to suit until the sonarrange distance matches the measured distance.

Thanks, Grant.

Hi All
I followed the instructions above and have at least one sonar working. I am using rover 3.2.2 and MP 1.3.52. The problem is in the settings for MP there is RNDFND and RNGFND2. This is fine, however in status and in tuning there is only sonarrange and sonar voltage. I can not find variables for the range finders separately so that I can see how they are individually reacting.

Can you please explain how to wire up for the trigger pins, I assume that you use the pixhawk output 4 & 5 to be wired to pin 4 on each of the MB1240 sensor?
I’m getting a reading from sonarrange, on my 6Wheel Wild Thumper, and it shows on the bin file. I’ve been trying to get the steering to see obstacles, I am still trying to achive.
Thanks in advance for any help, I’m more at home with Helicopters, but I wanted to try a rover.


It has been a long time since I worked with the Dual Sonars. During the time that I used them for obstacle avoidance I found them to be too unreliable at any speed over 3m/s. They would false trigger due to ground bounce and cross winds. Also the processing time made them too slow for consistent obstacle avoidance at high speeds.

I would recommend using LidarLite as it is much more reliable and can range much farther than the acoustic sonar!


I’ve got the MB1240’s working , but as you say you have to have a low travel speed.
I have a Lindar Lite but it’s and early version, on one of my Quads. Do you have one or two No. on the front, the same as as the MB1240’s? Any info you can spare, would be helpful. Have you tried the rotary Lindar?

Would LidarLite work to keep a Rover inside of crop rows? I am making a rover to do Ag spraying and would like to have it avoid objects on each side. Essentially to keep the sucker running straight.

YouTube Test:
Pixhawk2 Rover

Hi Jimmy,

LidarLite is really sensitive to the quality of the reflecting surface.

I suggest that you take a look at Donkey Car where they use OpenCV and TensorFlow to keep a model RC car within its driving lane. The software is very mature and is widely supported.



Does this OpenCV include Autonomous missions?

Oh, and thanks for always helping. It’s great to have your knowledge here!

Once a vehicle running the Donkey Car OS is trained, it can be used for running autonomous missions.

The way that I look at it, you need optical processing to stay in the row and GPS to know when to turn into the next row and when to start and stop in the field. You are looking at sensor fusion here.

There are special GPS systems that are designed to keep a tractor aligned in the rows of a field by using a local reference, but I can’t remember where I read about that kind of system.


That’s a tall order right now. I will try the Donkey. I have most of the parts. Just need to 3D print some parts and get the Sombrero. I the mean time I have the dual Maxbotics up and working but they are not working independently. No readings that are changing. They just mimic each other at around 367cm. Will this solution even work with current Ardurover?

Is Sonar value merged into RNGFND?

Servers by jDrones