Ultrasound range finder

I was lucky enough to get one of the free seeed modules that were given away (http://mbed.org/blog/entry/Free-Stuff---Seeedstudio-Modules/). I was given the ultrasound range finder.

Seeed ultrasound range finder

http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger is Seeed's docs for the module.


The range finder has a 4 pin connector, 3 of which are used. It has GND, Vcc and Signal lines. These are labelled on the board. The docs say the sensor is designed for 5V, but it works fine with the mbed's 3.3V. The signal line can be connected to any of the mbed's digital in/out pins.

To trigger a measurement a short pulse (around 10 us) is sent on the signal line. The ranger then send out some pulses and time when they return. The distance is then returned as a pulse of varying length such that

distance [m] = pulse width [us] / 5800 [us / m]

The two images below show the pulses being sent and received for a couple of different distances.

x pulse x pulse


I've written some code that runs the ultrasound ranger. It uses a /handbook/DigitalInOut to send a pulse and then to measure the width of the returning pulse using a /handbook/Timer. The code allows you to set a cut off time so that, should you lose connection to your range finder, it will return a negative distance and not hang up your program. I've tried this out and it is quite happy for me to disconnect the sensor and it will just return a distance of -1.0 m each loop until I reconnect it and it will resume giving me measured distances.

My code uses a library I wrote to read and write digital pulses:

Import libraryPulse

Output digital pulses of specified length and read the length of input pulses.

and also a library for range finders:

Import libraryRangeFinder

Class to handle triggering and reading the distance measured by a range finder.

This means that you can use a range finder with a very simple piece of code such as:

Import programSeeedUltrasoundRangeFinder

A simple program to use a Seeed ultrasound range finder.

Possible Improvements

I think it is possible to use some of the mbed's pins to take advantage of the LPC1768's time capturing ability. This should be more accurate than the current polling method and would be able to run in the background. I don't think this level of accuracy is needed with this sensor but it's something I might look into to learn some more about using the chip directly.

Use Cases

Some example use cases of these sensors are:

  • Robots detecting nearby walls/objects to avoid
  • Controlling the height of a quadrotor
  • Detecting motion by checking the variation in distance
  • Warning people that they are getting too close to you when you are cycling

And Finally...

If anyone else has any ideas, or if you read my code and would like to help me improve it then get in touch.

I'd like to thank the mbed team and also Seeed for giving me a cool sensor for free.

Please log in to post comments.