Acoustic Radar Display

34,922

456

41

Published

Introduction: Acoustic Radar Display

About: 55+ years in electronics, computers, and teaching ... now retired.

This instructable describes how to make an ultrasonic “radar-style” display using an Arduino microcontroller, an ultrasonic sensor, and a small stepping motor.

An optional sensor modification allows multiple objects to be detected with each ping.

Construction is simple ... all you need are two drills, a sharp knife, a pair of side-cutters , and a soldering iron.

Photo 1 shows the basic parts. The “insert” shows a random-dot test pattern. Dots representing primary objects are shown in red ... dots representing secondary objects are shown in blue.

Photo 2 shows the assembled unit.

Photo 3 shows an actual screen shot of seven objects. [1]

The video clip shows the unit in operation.

[1]

The azimuth and distance of each primary object are shown in red. Any echo from a secondary object is shown in blue. Without the sensor modification you will only see the red objects.

Since the sonic pulses expand in a cone-like manner, distant objects appear wider. The actual bearing of each object is the midpoint of each continuous (red or red/blue) line.

Continuous lines containing both red and blue dots are a single object, part of which is in shadow.

Step 1: Wiring Diagram

The wiring diagram is shown in photo1.

An optional modification is shown in photo2. This modification is the SAME for both the HC-SR04 and the HY-SRF05 ultrasonic sensors and allows multiple echos to be detected. [1]

[1]

For a full explanation see my instructable https://www.instructables.com/id/Enhanced-Ultraso...

If you have an HC-SR04, the integrated circuit to which you solder the wire is labelled U2

Step 2: Parts List

The following parts were obtained locally:

  • 1 only plastic food container.
  • 1 only sub-miniature micro-switch.
  • 1 only male header strip (used for attaching wires from sensor).
  • 1 only female header strip (used to mount sensor).
  • 1 only piece of 20 gauge aluminium (scrap) sheet 40mm x 55mm.
  • 6 only 9mm nylon spacers tapped 3mm.
  • 3 only cable-ties.
  • 13 only 3mm x 6mm bolts.
  • 1 only 3mm nut.
  • 4 only 4mm x 10mm bolts.
  • 2 only 4mm nuts.

The following parts were obtained from https://www.aliexpress.com/

  • 1 only Arduino Uno R3 microcontroller complete with USB cable.
  • 1 only 28BJY-48 5 volt stepping motor complete with ULN2003 controller.
  • 1 only 5mm bore brass hex shaft to wheel coupler for model cars.
  • 1 only HY-SRF05 (or HC-SRF04) ultrasonic sensor.

Step 3: How It Works

Mechanical

All parts are housed inside a plastic food container. Power is obtained from your USB port.

The circuit comprises an Arduino, an ultrasonic sensor, a stepping-motor, and a micro-switch for moving the sensor to its “home” position. The micro-switch is necessary as it is not possible to rotate the stepping motor by hand due to its 64:1 internal gearing.

When first powered up the Arduino rotates the sensor to its “home” position, as determined by the micro-switch, then “polls” the display until it gets a response.

The 28BJY-48 stepping motor has a “stride angle” of 5.625/64 degrees which means that 1 degree steps are not possible (even though our graticule is labelled 0..180 degrees).

Fortunately, 180/stride-angle = 180*64/5.625 = 2048 which is evenly divisible by 8. If we increment a number from 0..2048 and divide by 8 there are 256 occasions when we get a remainder of zero ... we simply send a “ping” whenever the remainder is zero. This equates to a “ping” every PI/256 radians or 0.703125 degrees.

Software [1]

The display then takes control and continually asks the Arduino to supply the following data:

  • Azimuth
  • Distance1
  • Distance2
  • Direction

The “distance(s)” for each “azimuth” are then displayed on the screen. The “direction” information is used to create the illusion of “dots” appearing behind the “beam” as it rotates.

The Arduino automatically moves to the next “ping” position whenever data is sent to the display.

[1]

The “Processing 3” software used for writing the display may be downloaded from https://processing.org/download/

Processing 3 supports 2D and 3D graphics and is very similar to the Arduino IDE (Integrated Development Environment). The main visual differences are a “graphics window” when the code is running and the use of a “draw()” function instead of the Arduino “loop()”.

Step 4: The Display

The Graticule

I chose to create a 180 degree graphics display as it provides a “radar shadow” in which to stand while experimenting. Such a display is also compatible with a servo motor should I wish to use one. A full 360 degree display can be obtained by tweaking the code.

