Sonar, short for Sound Navigation and Ranging, is a technique that is based on sound propagation. Its first record in human history is in 1490 by Leonardo da Vinci: a tube inserted into the water was said to be used to detect vessels by placing an ear to the tube [1]. Over the years (mostly in 1900’s) this technique is being developing in many areas, mostly in navy, avoiding accidents and providing strategic information to the military system in terms of enemy location and so on.

Sonars are helpful for exploring and mapping the ocean once sound waves travel farther in the water than do radar and light waves, they are typically used helping Mariners to investigate the size and location of the objects. So that potential threats to the vessel can be identified and overcome [2].

In this article I will discuss about Sonar system principles and how it can easily be implemented and embedded in Arduino platform using Altair Embed (no handing-coding required).

Sonar system

There are two main types of Sonar systems [3]:

  1. Active: The wave propagates from the transmitter to the target and back to the receiver, analogous to pulse-echo Radar.
  2. Passive: The target is the source of the energy which propagates to the receiver, analogous to passive infrared detection.

As can be seen the Passive system has the advantage for those who do not want to be found. Otherwhise they cannot measure the range of an object unless it is used in conjunction with other passive listening devices. An example of an Active system (through the water) can be see below:

It is important to note that the sound velocity depends on where is traveling. For example in an idel gas depends only on its temperature and composition. Otherwise on the water sound speed is affected by the oceanographic variables like temperaturepressure and salinity.

Increasing water temperature, salinity and pressure (depth) the speed of sound in water will increase approximately following the items below [4]:

  • Temperature 1°C = 4.0 m/s
  • Salinity 1 PSU = 1.4 m/s
  • Depth (pressure) 1 km = 17 m/s

For curiosity purposes sound travels about 1500 m/s in seawater and much more slowly in air, at about 340 m/s. In the system of this article I will implement an Active system using that value (340 m/s) which is a “standard” value for atmospheric air at 20°C.

Arduino platform

1. Introduction

There is no better place but Arduino website itself to describe what it is. Basically is an open-source electronics platform based on easy-to-use hardware and software [5] where many type of electronics systems can be implemented and embedded using Arduino language (based on C/C++) on an Arduino IDE.

Over the years Arduino has been the brain of thousands of projects, from everyday objects to complex scientific instruments [5]. From these many applications, some softwares are able to embed models on Arduino (as Altair Embed in this system) basically using electrical signals to read inputs (buttons for example) and turn it into an output through its pins (turning on an LED and so on).

2. Sonar System – Hardware requirements

For the development of a static Sonar system using Arduino as a microcontroller (MCU) some essential hardware should be used:

  • Arduino
  • Breadboard and Jumper Wires
  • Ultrasonic Sensor HC-SR04

Basically the Breadboard and Jumper Wires are used to connect the elements in the electric circuit transmitting the electrical pulses from the Arduino to the ultrasonic sensor and vice versa, making easy a change on a circuit as needed.

I would like to discuss a bit more deeply about the Ultrasonic Sensor HC-SR04, from its specifications to how it calculates the sound propagation.

It is capable of measuring distances from 2 cm to 4 m with great accuracy (around 3 mm) and low price. This module has a ready circuit with transmitter and receiver coupled with 4 pins: VCC (5V power input pin); TriggerEchoGND), as can be seen in the left picture.

The operating principle of HC-SR04 consists in the emission of ultrasonic signals (mechanical waves with a frequency above 40 KHz) by the transmitter and the reading of the return signal (echo) of this same signal on the receiver, as described:

  1. The trigger pin turns high for 10 μs (trigged by an external source: Arduino) and then turns off: This action will trigger 8 pulses of an ultrasonic wave at frequency of 40 KHz from the transmitter. The receiver will wait for the wave to return.
  2. Once the wave is returned after it getting reflected by any object, the Echo pin goes high for a particular amount of time: The equivalent time (t) is taken for the wave that returns back to the sensor:

3. Sonar System – Schematics

Once HC-SR04 is the only external component in the system, it will be necessary just 4 pins on the Arduino: Supplier (5V), Ground (GND), Trig (9) and Echo (10) following the picture below (where I used Arduino UNO):

These pins will be set on Altair Embed in order to follow the logic presented in the plot above where was discussed the pulses regarding the sensor.

Note that you can choose the pins you want, just remembering to be careful with the circuit: Avoid short-circuit; Connections on pins that are not equivalent (Arduino-Breadboard); Parallel circuit.

4. Sonar System – Altair Embed implementation

Altair Embed is one of the softwares on Model-Based Development Altair’s platform. It is a tool for embedded systems which automatically generates a code from block diagram models and transfers to popular target MCU hardware (like Arduino). That is a great advantage once rapidly produces high-quality results, and can be used on interactive Hardware-in-the-Loop (HiL) testing.

To implement that, firstly you should declare the system configuration that you will work (MCU), as can be seen as a block “Arduino Config” where I set as Arduino Uno. Furthermore the core system is the main block “Compound” (blue), that was used as a super block and it is based on 3 blocks (as indicated by numbers) which are discussed below:

  1. Send Ping: These 3 lines of code create a 10microsecond gate signal sent to the trigger output pin
  2. Get Round Trip Time: Logic system to activate Echo pin due the return wave
  3. Serial output: Divide by 2 to get “one way” time, then, since sound travels at 340m/sec or 0.034cm/microsecond, multiply by 0.034 to get the distance in cm

On Embed (as Arduino IDE) is possible to use external libraries (normally implemented for specific reasons like sensors) in a way to facilitate the implementation even more. On that case for example I could use “#include “HCSR04.cpp” to call a ready library to read the distance. So there are several ways to implement (depends on your application and requirement conditions) in in your system. (This system in specific was based on that tutorial, with some changes).

Results

In order to analyze the Sonar principles on that system, I used 2 ways to evaluate the object distance in the assembly: Ruler; Embed Measurements (DisplayPlot). As can be seen in the video below the results are very reliable as expected, validating the system implementation:

It is important to point out that the idea of this article, besides discuss how a Sonar system works, is to explain how it can be easily implemented and embed on a real platform (Arduino) based on a block diagram logic contextualizing with real engineering applications.

However, nothing prevents it from being implemented through scripts, By the away there are many cool examples over the internet and they can be easily accessed in websites like GitHub where there are many open source scripts.

No alt text provided for this image

Please feel free to comment, or even contact me if you have some note about this model. I would like to share with you that my last articles besides being on my LinkedIn page, they are on Altair University as well (thanks Rahul for incentiving me on my articles). Finally, let me know if you would like to know something about the software that I’ve used. Thank you for your attention!

References:

  1. Fahy, Frank (1998). Fundamentals of noise and vibration. John Gerard Walker. Taylor & Francis. p. 375. ISBN 978-0-419-24180-5.
  2. https://www.etechnog.com/2018/12/applications-of-sonar-technology.html
  3. https://oceanservice.noaa.gov/facts/sonar.html
  4. https://dosits.org/tutorials/science/tutorial-speed/
  5. https://www.arduino.cc/en/guide/introduction

About João Marabisa

Technical Support Intern
Elevate your design skills, win prizes, and become an optimization rockstar! Learn More...
Elevate your design skills, win prizes, and become an optimization rockstar! Learn More...

Have a question or comment?

Post your comment/question on our user forum.