Ultrasonic Sensors in Robotics

When I first became interested in robotics, I had no idea where to start. I didn’t know which sensor to use. I didn’t know how to use an ultrasonic sensor with Arduino or Raspberry Pi.

I wish there had been a list detailing the ultrasonic sensors that can be used in robotics and are compatible with Arduino and Raspberry Pi boards.

On this page, we compiled them in a brief overview.

If you think I’ve left an important one out, please leave me a note in the comments or send me an email.

This page is still a work in progress and subjected to change in the future! This page was last edited on 21.05.2020

We use ultrasonic sensors in robotics when we want to detect obstacles in extreme conditions since the sensor is not affected by dust, moisture, and dirt. Also, an ultrasonic sensor can be used in a dark environment since the light does not affect an ultrasonic sensor’s detection ability.

In robotics, the ultrasonic sensors are used in applications such as:

  • object detection
  • detect the position of an object
  • tracking an object

We saw the advantages of an ultrasonic sensor. We go further to understand the limitations of a sensor that uses sound waves to detect objects.

The sensing accuracy of an ultrasonic sensor may be affected by soft materials, the temperature of the environment, and the noise of a wide frequency range. We can improve the accuracy of sensing by compensating the environment’s temperature and filtering the sensor’s output.

List of ultrasonic sensors

HC-SR04

The HC-SR04 Ultrasonic Sensor

  • The distance measured: between 2 and 400 centimeters;
  • Input: Trigger Signal 10us TTL pulse;
  • Output: Echo Signal Output TTL level signal, proportional with range;
  • Update rate: 40KHz;
  • Measuring Angle: 15 degree;
  • Ranging Accuracy: 3mm;
  • Power supply: 5V with a peak current of 15mA;
  • Link to buy: Amazon;
  • HC-SR04 Datasheet;

The HC-SR04 is an inexpensive sensor that is very easy to use with a microcontroller board such as Arduino or a single-board computer that runs Linux like the Raspberry Pi. It is by far the most used ultrasonic sensor in robotics and automation projects.

  • Detection range for HC-SR04 with Arduino and millis() – This is an introductory tutorial that requires an HC-SR04 sensor and an Arduino board. This tutorial will teach you how to connect the sensor to Arduino and read the data returned by the sensor.
  • Arduino – HC-SR04 ultrasonic distance sensor – From this tutorial, you will learn how to use the “Ultrasonic.h” library to read the data returned by the sensor. With a single line of code, you can read the data returned by the sensor in your preferred measurement unit.
  • HC-SR04 Ultrasonic Range Sensor on the Raspberry Pi – HC-SR04 can be used with any version of the Raspberry Pi board. In this tutorial, you will learn how to connect the sensor to Pi and how to use Python to display the distance measured by the sensor.
  • RPi: HC-SR04 Ultrasonic Sensor mini-project – If you want to build an IoT application, you need an Internet connection. Connecting an Arduino board directly to the Internet is a solution, but depending on the project needs, it is often not the best answer. In this tutorial, you have an example of how you can return the distance detected by the HC-SR04 sensor using the libraries for Arduino and the Raspberry Pi board.
  • Measure Distance using Ultrasonic Sensor | Pi4J | JAVA | Pi – If you need automation, Java, and IoT, in this tutorial you have an example of how you can access the full I/O capabilities of the Raspberry Pi via Java and read the distance returned by the ultrasonic sensor.
  • Wiring ESP8266 nodeMCU with HCSR04 Ultrasonic Sensor – For IoT applications, a much cheaper resource than Arduino and Raspberry Pi is the ESP8266 module. With a more limited capacity than an Arduino or a Raspberry Pi, the ESP8266 nodeMCU is a board that can be connected to the Internet to read the values returned by the ultrasonic sensor. In this tutorial, you will learn the steps required to connect HC-SR04 to the nodeMCU and write the script needed to read the values returned by the sensor.
  • Improve ultrasonic range sensor accuracy – There is a simple way to improve the accuracy of the sensor. From this tutorial, you will learn how to calculate the distance between the sensor and an object applying the ambient temperature. In this tutorial, MagicByCalvin describes in a few words the physical phenomenon that improves the measurement precision of the distance detected by the sensor. In addition to the ultrasonic sensor, a temperature sensor will also be included.
  • Remove impulse noise from ultrasonic sonar data – The accuracy of the HC-SR04 sensor can be improved. Taking into consideration the ambient temperature, we can improve the precision of the measurements. Besides the temperature compensation, an impulse noise reduction method can also be applied to ultrasonic sonar data. This tutorial will teach you how to implement the median filter to remove impulse noise from ultrasonic sonar data.

Parallax PING)))

  • The distance measured: between 3 and 300 centimeters;
  • Input trigger: positive TTL pulse, 2 µs min, 5 µs typ;
  • Echo pulse: positive TTL pulse, 115 µs minimum to 18.5 ms maximum;
  • Update rate: 40 kHz;
  • Measuring Angle: 20 degree;
  • Power supply: 5V with a peak current of 35mA;
  • Link to buy: Parallax;
  • Parallax PING))) Datasheet;

