| SensComp to BS II Example Last Modified: 2006-11-01 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() Introduction In this example, a Parallax Basic Stamp II uses a 6500 Polaroid Ranging Module combined with a 7000 Series transducer to measures distances to obstacles. The stamp tells the sonar module to emit a "ping" and measures the time it takes to receive an echo. It converts this time to a distance in inches and displays the value using the debug feature in the Basic Stamp II development software. Circuit Schematic In the following schematic, the Basic Stamp II is powered by an external 9V battery. The sonar module has its own supply of four AA batteries (Ni-Cad, NiMH, or Alkaline). (Be sure the sonar module power supply and Stamp power supply share a common ground connection.) According to the Polaroid specs, The sonar module uses up to 2A during the transmit period and up to 100ma after the transmit period. Do not use the Stamp's 50ma onboard regulator to power the sonar module. The only additional component required for this circuit is a 4.7K pull-up resistor for the ECHO output from the sonar module. ![]() The test circuit also included a jumper wire between pin 3 and pin 15 of the socketed chip on the sonar board. The jumper eliminated some noise problems as described in the Polaroid Sonar Ranging Primer . Source Code This example code is written in PBASIC. ' polaroid-1.bs2
' POLAROID RANGER TEST PROGRAM
' 6-30-2000
'--------------------------------------------------------
' variable declarations
dist var word ' working variable for distance calculation
'--------------------------------------------------------
' constant declarations
ECHO con 15 ' sonar module echo detection output
INIT con 14 ' sonar module control input
' 1 starts a measurement
' 0 resets the module
settle con 1 ' delay to ensure proper initialization
delay con 20 ' time between sonar samples
' CONVERSION FACTORS
'
' The RCTIME command returns the round-trip echo time in 2us units
' which is equivalent to the one-way trip time in 1us units.
'
' Taking sonar samples in rapid succession may occasionally cause
' a false measurement. A delay between starting a sonar reading
' and measuring the time to receive an echo helps prevent this
' problem. Because of this delay, the distance calculation
' must include an offset.
'
' distance = (echo time + offset time) / (conversion factor)
'
' use 74 for inches (73.746us per 1 in)
' use 29 for centimeters (29.033us per 1 cm)
convfac con 74 ' use inches
offset con 700 ' (determined experimentally)
'--------------------------------
' main loop
loop:
gosub sr_sonar
debug dec dist,cr
pause delay
goto loop
sr_sonar:
high INIT
pause settle ' be certain that ECHO is low
rctime ECHO,0,dist ' wait for ECHO to go high
low INIT ' reset module
dist=(dist+offset)/convfac
return
Revision History:
| ||||||
Related Links: | |||||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved. |