LV-MaxSonar Sensor Questions
June 5, 2009
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.
- 20Hz reading rate.
- 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:
- 14.5cm -> 20cm: ±1cm
- 25cm: readings where 21.5cm
- 30cm: readings where 26cm
- 40cm: readings where 36cm
- 50cm: readings where 45cm
- 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: