# LV-MaxSonar Sensor Questions

Hello,

This is my first post here at LMR. I decided to write out a question in the format of a blog. Since I've had some trouble getting my head around this issue and I found limited resources regarding this special device on the Internet. Creating a blog post might help other people with similar questions as me.

My problem is quiet simple. I got a  nice little package from Sparkfun.com today. Waiting for two weeks now it finally arrived. I'm building my first robot. Exciting. Learning something new every day. Anyhow, I cant get any sensible readings out of my EZ1 Ultrasonic Sensor. I wanted to buy a Ping)), but couldnt find a shop which had it AND the other parts I needed. So I ended up with this little thing. It has three different outputs. One analog, 0-5v, one PWM where we can measure the speed of sound in Microseconds, and a third serial output.

To make it easier i'll try to sum up the details of the device here. Complete datasheet.pdf

• 42kHz Ultrasonic sensor.
• RS232 Serial Output - 9600bps.
• Analog Output - 10mV/inch.
• PWM Output - 147uS/inch(0.147 ms (milliseconds) per inch).

So far I've hooked up the device and done some testing, none of which did impress me, but I think I'm doing it wrong, anyway. The analog testing was OK. Managed to get a not so accurate result in cm using the following formula:

`     (AnalogValue / 2) * 2.54.`

1 inch == 2.54cm. I've seen people report that they get more accurate readings if multiplied by 2.6 which in my case also was true.

When looking at the pulse width readings I had trouble figuring out a good formula and I guess this is where I'd like some suggestions. So far I've just done some random testing with no conclusive results. For example; I managed to get ok results up to 50 cm, but after that readings where random. I think my math is wrong.I've used the following assumtations; Speed of sound is ±340m/s or 29 microseconds per cm. Also its worth to notice that there are 1,000,000mus per second. Or to say it in a different way, its one millionth of a second. To calculate the PW value i used this.

`    (microseconds / 2) / 29    or: microseconds / 2 / 2900000`

These are my results:

1. 14.5cm -> 20cm: ±1cm
6. 50 -> nothing that made sence. Sometimes high, other times low.

I've used the Arduino board to perform the calculations. The code was a rewriting of the ping)) example on the arduino.cc page. I used the RX pin on the last test to trigger the sensor. MaxSonar writes that "To calculate distance use the scale factor of 147uS per inch." But I wasnt able to get any results using that formula, probably did it wrong. So i guess what I'm looking for is some kind of advice on how to use this device. Remember I'm a complete newbie and have only done this for two weeks now. Less then a month ago I had no idea what a resistor or a microcontroller was, I had no idea this kind of computing could be so much fun :)

Thanks for the help, in advance.

Btw. here is a short list of links i found related to this sensor on the net. Might be interesting for others as well:

## Comment viewing options

Hi Simon, I have the same setup as you. A maxbotix using pulse width on an arduino.

I found the accuracy is off by a few cms which could be because of the divides being done in integers. I don`t need extremely good accuracy so it didn`t bother me.

What is more annoying are the fluctuations every now and then even when not moving. Sometimes at distances more than 1m it could jump or drop suddenly by about 20cms. I thought it might be noise so I put a resistor and cap on the +ve and gnd pins right on the back of the sensor according to this FAQ. I haven`t really done any testing so I couldn`t say if it helped or not but if your power supply is a bit noisy it might be worth a try.

Thanks for the kind replies.

I'll try to update my blog post with new _facts_ so it can serve as a small resource on this sensor. I actually didnt pay attention to the calibration phase, must have missed it. So it might have coused some random results because of that, but i did a great amount of tests, so i dont think it was sufficiant.

I also noticed the sudden drops, as you say, ezekiel, Especially in an open range at greater distance. The Close range readings still are kind of good. But not as good as i expected :)

I got another IR sensor i will test later. Lets see how they compare.