skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home MP3 Player 8051 Tools All Projects PJRC Store Site Map
You are here: Teensy Teensyduino Libraries Ping

PJRC Store
Teensy 3.1, $19.80
Teensy 2.0, $16.00
Teensy++ 2.0, $24.00
USB Cable, $4.00
Teensy
Main Page
Teensy 3.1
Getting Started
How-To Tips
Code Library
Projects
Teensyduino
Reference

Ping Library

The Ping library, by Caleb Zulawski, let you use the Parallax Ping))) ultrasonic sensor to make distance / range measurements.

Download: Ping.zip (version 2.0)

Hardware Requirements

Ping requires just 1 pin, and power.


Parallax Ping))) connected to Teensy 2.0

Basic Usage

Ping myPing = Ping(pin);

Create an instance of the Ping library. You can connect many "Ping)))" sensors, with each on its own pin, and create instances of the library for each.

myPing.fire();

Make the ultasonic measurement.

myPing.microseconds();

Read the measurement in microseconds.

myPing.inches();

Read the measurement, converted to inches.

myPing.centimeters();

Read the measurement, converted to centimeters.

Example Program

Open the example from File > Examples > Ping > Ping_Library_Example.


Ping Measuring 3 Inch Distance


#include <Ping.h>

Ping ping = Ping(13);  // Ping signal on pin 13

void setup() {
  Serial.begin(115200);
}

void loop(){
  ping.fire();
  Serial.print("Microseconds: ");
  Serial.print(ping.microseconds());
  Serial.print(" | Inches ");
  Serial.print(ping.inches());
  Serial.print(" | Centimeters: ");
  Serial.print(ping.centimeters());
  Serial.println();
}

Using Teensy 3.0 with 5 Volt Ping

The Parallax Pin requires 5 volt power, which can be taken from Teensy 3.0's VIN or VUSB pins.

A Ping sensor was tested with Teensy 3.0 to determine if it strongly drives the pin with 5 volts. The result appears to be Ping driving approximately 3.9 volts into the Teensy 3.0 pin. Using a 470 ohm or 1K resistor in series with the Ping signal may be wise (to limit the current Ping could inject into Teensy 3.0's built-in protection diodes), but at least the Ping output is not so strong to force Teensy 3.0's pin beyond 3.9 volts.


Teensy 3.0: Start Pulse is 3.3 Volts, Response Pulse is 3.9 Volts.

More Details

Please refer to the official Ping library documentation for more details.