The following photos explain how the graticule was created:

Photo 1

  • The graticule comprises a number of “arcs” and “lines”. Angled labels are shown in this photo but were later dropped in favour of horizontal text which is easier to read.

Photo 2

  • Shows a red line depicting the “beam”. The text in the label is now horizontal.

Photo 3

  • The red line in photo 2 has been rotated 0..180 degrees through 256 azimuth positions. In this photo the outer parts of the graticule are not covered as the beam-width is too narrow. This results in some strange artifacts.

Photo 4

  • Increasing the beam-width has eliminated these artifacts.

Photo 5

  • Random dots have been introduced to represent primary (red) and secondary (blue) echos. The range, which can be changed, has been set to exactly 100cm to match the display. A fading beam pattern has also been introduced. The technique used to create this “fading beam” is explained further on.

Photo 6

  • The color scheme has been changed to add a touch of realism.

Animation

The animated portions of the graphics display use 3D graphics to greatly simplify the code. To understand how this is possible let’s draw a “30 degree line” of constant radius from an XY start coordinate of (0,0).

2D graphics requires the use of sin(30) and cos(30) to calculate the XY end coordinates of the line:

X=cos(30)*radius = 0.866*radius
Y=sin(30)*radius = 0.5*radius
line(0,0,X,Y);

3D graphics doesn’t require the use of trigonometry. We simply rotate the XY grid coordinates about the Z-axis then draw a horizontal line .... no maths required!!!

pushMatrix();		//preserve our current grid coordinates
rotateZ(radians(30));	//rotate our XY grid coordinates about the Z-axis
line(0,0,radius,0);	//draw a “horizontal” line on the rotated grid
popMatrix();		//restore our grid coordinates

Either way works but this second method lends itself to “ping” intervals of PI/256 radians.

Fading Lines

The fading beam pattern uses a clever technique found at https://forum.processing.org/two/discussion/13189...

The beam is given its own virtual screen. Prior to drawing any line the “alpha” (opacity) of all previous lines is reduced by a small amount. Ultimately the earliest lines become invisible which gives the illusion of a fading “fan” pattern.

This virtual screen, which is never erased, is then merged with the contents of the main screen whenever the display is refreshed.

Step 5: Mounting Bracket

The drilling template for a suitable mounting bracket is shown in photo 1.

Position the two outer “mount” holes below the transmit (T) and receive (R) sensors. I find that best results are obtained if the sensor rotates around the receive (R) sensor rather than midway between the two sensors. The three holes allows you to experiment.

Details of how to “cut and fold” aluminium may be found in my instructable https://www.instructables.com/id/How-to-Cut-Fold-...

Step 6: Assembly

USB cable-hole

Do not try and drill a cable-hole for the USB connector though the side of the plastic container as plastic tends to split and chip. Instead, melt a hole using the tip of a hot soldering iron then trim with a sharp knife. Take care not to breath the fumes.

Shaft-extender

Replace one of the 4mm “grub-screws” in the shaft-extender with a 4mm x 10mm bolt. This bolt is used to activate the micro-switch.

Micro-switch

Position the micro-switch such that it is activated by the 4mm bolt when the shaft rotates in a clockwise direction.

I used two turns of 20 gauge copper wire to attach the micro-switch to the case as 2mm nuts and bolts were not readily available.

Remaining components

Layout is not critical. The motor shaft was positioned centrally. The Arduino and motor controller were mounted on nylon spacers which allow the wires to be tucked underneath.

Mounting the sensor

Photo 1

  • shows the sensor assembly. The HY-SR0F-5 socket has been fashioned from a female-header socket. All unwanted pins have been removed and a 3mm hole drilled through the plastic. The header is then attached to the bracket by means of a 3mm nut and bolt.

Photo 2

  • shows a side view of the sensor assembly. The wires from the header are cable-tied to the bracket. This “strain-relief” prevents unwanted cable movement as the sensor rotates. Note also the “grey” wire attached to pin 10 of IC1. This wire is optional and feeds the secondary echos to the Arduino.

Attach the sensor assembly to the shaft extender after the micro-switch has operated following power-up. The shaft is then in its “home” position.

Step 7: Software Installation

Install the following code in this order:

Arduino IDE

Download and install the Arduino IDE (integrated development environement) from https://www.arduino.cc/en/main/software if not already installed.

Processing 3

Download and install Processing 3 from https://processing.org/download/

