910-28015B

Copyright © Parallax Inc. PING))) Ultrasonic Distance Sensor (#28015) v2.0 2/4/2013 Page 7 of 9
Example Program: PingMeasureCmAndIn.bs2
This program for the BASIC Stamp 2 displays distance measurements in both inches and centimeters in
the BASIC Stamp Debug Terminal. The example program can be downloaded from the 28015 product
page at www.parallax.com. The BASIC Stamp Editor software, which includes the Debug Terminal, is a
free download from www.parallax.com/basicstampsoftware.
' 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
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP
Copyright © Parallax Inc. PING))) Ultrasonic Distance Sensor (#28015) v2.0 2/4/2013 Page 8 of 9
Propeller Microcontroller
{{
***************************************
* 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.
┌───────────────────┐
│┌───┐ ┌───┐│ Connection To Propeller
││ PING))) ││ Remember PING))) Requires
│└───┘ └───┘│ +5V Power Supply
GND +5V SIG
└─────┬───┬───┬─────┘
│ 1K
└┘ └ Pin
--------------------------REVISION HISTORY--------------------------
v1.1 - Updated 03/20/2007 to change SIG resistor from 10K to 1K
}}
CON
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
Copyright © Parallax Inc. PING))) Ultrasonic Distance Sensor (#28015) v2.0 2/4/2013 Page 9 of 9
The ping.spin object is used in an example project with the Parallax 4 x 20 Serial LCD (#27979) to
display distance measurements. The complete Project Archive can be downloaded from the Propeller
Object Exchange at http://obex.parallax.com. The Propeller Tool software can be downloaded from
www.parallax.com/propellertool.
───────────────────────────────────────
Parallax Propeller Chip Project Archive
───────────────────────────────────────
Project : "ping_demo"
Archived : Tuesday, December 18, 2007 at 3:29:46 PM
Tool : Propeller Tool version 1.05.8
ping_demo.spin
├──Debug_Lcd.spin
├──Serial_Lcd.spin
└──Simple_Serial.spin
└──Simple_Numbers.spin
└──ping.spin
Reources and Downloads
For additional example code downloads and links to videos, tutorials and robotics projects that use the
Ping))) Ultrasonic Distance Sensor, visit www.parallax.com and search “28015.”
Product Change Notice
Rev A: original release
Rev B: resonator added to the SX-28 co-processor circuit. No changes to functionality
Rev C: SX-28 co-processor changed to PIC16F57. No changes to functionality.
Revision History
Version 2.0: Added revision history. Removed Javelin Stamp examples. Added URLs for programming
software. Added Product Change Notice section with PCB revision information.

910-28015B

Mfr. #:
Manufacturer:
Parallax
Description:
Processor Accessories Ping Ultrasonic Sen plus Protector Stand
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet