This is a page deticated to the Ping sensor.

What is the Ping)) sensor and what does it do?

The ping sensor is an ultrasonic range finder. It uses Sonar to find the distance of an object with the accuracy of 2-3 cm. It emits sound to high for the human ear to hear. The sound hits an object and comes back to the sensor while the sensor times how long it takes the sound to come back.

Useful Information:

Power Requirements:



Ground | +5V | IO

How to set it up:

No resistors or capacitors are required for set up.

Ping schematic
  • I/O Pin is the input/output.
  • Vss is ground
  • Vdd is power (+5Volts)

Sample Program:

In this program, the I/O wire goes to P 15.

This program is for Basic Stamp 2.

' Smart Sensors and Applications - PingMeasureCmAndIn.bs2

' Measure distance with Ping))) sensor and display in both in & cm

' {$STAMP BS2}

' {$PBASIC 2.5}

' Conversion constants for room temperature measurements.

CmConstant CON 2260

InConstant CON 890

cmDistance VAR Word

inDistance VAR Word

time VAR Word



PULSIN 15, 1, time

cmDistance = cmConstant ** time

inDistance = inConstant ** time

DEBUG HOME, DEC3 cmDistance, " cm"

DEBUG CR, DEC3 inDistance, " in"



This program is for the Propeller Microcontroller.

  • Note that the I/O wire requires a 1K Ohm resistor.*

 * Ping))) Object V1.1 *
 * (C) 2006 Parallax, Inc. *
 * Author: Chris Savage & Jeff Martin *
 * Started: 05-08-2006 *
 Interface to Ping))) sensor and measure its ultrasonic travel time. Measurements can be in
 units of time or distance. Each method requires one parameter, Pin, that is the I/O pin that
 is connected to the Ping)))'s signal line.
 --------------------------REVISION HISTORY--------------------------
 v1.1 - Updated 03/20/2007 to change SIG resistor from 10K to 1K


TO_IN = 73_746 ' Inches

TO_CM = 29_034 ' Centimeters

PUB Ticks(Pin) : Microseconds | cnt1, cnt2

Return Ping)))'s one-way ultrasonic travel time in microseconds

outa[Pin]~ ' Clear I/O Pin

dira[Pin]~~ ' Make Pin Output

outa[Pin]~~ ' Set I/O Pin

outa[Pin]~ ' Clear I/O Pin (> 2 μs pulse)

dira[Pin]~ ' Make I/O Pin Input

waitpne(0, |< Pin, 0) ' Wait For Pin To Go HIGH

cnt1 := cnt ' Store Current Counter Value

waitpeq(0, |< Pin, 0) ' Wait For Pin To Go LOW

cnt2 := cnt ' Store New Counter Value

Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1 ' Return Time in μs

PUB Inches(Pin) : Distance

Measure object distance in inches

Distance := Ticks(Pin) * 1_000 / TO_IN ' Distance In Inches

PUB Centimeters(Pin) : Distance

Measure object distance in centimeters

Distance := Millimeters(Pin) / 10 ' Distance In Centimeters

PUB Millimeters(Pin) : Distance

Measure object distance in millimeters

Distance := Ticks(Pin) * 10_000 / TO_CM ' Distance In Millimeters


For further information and resources please visit the Parallax website:

Ping))) Ultrasonic Distance Finder