Acoustic Radar Sender [1]

Copy the contents of the attached file, “acoustic_radar_sender_2.ino”, into an Arduino “sketch”, save, then upload it to your Arduino Uno R3.

Close the Ardino IDE but leave the USB cable connected.

Acoustic Radar Receiver

Copy the contents of the attached file, “acoustic_radar_receiver.pde” into a Processing “Sketch”.

Bugfix

[1]

"acoustic_radar_sender_2.ino" fixes a "scan-creep" bug in "acoustic_radar_sender_1.ino" . My thanks to https://www.instructables.com/member/newtoeu/instr... for pointing it out.

Step 8: Testing

Click the top left “Run” button in your Processing window and your project will burst into life.

Try detecting different objects:

  • Nearby objects require the transmit (T) sensor to be low to prevent the "beam" passing over the top.
  • More distant objects require a larger surface area as much of the acoustic energy is lost as the beam spreads ... plus the return echo also spreads.
  • Experiment with the three mounting holes.
  • You may wish to try mounting the sensor vertically so that the transmit and receive beam-widths overlap.

  Click here   to view my other instructables.

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest
    • Clocks Contest

      Clocks Contest

    41 Discussions

    Can of Watties!!! This guy's a Kiwi!

    Excellent Instructable, lots of fun and very well presented. It looks like the radar prefers the Baked Beans...

    Thanks.

    1 reply

    Thanks for commenting :)

    0
    user
    tmoir

    23 days ago

    How far can those sensors detect objects? Can they work at say 2-3 metres distance?

    1 reply

    The HC-SR04 and HY-SRF05 sensors have a maximum range of around 4 meters. I have restricted this range to 1 meter in my code.

    Super project! Got it working without too much trouble; thank you *lingib*, for an excellent instructable.

    The two main issues I had before getting this project to work were ... figuring out how to tweak the "Processing" sketch to talk to the Arduino IDE, and a bad connection, which was totally my own fault (too embarrassing to explain, but ... I forgot to solder something(s)!) All of this was achieved by following the instructable to the letter. This success emboldened me to try running the project on a Pro-Mini, which worked just fine ... then I tried a Nano, which worked fine as well. The idea behind trying these smaller footprint Arduinos being that I had the notion to build the whole thing into a smaller box.

    The box I eventually chose had enough space inside to accommodate a couple of Li-ion cells in series to power the stepper; I preferred this to driving it directly from the Uno. I also included an on/off switch for this battery stepper supply, and a reset push switch for the Uno (handy for me to have, given my method of repeat testing). Right now I have a completed, as specified, functional Acoustic "Radar" unit that has only one cable; USB to the PC.

    One thing I'd like to try is to extend the range beyond 1m ... some guidance on this would be appreciated?

    Being introduced to "Processing" has been a big step forward for me so, thanks for that, too.

    I have a small video https://vimeo.com/276095498 of the first success on the bench, before the sensor was mounted, so it's just sitting there static.

    Just remembered to mention this as well ... only for fun, I added a small laser head to the rotating sensor that tracks (points to) the reflecting surface ... nice visual effect and, as I say, just for fun.

    I really enjoyed building this project ... thanks again lingib :-)

    2 replies

    Well done ... your video is great :)

    To double the 100cm radius to 200cm radius:

    (1) double the numbers in

    // ----- label the arcs

    fill(255); //light gray text

    textAlign(LEFT, BOTTOM);

    text("100cm", +5, -width/2); //"100cm"

    text("75", +5, -width/2*0.75); //"75cm"

    text("50", +5, -width/2*0.5); //"50cm"

    text("25", +5, -width/2*0.25); //"25cm"

    // ----- new code follows

    text("200cm", +5, -width/2); //"200cm"

    text("150", +5, -width/2*0.75); //"150cm"

    text("100", +5, -width/2*0.5); //"100cm"

    text("50", +5, -width/2*0.25); //"50cm"

    (2) Change the following four code lines in

    // =======================

    // plot data

    // =======================

    stroke(255, 0, 0); //set data1 color to red

    if (Ping[index][0]>100) Ping[index][0] = 1000; //hide by printing off-screen

    ellipse(width/2*Ping[index][0]/100, 0, 5, 5); //plot data1

    stroke(0, 0, 255); //set data2 color to blue

    if (Ping[index][1]>100) Ping[index][1] = 1000; //hide by printing off-screen

    ellipse(width/2*Ping[index][1]/100, 0, 5, 5); //plot data2

    // ----- new code follows

    stroke(255, 0, 0); //set data1 color to red

    if (Ping[index][0]>200) Ping[index][0] = 1000; //hide by printing off-screen

    ellipse(width/2*Ping[index][0]/200, 0, 5, 5); //plot data1

    stroke(0, 0, 255); //set data2 color to blue

    if (Ping[index][1]>200) Ping[index][1] = 1000; //hide by printing off-screen

    ellipse(width/2*Ping[index][1]/200, 0, 5, 5); //plot data2

    Thank you lingib, this modification works as it says on the proverbial tin! Your swift response to my wish has been superb; thank you for that too.

    Best wishes ...

    You're welcome ... thank you :)

    0
    user
    MikeK270

    Question 26 days ago

    I followed your tips about the connected state and it does appear to be connected, i'm seeing values like you showed in your screenshot, but my motor still isn't moving. The UNL lights aren't lighting up at all. I ran a separate test of the UNL and stepper, worked fine. Is it possible it's because there's no statement to include a library? I'm so close :-)

    2 more answers

    No additional libraries are required ... the code should just run.

    Check that:

    (1) Check that the link on the ULN2003 controller is present. Removing that link removes power to the motor and you won't see any lights.

    (2) Check that 5 volts is getting to the ULN2003 controller.

    (3) None of the lights will light when the motor is first turned on as all outputs will be zero.The motor should be rotating if your display is seeing code. Check, with a voltmeter that voltage is appearing on the IN1, IN2, IN3, IN4 input pins. (I have not tried this but you could disconnect say IN1 and apply 5 volts directly, via a 560 ohm .. or 1000 ohm resistor to that pin ... if the controller is okay then one of the lights should light).

    (4) Is it possible that something is jamming the motor shaft?

    (5) Check also your wiring ... I tape my arduino connections as they have a habit of falling out. It only takes one pin.

    0
    user
    MikeK270

    Question 4 weeks ago

    Love this idea and am trying to make it but running into issues. My motor doesn't move (I tested it on it's own, works fine) and the terminal is just repeating S over and over and I just can't figure out the issue. I don't have a microswitch so I set that value to false like in the comment but still no luck. Any suggestions? Oh I also am using the 04 ultrasonic w/out the optional connection if that helps.

    3 more answers

    Just a thought ... try increasing the motor parameter in the arduino heading from Delay=2; to say Delay=4;

    I had one motor that refused to start when the delay time was small.

    Lingib's answer about the serial list was correct and resolved the issue. Note for anyone having this problem that code is in the processing sketch, not ino. my motor isn't working still but I think I know the issue there. I'm getting graphical display from processing now with accurate distance so that's awesome. Great instructable!!!!

    Your motor will not move until a link is established.

    To establish a link you need the same baud speed at both ends and the correct port number in the the setup(){} line "myPort = new Serial(this, Serial.list()[0], Baud_rate);" A list of port numbers will appear when you run the processing application. A screen shot is attached.

    The first line of the attached screen shot reads [0] "COM5". This [0] matches that in the myPort code above. If you see several port numbers try each in turn.

    The fact that you are seeing more than one "S" indicates that your arduino is not receiving the "S" acknowledgement from the terminal . You should only see the first "S" from the arduino (this is the "S" in the second line of the attached screen shot).

    You could also try lowering the baud speed at both ends but I found that 9600 bauds is too slow when passing data ... but it may help when when debugging.

    Once a link is established you will only ever see lines of data that are then split up into "Azimuth, Distance1, Distance2, Direction". You should only ever see one "S" from the arduino. You will never see any "S" characters from the terminal.

    The "void serialEvent(Serial myPort){}" function is the key to the handshaking. Try adding some println() statements to this routine to verify the state of the "Connected" flag and to check that the terminal has actually sent an "S" to the arduino.

    The handshake sequence is as follows:

    Power up the arduino first. The arduino will move to the "home" position then continuously send a letter "S" to the terminal. Now run the processing terminal.

    On receiving a letter "S" the terminal sets a "Connected" flag high then sends an "S" to the arduino requesting data..

    For each received "S", the arduino will rotate the motor eight steps to the next "ping" position then send a data string to the terminal. The terminal will not send another "S" until it has finished processing the last line of data. The motor will not move again until another "S" is received from the terminal.

    Hopefully this will help identify the problem.

    data.jpg

    would anything change if i used a faster motor?