US-100 ultrasonic sensor in serial mode

In a previous article we used the US-100 ultrasonic sensor in pulse width mode, consisting primarily of sending a first start pulse and measure the pulse width of return. The problem of this mode of operation is that fails to take advantage of the characteristics of this sensor, which is able to compensate its calculations from room temperature.

In this article we will study the behavior of US-100 serial mode.

Settings and messaging of US-100 in serial mode

us100_1The serial mode for this sensor is set up via jumper. So, we will ensure that the rear jumper is closed.

In this mode, serial communications take place via those pins marked as Tx and Rx, which would be connected respectively to the transmit and receive pins of our Arduino. The serial port is configured as 9600 8N1.

In terms of messaging, this device allows two commands in serial mode:

  • 0x55: distance measurement request
  • 0x50: temperature measurement request

Response messages are:

  • Distance in millimeters, two bytes according to the expression: MSB * 256 + LSB
  • Temperature in degrees Celsius, one byte according to the expression: BYTE – 45

Mounting the test circuit

us100_bbWe will make the assembly shown in figure based on the following components:

As you can see in the figure, we connect pins 2 and 3 with the pin “trigger / tx” and “echo / rx” the US-100. The US-100 also requires that the two pins “GND” are shorted and connected to GND in Arduino.

Arduino programming

We use the following code to check the sensor:

// Prueba de medidas de distancia y temperatura con US-100 en modo serie
// Por RafaG, 2014

#include <SoftwareSerial.h>;

const int US100_TX = 2;
const int US100_RX = 3;

// Instancia nuevo canal serie
SoftwareSerial puertoUS100(US100_RX, US100_TX);

unsigned int MSByteDist = 0;
unsigned int LSByteDist = 0;
unsigned int mmDist = 0;
int temp = 0;

void setup() {

void loop() {

    puertoUS100.flush(); // limpia el buffer del puerto serie
    puertoUS100.write(0x55); // orden de medición de distancia


    if(puertoUS100.available() >= 2) // comprueba la recepción de 2 bytes
        MSByteDist =; // lectura de ambos bytes
        LSByteDist  =;
        mmDist  = MSByteDist * 256 + LSByteDist; // distancia
        if((mmDist > 1) && (mmDist < 10000)) // comprobación de la distancia dentro de rango
            Serial.print("Distancia: ");
            Serial.print(mmDist, DEC);
            Serial.println(" mm");

    puertoUS100.flush(); // limpia el buffer del puerto serie
    puertoUS100.write(0x50); // orden de medición de distancia

    if(puertoUS100.available() >= 1) // comprueba la recepción de 1 byte
        temp =; // lectura del byte
        if((temp > 1) && (temp < 130)) // comprobación de rango válido
            temp -= 45; // corrige offset de 45º
            Serial.print("Temperatura: ");
            Serial.print(temp, DEC);
            Serial.println(" ºC.");


Notice that we use the library SoftwareSerial in order to enable pins 2 and 3 as a new serial port for our Arduino. Otherwise, the code simply sends commands on distance measurement and temperature, showing the results.

Performing the tests and results

entorno100Once done the previous assembly -and propperly coded our Arduino-, our breadboard with the sensor installed is placed in front of a solid surface, using a ruler to reference the measures, such as is indicated in the figure:

By reference to a centimeter ruler, five measurements are taken for each of the reference distances (30, 25, 20, 15, 10, 5 and 3 cm). The errors of the mean for each group relative to the reference measurements are shown in the following graph:

graf100It can be seen that the measurement error remains within the manufacturer’s specifications. For small distances the error becomes negligible.

This entry was posted in Arduino and tagged , . Bookmark the permalink.

7 Responses to US-100 ultrasonic sensor in serial mode

  1. stoduk says:

    In your comparison of HC-SR04 and US-100, the US-100 had errors up to 8.5cm – with the error being roughly linearly increased with distance. [the HC-SR04 has slightly smaller errors, but comparable]

    In this review are you saying that in serial mode the US-100 gives drastically better accuracy? The max error is “0,1 cm” – is that 1mm? If so, do you think that is because the temperature compensation is coming in to play? Was this test done with the same unit from the previous test?



    • Rafa G says:

      Temperature compensation is very important to improve the accuracy but, in this case, it’s even more important the fact that the calcs are made by the same sensor and not the Arduino.


      • stoduk says:

        OK, guess that makes sense – looking at the NewPing library it is polling every 24us and claims that limits the accuracy. It always seemed odd to have the SR04 be smart enough to do the trigger/echo dance, when it could just report back the measurement directly. I should have realised the cheapest module was a dud, and gone for the US-100 🙂



      • stoduk says:


        I’ve got a US-100 now and the results are impressive. I’ve got it sat at a distance of 672mm from the floor, fixed to my desk pointing downwards.

        Using it in the dumb mode (ie. sending ping, measuring echo) I see the measurement is much higher than it should be (~795mm, so 123mm). I also see much more variability in the numbers – from 792 to 798mm.

        Using it in the serial mode I see the measurement is both more accurate (672mm exactly) and far more stable (it barely changes, occasionally I’ll see it jump up by 1mm). The stability isn’t as simple as the US-100 faking it by doing some smoothing on the values it returns – fetching readings every 100ms, if I wave my hand past the sensor I will see one lower number with perfectly accurate readings either side, so it responds quickly.

        This backs up all your findings I think, and shows how much better the US-100 is over the more basic models.

        The two flaw of US-100 for me are:
        1) it is a different size to the HC-SR04 (board is ~1mm less long, so the mounting holes are at a different distance, and the ultrasonic tx/rx devices have a different separation). Only bad if you wanted to use this as a drop in replacement where you have an existing housing or mounting to fit it to.

        2) The serial data returned is rather dumb, so it wouldn’t be hard to trip up – specifically the data returned doesn’t identify what it value it is returning (or which byte is the start value). This would be more of a problem if you wanted to get distance *and* temperature readings – otherwise you should be able to avoid problems with some heavy handed pauses to get in step with the US-100’s output.



      • stoduk says:

        [wish I could edit comments!]

        Update to my last post: there was a bug in the test using trigger/echo mode, that meant the result was scaled by 57/50. This means it was returning a value of (795 * 50 / 57 = ) 697mm. So it is still overestimating the distance, but by more like 25mm. The comments about variability still stand (6mm from lowest to highest reading).


      • stoduk says:

        Ages ago I wrote a library for using US-100 in serial mode, I’ve finally put is somewhere so others can benefit. Mentioning here as I figured people might come across this page when they are investigating what to buy.


  2. Pingback: My Swimming Pool project | How can I help you?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s