Using the Ping Sonar with an Arduino

Today we’ll be learning how to use Arduino to read and print data from the Ping sonar!

The Ping Sonar is a multipurpose single-beam echosounder. It can be used as an altimeter for ROVs and AUVs, for bathymetry work aboard a USV, as an obstacle avoidance sonar, and more. It communicates over serial, so it’s compatible with an Arduino or any other microcontroller.

Parts and Tools

Main components used in this guide.

Main components used in this guide.

You Will Need

You will also need:

Firmware Version and Baud Rate for Old Ping Sonars

The ping1d-simple sketch used in this guide uses the SoftwareSerial library for compatibility with Arduino boards that have only one hardware serial interface, like the Arduino Uno. SoftwareSerial requires the Ping to communicate at 9600 baud. The latest Ping firmware will automatically switch to the correct baud rate.

  • New Ping Sonars, with all black body, already have the latest firmware installed and you can skip this section. You do not need to install new firmware.
  • PING2-SONAR-R1-RP-2
  • If you are using an older Ping Sonar, with black body and blue transducer ring, you will need to install the newest auto-baud rate firmware using the instructions below.
  • PING-SONAR-R3-RP 1
  • If you are using an Arduino board that has multiple hardware serial interfaces, like the Arduino Mega, you can use the hardware serial interface at 115200 baud instead of SoftwareSerial. You do not need to change the firmware. Use the ping1d-simple-mega sketch as an example instead.

Updating the Ping Firmware

1. Connect Ping to your computer via BLUART or any USB to Serial Adapter

  • Follow the instructions in the Ping Sonar Quick Start.

2. Open Ping Viewer.

3. Verify that your device is communicating properly before going further.

ping-arduino01

4. Open Firmware panel by clicking on the gear icon, then click on the third icon with the circular arrow.

ping-arduino-00

5. Set the version to the latest ‘auto’ firmware (ping-V3.28_auto or newer). If you are already on the latest firmware you can skip to the next section.

6. Ensure that your device is connected securely to a reliable USB port. It is important that it does not lose connection during the next step.

7. Click “Firmware Upgrade”. This will take a couple minutes.

8. When it completes, you should be able to see data streaming again (but slower now).

Wire Connections

ping-arduino-04-fixed

1. Connect the red (5V) wire of Ping to a 5v pin on the Arduino.

2. Connect the black (Ground) wire of Ping to a Ground pin on the Arduino.

3. Connect the white (TX) wire of Ping to pin 9 (SoftwareSerial RX) on the Arduino.

4. Connect the green (RX) wire of Ping to pin 10 (SoftwareSerial TX) on the Arduino.

ping-arduino-05-fixed

ping-arduino-6-fixed

Arduino Library Installation

Via Arduino IDE

1. Open Arduino IDE

2. Open the Library Manager via Sketch > Include Library > Manage Libraries

ping-arduino-07

3. Search for “Blue Robotics ping-arduino” and click “Install”

ping-arduino-08

Via ZIP File

1. Download the latest zip here.

2. Unzip the file, and place the folder in your Arduino/libraries folder

Using the Simple Example

To make sure everything is working, let’s upload the simple example sketch to the Arduino. This one gets the depth and confidence readings from Ping, and prints them out to the console.

1. Open the ping1d-simple example via File > Examples > ping-arduino > ping1d-simple

ping-arduino-09

2. Upload the code to the Arduino

ping-arduino-10

3. Open the Serial Monitor via Tools > Serial Monitor

ping-arduino-11

4. Set the Serial Monitor’s baud rate to 115200 (the baud rate of the Arduino)

ping-arduino-12

We’re done! If everything worked, you should now see the output in the Serial Monitor. This shows the distance (in mm) and the confidence percentage.

ping-arduino-13

Advanced Usage

There are many ways to interact with the Ping sonar beyond just getting the depth. You can find out more with these resources:

A good way to get started with more advanced usage is by uploading our advanced example with the same process as above:

1. Open File > Examples > ping-arduino > ping1d-advanced

2. Click Upload

3. Open the Serial Monitor and ensure the baud rate is set to 115200

4. You should see this data printed in the serial monitor:

ping-arduino-14