URM37 Ultrasonic Distance Measurer Library

Hey guys,

This'll be the first library I've written for the Arduino. The guy(s) over at YeRobot had produced some code to interface with the sensor but it requires the hardware serial ports (0,1) which I wanted to avoid.

This library is intended to make life a little easier by encapsulating the measurement and serial functionality. Everything is handled for you with minimal delays so you can avoid blocking.

First up, we've made a slight modification to the NewSoftwareSerial library to include "new/delete" operators. I wasn't aware that the AVR C++ libraries excluded support of the implicit "new" operator, which also meant the library wouldn't be stand-alone.

To minimise the number of ports used vs. the original code, only RX/TX are used. The rest are just wired to VCC. You'll have to modify your setup accordingly.

It's really simple to use. begin(rxPort, txPort, baudRate) that'll setup the serial port to communicate with the device, any standard digital port is fine.

requestMeaurement() - Send the distance request command. It'll only ever allow you to request it once until a message has been received regardless of the times you call the method.

hasReading() avoids blocking, it checks until the serial buffer has sufficient data.

...and finally, getDistance(). This returns an integer.

Onto the code: http://svn.atl.mnetcs.com/repos/arduino/

Put that in a folder called URM37 within hardware/libraries.

I haven't added this to the playground yet as, well, I'm not sure if its stable or "arduino-like". Plenty of work left to do ;)

Does anyone have any comments or suggestions? It's all pretty buggy at the moment and generally needs polishing up :)

Ah my mistake, I wasn't aware the SVN was secured.

Temporarily you can grab the library here

The sensor is available at


Interfacing with the tempreture sensor will be included soon.

For a full explanation of the library and it’s functionality, please visit my Wiki

You can now fetch the latest stable version from

URM37 Library 1.0

This now include the temperature measurement functionality.

Again, it’s very simple to use. There’s been quite a few changes throughout the code; however, the end user should only need to be concern with the following:

You call requestMeasurement(DistanceType); Where DistanceType is an integer which represents the measurement type. I’ve provided serial definitions in the example code which allows you to use DISTANCE & TEMPERATURE.

When you getMeasurement pass the variable which will contain the measurement as an argument. For example: getMeasurement(theDistance).

As the library now supports more than one measurement type, you can use a switch (per my provided example) which allows you to process the measument dependant on type. For example:

case DISTANCE: (The definition at the top of the example)


That’s it! A little more complicated than the first version but allows more flexibility.

Let me know if you spot any problems.

Final comments:
You thoeretically can send multiple commands to the device. These will queue up within the arduino and URM37 buffers. I’d avoid sending multiple types until you get a response otherwise you may run into some unexpected errors. (…basically I’ve not tried it)

Temperate: You can request this as much as you like. It is more or less instant. Don’t forget to remember, it probably wont change often is your ambient temperature is constant.

Distance: I found you can request distance VERY quickly. The response time is directly proportional the object in “view”. In essence, the speed of sound (taking into account temperature) guides how quickly you will receive a response. Chances are you’ll be using the URM within a small environment where all objects are within a few meters, consiquently, it’ll take few ms to respond. - I’m planning to run some tests, if you have any information let me know.

hi first of i would like to say that this links you have o your post are not working except the of the library on wiki.

i have the urm37 sensor working eith the code on the yerobot website. i find it diffucult to make the connections right since there are a lot of things going on like the ttl modes at the back

inside the library there is a code MeasurementBySerial. but is is not working for me. could you please give a connection diagram.

i am trying to make a project using these sensors. my project requires more than one. is there any way the code on the yerobot to be modifies so that it can take more than one sensor? i am asking for this code because it is the only one working for me at the moment.