_4211908.jpgI've originally meant to write about propeller mounting, tracking, tightening and about my first flight (which ended up with a stripped spinner nut), but since my sonar arrived and, since installation wasn't exactly 100% straightforward, that's today's subject. So, here it is, in the photo above - the Maxbotix LV-EZ4 sonar, freshly taken out of it's zip-lock baggy, along with a 5 pin header. Which is not included. That's from my own header stash. NOBODY TOUCHES MY PRECIOUSES! *cough*Headers.jpgWhy 5 pins? Because that's the minimum of pins that spans from the GND and +5V/+3.3V on one side of the header and the analogue out on the other. Why pins at all (instead of soldering the cable directly)? Because i want it to be easily replaceable and detachable, in case i want to experiment with it off the ArduCopter. Why EZ4 and not EZ0? Because i thought its beam pattern makes more sense for this particular application:EZ4.jpgNarrowest and shortest beam for tiny objects. Longest and widest beam for large, uniform objects (i.e. ground). Why LV and not XL? Because it's cheaper and my Arduino/electronics/RC/'copter budget's running thin at the moment. Otherwise, XL probably would've been a much better choice.Anyways. I've bought it from jDrones along with their little sonar mounting kit, just because i was too lazy to figure out / improvise my own way to mount it. And because it looked neat. However, first test fit ended up like this..._4201900.jpgMmmyeah. It would appear Maxbotix' tolerances are much looser than the margins jDrones left when designing the mount. The transducer casing isn't quite mounted at the center. Unsoldering it isn't an option, since it's epoxied to the board, so..._4201905.jpg... a few seconds of nylon spacer dremeling later (sandpaper works too, but i'm lazy):_4201906.jpgMuch neater. Now for the header. Here's a simple little trick for soldering headers (and connectors and other components) i've learned from FreakLabs. First flip the board and add a dab (and i really mean a dab) of solder to one of the holes:_4211910.jpgImportant tip! Never ever do this with the GND hole! They're usually connected to a rather biggish ground plane, which can soak up a lot of heat. Doing that might leave you with a plugged hole you'll have a really hard time sucking the solder from. Trust me, i've been there! Okay. Now. Take the header and press it against the holes:_4211911.jpgMind your finger! Don't put it on the pin that's against the soldered-up hole or you might get a burn in the next step. Which is - apply heat to the hole and push the header through simultaneously:_4211914.jpgTrim the leads as short as you can - you want the board to be as flat as possible:_4211916.jpgNow just solder the rest of the pins (and reflow the first one). Don't be stingy on the solder, after it fills up the hole (through to the other side), it won't accumulate any further and will just remain on the soldering iron. And there we go, nice and flat:_4211918.jpg_4211919.jpgThe baggy that comes with the sonar mount kit contains a bit more hardware (can nylon be called hardware?) than is needed for the installation. Here's what is needed to install it on the bottom of the ArduCopter:_4211923.jpgThe sonar PCB is flat... ish... but still not flat, so it's a good idea to use some washers:_4211925.jpg... and there we go, nice and neat:_4211926.jpgNow. Where to put it? From the hole distance, i'd say it was meant to be put smack dab in the middle of one of the main plate vertices, like this:_4211931.jpg... however, if you put it there, there will be no room for the battery and it will have to be mounted off-center, shifting the center of gravity quite a bit. Plus, it looks bad and interferes with access to the battery when you want to take it off / put it back. It turns out there are other two holes that fit the distance perfectly and don't obstruct the battery footprint:_4211937.jpgYou'll have to unscrew one of the nuts that clamp the arm. If you've got an ESC right above the corresponding bolt (like i did), you'll have to remove it, and mount it back when you're finished. One of the long spacers from the sonar mount kit will serve as the new nut. That also means you'll have to put the nut on the other side of the spacer (instead of a bolt). Here's the end result:_4211945.jpg_4211949.jpgThe only thing left now is to fashion a cable to hook the sonar up to the Oilpan pitot tube input. I've again made the same set of make-shift female header connectors as before. The sequence of the pins on the sonar is exactly the same as the sequence on the Oilpan - GND is the leftmost (when facing the front of the APM or the vertex of the sonar PCB with the pin header), then 5V, then analogue out/in._4211955.jpg_4211962.jpgThe only thing left now is to enable the sonar in software. I'm using ArduPirates branch. First, let's check if it works correctly. Navigate to Libraries/AP_RangeFinder/examples/AP_RangeFinder_test and open the AP_RangeFinder_test.pde sketch. There are two lines of interest here:AP_RangeFinder_MaxsonarXL aRF;//AP_RangeFinder_MaxsonarLV aRF;Now, it would seem logical to comment the first line and uncomment the second if you have an LV model. However, it so turns out that the LV model uses the exact same scaling on the analogue output as the XL, at least in my case. Whether it's something that has recently changed, or something mixed something up, i do not know. I do know that my sonar most definitely is an LV model and that it outputs correct values with the XL routines, NOT the LV routines. To be sure, leave it like this, run the sketch and check the output on the serial monitor, then change it to the other option and do the same. That should make it absolutely clear which one is the correct one.The first number is the real distance/altitude, the second is the raw output. For XL (and my LV), both numbers are the same, because the absolute output of the sonar board is scaled so that they're exactly proportionate and equal with a reference voltage of 5V.After you've verified your sonar works and you've determined the correct sonar reading routines to use, pay a visit to Config.h in the main ArduPirates sketch folder and set the two lines at approx. 251-252 (it's around line 65 for ArduCopterNG code branch) to:#define UseBMP // Use pressure sensor for altitude hold (default) ?#define IsSONAR // or are we using a Sonar for altitude hold?Next up, open ArduPiratesNG.pde, find the following lines at approx. 90-91 (around the line 228 for ArduCopterNG) and uncomment the appropriate one, depending on the result of your test sketch output:AP_RangeFinder_MaxsonarXL AP_RangeFinder_down; // Default sonar for altitude hold//AP_RangeFinder_MaxsonarLV AP_RangeFinder_down; // Alternative sonar is AP_RangeFinder_MaxsonarLVCompile and upload the code, switch to CLI mode and check the sonar PID values by pressing 'o'. According to defaults and the wiki, good values for the stock ArduCopter hardware should be P=0.8, I=0.3, D=0.7.That's all, folks (for now)!And a belated happy Easter!
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • Hi everyone, we saw a comment in this thread where a few of you had asked about the maximum range of the LV and XL ultrasonic sensors we offer. I figured I would quickly post some of the relevant information to answer these questions.

    The maximum range reported by the LV-EZ sensors is 254 inches or (645 cm)

    The maximum range reported by the XL-EZ sensors is (300 inches) or 765 cm

    The maximum range reported by the XL-EZL sensors is (420 inches) or 1068 cm

    It is important to note that each of these units has different scaling on the analog voltage output pins. (This is done to support the increased range information)

    Range to a given size target can be found by referencing the sensor beam patterns, a composite image of the  LV beam patterns is available here: http://www.maxbotix.com/articles/003.htm and for the XL's go here: http://www.maxbotix.com/articles/008.htm

    If you have any questions, please let me know.

    Best regards,
    Scott Wielenberg
    Technical Support & Sales
    of MaxBotix Inc.
    Phone: (218) 454-0766
    Fax: (218) 454-0768
    Email: scott@maxbotix.com
    Web: www.maxbotix.com
    Follow us on Facebook at: 


  • I have done some readings with a multimeter.

    I pointed to the proximity and read near 0V, then pointed to the ceiling and measured about 816mv so doing the conversion 9.18mV/inch is about 83inch = 211cm which looks reasonable.

    So it seems like the sensor works ok.

    Any  suggestions from the code gurus?

  • Nice catch :)

    It's not a bad soldered, it's just that the solder hasn't flown all the way through to the top-side of the board (the pins are soldered from the other side and there's plenty of solder there). And the reason it hasn't is that it's a ground hole.

    Ground holes generally have a tendency to wick less solder in them, because they don't heat up uniformly throughout the whole through-hole, which is due to one side typically being a part of a larger ground plane which draws the heat away. If you look carefully, the telemetry port's ground pin is the same way.

  • @Ante, Nice photos, your build logs are excellent. In the last photo here it looks like one of your RA Header pins to the pitot connections isn't soldered properly, but it may just be the photo.


  • just to be clear, where I am:

    ArduCopterMega 2.0.23

    LV EZ4 sonar

    about constant 340cm reading on test/sonar on CLI


    I've been reading the datasheet and have to do some tests with a multimeter to figure out if the sensor is working properly, when I have time (whenever is that) I will post my results.


    Any other one with sonar problems?

  • hey I.S, im getting 34 also, will not go lower than that too....?
  • Nope. Absolutely no free time for the past few weeks (thesis deadline approaching).
    Didn't even have time to check ACM2 out.
  • @Ante

    Very nice post.

    I have just installedLV EZ4 sonar, enabled it on ACM2 .23 and do the Sonar test on CLI.

    It gives me about 340cm reading all the time no matter how far from the floor the sensor is.

    Have you tested your sonar on ACM2?

  • @Michael Zaffuto - I love that shield :)
    So far, haven't used it for much besides basics (shift register, PWM), but keep planning to try out the sonar rangefinder project from Eric's page and then expand it a bit (i've got a dozen of ultrasonic transducers and some op-amps i've bought for that sole purpose). Work and ArduCopter keep interfering and i have a thesis i really should be working on ;)


    @ Jani - Oh, i've got a bunch of three-wire cables very similar to that one, but didn't want to chop them up. Plus, this way, i can take the sonar off the ArduCopter and plug it into a breadboard if i ever want to experiment with it (90 degree header means it's conveniently directed forwards in that case :)


    Re: EZ0 vs. EZ4 - thing i found important in the datasheets is, EZ4's detection pattern is narrower and shorter the smaller the object you're bouncing the echo off from. I.e. small protruding objects that might be near the arducopter (a branch, a loose wire, battery's velcro) will likely be ignored in favour of the big, fat and flat target that's the ground below. That's why i chose it. I might be completely off in my reasoning, though. And i haven't tested how it works with grass yet (but it does give off a nice and solid bounce off carpets).

  • Developer

    ArduCopter does not know if you are using XL or LV. It just relies on output what those are giving. ArduCopterMega supports both sonars for other ArduCopter software's we do not know but most of them are based on our libraries so they should work ok too.


    If you want as high as possible altitude, take XL due it's range is almost double compared to LV. As said LV works well too. After 5-6 meters it does not matter so much anyways because we can start rely on pressure sensor.


    The most important accuracy is on low altitudes anyways... Just like if you plan to take a picture from house, you will take picture from around 60-100m of alt, if baro/gps can hold you within 5 meters it is still really accurate and you don't see the difference on that.



This reply was deleted.