Using the Ping Sonar with an Arduino

Introduction

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:

Change the Baudrate to 9600

By default, Ping communicates at a baud rate of 115200. For flexibility, our ping-arduino example uses SoftwareSerial, which is only compatible with a maximum baud rate of 9600. To use the example we will need to flash the 9600 baud firmware via Ping-Viewer. If your microcontroller has an extra hardware serial port, you may use that instead at 115200 baud.

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-arduino-02

4. Open Firmware panel by opening the top left () menu, then clicking the circuit icon ().

ping-arduino-03

5. Set the version to the latest 9600b firmware.

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).

  • If something didn’t work, reference Device Recovery on this page.

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