PING))) differs from other sensors by using a single pin for trigger and echo. For example, the HC-SR04 uses a separate pin for trigger and echo. The sensor can detect objects in the range of 3 centimeters to 3 meters.

The PING))) sensor is compatible with an Arduino and Raspberry Pi board. Below you find the tutorials and resources needed to start working with PING))) for both development boards.

  • Ping Ultrasonic Range Finder – This is a basic tutorial for PING))). From this tutorial, you will learn how to use an Arduino UNO board and several current wires to power the sensor and read the values returned by the sensor.
  • Raspberry Pi and Parallax Ping))) – Raspberry Pi can also read the values returned by the Ping sensor. In this tutorial, you will find instructions for connecting the sensor directly to the Raspberry Pi board and writing a Python script to read the values returned by the sensor.
  • Calibrate PING))) – Like any other ultrasonic sensor, the PING sensor))) can return wrong values. Errors appear for various reasons, such as noise or not a constant voltage supply. By calibration, the errors that may occur in sensor operation cannot be reduced to zero. But it can significantly reduce the external effects that can result in the return of the wrong values.

Maxbotix I2CXL-MaxSonar-EZ4

  • The distance measured: between 0 and 765cm;
  • Communication: I2C;
  • Resolution: 1cm;
  • Update rate: 42 kHz;
  • Power supply: for 3.3V operation is 2.7mA (50mA peak) and for 5V
    operation is 4.4mA (100mA peak);
  • Link to buy: Amazon;
  • Maxbotix I2CXL-MaxSonar-EZ4 Datasheet;

Maxbotix has launched a full range of ultrasonic sensors, but I will refer to only one sensor – the I2CXL-MaxSonar-EZ4.

It has a resolution of 1 centimeter and can detect objects at a distance of maximum 765 centimeters. It is a sensor designed primarily for indoor applications and has a high noise tolerance.

Below you will find a series of tutorials to use EZ4 with both Arduino and Raspberry Pi, and also with the Pixhawk controller.

  • How to Use an Ultrasonic Sensor with an Arduino – In this tutorial from Maxbotix, you can learn how to connect the EZ4 sensor to Arduino and read the values returned by the sensor. In this tutorial, you will find explanations for each piece of code and steps to connect the sensor to the Arduino board on the analog or digital pins.
  • Using an I2C?MaxSonar with an Arduino – The ultrasonic sensor can be connected to the Arduino using the I2C protocol. In this tutorial is used the “SoftI2CMaster.h” library. The library is adapted for use with the MaxSonar sensors.
  • Interfacing Ultrasonic Sensors with a Pixhawk or Ardupilot Mega (APM) – Pixhawk is a controller used in autonomous applications for multi-rotor copters and robots. Such a controller needs sensors to be able to detect obstacles on a particular route. In this tutorial, the Maxbotix sensor is used to allow an autonomous drone to land on the ground. Even though it is an ultrasonic sensor designed for indoor applications, the sensor also works in outdoor applications.
  • Interfacing a Raspberry Pi with an ultrasonic sensor to read serial data – In this tutorial you find the instructions to connect the EZ4 to Raspberry Pi and read the values returned by the sensor. On Raspberry Pi runs a Python script to read the distance between the sensor and the detected obstacle.

URM37

  • The distance measured: between 2 and 800cm;
  • Communication: RS232 or TTL-level output level;
  • Resolution: 1cm;
  • Accuracy: 1%;
  • Power supply: 3.3V? 5.5V with a peak current of 20mA;
  • Link to buy: DFRobot;

URM37 V4.0 is a sensor that integrates (in addition to trigger and echo) a temperature sensor for a more accurate measurement. The sensor can be used to detect objects between 2 and 800 centimeters with a resolution of 1 centimeter.

Devantech SRF04/SRF05

  • The distance measured: between 3 and 300cm for SRF04 // between 1 and 400 centimeters for SRF05;
  • Input Trigger – 10uS Min. TTL level pulse;
  • Echo Pulse – Positive TTL level signal, width proportional to range;
  • Resolution: 3-4cm;
  • Update rate: 40 kHz;
  • Power supply: 5V with a peak current of 50mA;
  • Link to buy: RobotShop SRF04 || SRF05;
  • Devantech SRF04/SRF05 Datasheet;

Under the name of Devantech are two ultrasonic sensors: SRF04 and SRF05. There is only one significant difference between these two sensors – the range varies between 3 centimetres to 3 meters for SRF04 and 1 centimetre to 4 meters for SRF05.

Both sensors have the same resolution that is 3-4 centimetres. The design and the operation mode of the SRF sensors are very similar to the HC-SR04 sensor.

Below you can find a tutorial to read the values detected by sensors with the Arduino board.

  • SRFxx Sonic Range Finder Reader – In this tutorial, you will learn how to use the “Wire.h” library to return the distances measured by the SRF sensor. Connecting the sensor to the Arduino board is through the I2C serial protocol.

Leave a Comment

Your email address will not be published. Required fields are marked *

Don't Miss Out!

Get the latest news, tutorials, reviews and more direct to your inbox when you subscribe!