Datasheet
Page 4 · Smart Sensors and Applications
√ Place an object (like a water bottle, box, or paper target) 15 cm from the front of the
Ping))) sensor.
√ Enter, save, and run PingTest.bs2.
√ The Debug Terminal should start reporting a value in the neighborhood of 450.
Values of 438 to 466 mean the distance is between 15 and 16 cm.
√ Move the target to a distance of 30 cm from the Ping))) sensor and verify that the
value of the
time variable doubled.
√ Point your Ping))) sensor at a variety of near and far objects and observe the time
measurements.
√ Multiply your measurements by 0.03434 to convert to centimeter measurements, and
verify that the measurements are correct.
' PingTest.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
DEBUG HOME, "time = ", DEC5 time
PAUSE 100
LOOP
Your Turn - Displaying Centimeter Measurements
The next activity will introduce how to derive constants like 0.03434 for converting the
echo time measurements to centimeters and other units. But first, let's look at how the
PBASIC
** operator makes it possible to multiply the time variable by a value like
0.03434. To convert 0.03434 to a value the
** operator can use, multiply it by 65536,
and use whatever's to the left of the decimal point. Since 0.03434 × 65536 = 2250.5,
we'll use 2251 with the
** operator for the time to centimeter conversion. Here's the
conversion statement with the constant we just figured along with a
DEBUG command to
display the centimeter value.
time = time ** 2251
DEBUG CR, "Distance = ", DEC4 time, " cm"