SODAR (Sonic Detection And Ranging)

A video is available to support this article;

Introduction and background
RADAR (as used extensively, effectively and greatly developed further) back in World War 2 is the detection of objects using radio waves giving both the direction of the object and it’s range (distance) from the RADAR system. The acronym RADAR (which can be spelt as lower case ‘radar’) stands for RAdio Detection And Ranging. SODAR uses the exact same techniques as RADAR and gets the same results but uses sound as the wave being send rather than radio. So logical SODAR stands for Sonic Detection And Ranging.

You’ve probably all seen the movies of war ships with rotating oval dishes atop of the bridge (or some other high structure). These are the RADAR systems (well mostly, some may just be ‘listening’, but that’s another story). As they rotate they send out an Electromagnetic (radio) pulse and listen for the echo of it returning to the same dish. The time it took to return determines the distance of the object that reflected the wave and its direction is given by the direction that the radio dish is pointing in at that moment. Now you may point out that the dishes move quiet quickly (and they do) but bare in mind that radio waves move at the speed of light (as they are a form of light) and the round trip time from sending out to the returned echo is phenomenally short.

So combining the direction of the dish with any returned pulse gives you distance and direction to the object. Of course the dish continues rotating sending out and listening for returned pulses to build of a picture of the surrounding area. The principles of RADAR were well before WW2, almost from the earliest radio experiments were made but it took the invention of the cathode ray tube to provide a display to make an effective complete system.

Why not always use SODAR instead of RADAR?
As a general rule the higher the frequency of a wave the less it spreads out over distance. Sound (being a very low frequency) would be hopeless over distances of a few tens of meters (at absolute best). It’s also extremely slow compared to Radio and longer distances (as would be present in naval or other areas) would exaggerate the time for a pulse to return.

So why are you creating a SODAR system?
Because sonic modules are cheap, plentiful and for my needs they only need to operate over a short distance (around a meter) so the resolution will be fine and speed to returned pulse will not be an issue. Radar modules are available but will be used for another project another day.

How will you be using this system?
This article will create the basic system which you can then use as you wish but the obvious system use (and the one I will be creating) would be for collision avoidance for a small robot. But that will be another article.

Kit List
Arduino Nano (or Uno)
HC SR04 ultrasonic sensor
2003(a)  stepper motor driver board
Stepper Motor (28BYJ-48)
128×64 pixel OLED Display (SSD1306 driver)
IR (infra-red) obstacle avoidance sensor
Power source for motor, i.e. Battery pack, power supply or 9v battery
Some wires
Breadboard

The completed project
Before we move on to the design, build and software for this project I thought it might be handy for you to look at the completed breadboard build to get a feel for where we are going. Look at the picture below:*

You can see the sonic module has been mounted on-top of a stepper motor. A stepper motor is a type of motor that we can control with extreme precision, so it’s direction would be known at any one time. This means that when a pulse is returned I will know in what direction the object lies. Just underneath the white card (which attached to the sonar sensor) is the obstacle avoidance sensor. It’s not easy to see but it’s a small cheap board that has a infra-red emitter and a sensor. The idea is if some of that IR is reflected back it will pull it’s output low and if nothing in front (no IR reflected) then it will be pulled eye. Above when the motor is finding it’s start position the card will go over the sensor and send the output low. We detect this and stop the motor, knowing that we are now at the start point ready to start out scan from a known position.

There’s also a small display which maps out the objects as they are found in both distance and direction. Obviously we need a computer to control the motor and do the distance calculation etc. etc. and in this instance I’ve chosen an Arduino Nano. In addition there is a small stepper motor controller board which the Arduino uses to control the stepper motor. More on driving stepper motors can be found in this article. Note that the stepper motor needs a separate power supply (in this case an additional battery pack) due to the high current used by them.

The circuit diagram.

Building and testing
The first thing we will do is add the display and get that working. You need an IC2 128×64 oled (SSD1306 driver). These are very commonly available. Other displays could be used but adapting them for use is beyond the scope or support of this article.

Installing the OLED display libraries
The first is the driver for 1306 OLED display driver chip. Go to the Arduino IDE library manager, “Sketch->Include Library->Manage Libraries”. Type “Adafruit SSD1306” into the search field. The first result should be the one you require titled “Adafruit SSD1306 by Adafruit”. Install this. The second library is the “Adafruit GFX library”, type in “adafruit graphics” and install the graphics library. 

The screen I’m using is shown below and if you can source one like this with the same connections you should have very few problems getting yours up and running using this tutorial.

Connection Table
The following shows the connections required to the various Arduino models, in addition after the table is the connection diagram specific to the Arduino Nano.

OLED ConnectionNano ConnectionPro-MicroUnoLeonardo
VDD5V5V5V5V
GNDGNDGNDGNDGND
SCKA53A5 (*)#3
SDAA42A4 (*)2

Load and upload the Adafruit example routines, these can be found at “File->Examples->Adafruit SSD1306->ssd1306_128x64_i2c”. You should see a demo being drawn on your screen.

Not working?
If it works then great, you’ve done it, if not then the most likely culprit(apart from bad wiring – please check!) is the I²C address of your display. These tend to be either 0x3C or 0x3D. So first try changing the line

#define OLED_Address 0x3C

to

#define OLED_Address 0x3D

and recompile/upload. If this doesn’t work it may be that your screen has an even different address to the most common ones.  In this case you need to load a  I²C address scanner onto your Arduino to get the screen to return its address and use that one in the code above. See this Link for a suitable scanner.

Adding the stepper motor
Add the stepper motor driver chip and stepper motor as shown in the circuit diagram. Note again that the stepper motor needs a separate power supply (in this case an additional battery pack) due to the high current used by them. Failure to do this can cause resetting of your MCU.

Stepper Software Library
To make things easier there are several libraries available for your MCU if you use the Arduino IDE as your development environment (and indeed even if you don’t but I won’t be covering them in this article).  By default the Arduino IDE already includes a library and all you need do to use it is add the following line to your code

When the code below is uploaded the stepper motor should move to the left and then to the right.

Adding the ultrasonic module
Add the module to the motor using a little hot glue (or perhaps another method of attaching it of your choice) as shown below;

Left Stop Sensor
In order for the stepper motor to know where the far left is we add in a stop sensor. This is a simple infra sender and receiver module, when the ultrasonic module cuts the beam the Arduino knows the motor has gone as far left as we wish it to go. See the photo below.

Wire it up as shown in the circuit diagram and test by uploading the test code below

When you run this code you should see a “1” on the screen with nothing in front of the sensor but if you out something in front it should change to a “0” (preferably something light coloured, a finger usually works). This shows that when the object is near it reflects the infra-red light coming from the sender on the module back to the sensor. There is a sensitivity adjustment on the modules if you are having problems.

If this all works ok you need to place it somewhere where the moving sonar sensor will reflect the beam back. I placed a small piece of white card onto the sensor and bent the IR Sender LED and receiver up to make it more convenient. The picture and video at the top of the page make this more obvious to see. Upload the code below and you should see the motor move to the left until it breaks the stop sensor and then move to the right 180 degrees and then keep on repeating this pattern. If it doesn’t find the stop sensor after half a turn or so then it will stop and do nothing. This is to prevent a tangle of wires if something goes wrong.

Bringing it all together
The code below will make your build behave like a RADAR (SODAR), it will sweep the ultrasonic sensor left and right taking readings as it goes and displaying what it finds on the screen.

The way it works is it first (in the set-up routine) sends the sonar module to the left most position. Once this is found it continues with the main loop. Within the main loop it moves approx 6 degrees to the right, sends an ultrasonic pulse and waits for any reflection. If it gets one it works out the distance to the object and scales it onto the screen in the right position. If it receives no echo after the sonic pulse has travelled 50cm’s then it is deemed that nothing is in that direction. Experiment by placing objects around the SODAR for it to detect and display. You can see in the main loop that the routine returns a distance to the object or 0 if nothing is found. If you want to use this circuit in a collision avoidance system you would need to write code to avoid that object and look for gaps in the returned data to guide your robot through.

What Next?
There are two main things I want to do, one is to build a robot that can use this circuit to detect its surroundings and drive around obstacles or through gaps. However the “resolution” of the device is poor, the further away an object is the larger it appears. This is due to the normal way waves spread out. The solution to this is to either focus the beam more or to use a higher frequency (such as microwaves etc.). This is something I plan to look into.

The other is to add a larger more colourful screen instead of the small two colour one used. Watch this blog for what comes next!