
A couple of you have requested an
interface to the some sort of sonar device. I chose the SRF04
because its cheaper then the SRF08 and a bit faster. The SRF04
will cost you between $30-$40.
How it works
you supply a pulse from low to high
and back low again on the trigger lead to start the SRF04. This
sends out a pulse. The SRF04 will then pause for a few ms then
deliver a pulse on the output line. To read the range we measure the
length of this pulse. We will use the pulseout command to trigger
the sensor and the pulsein command to read the echo time.
pulseout
triggerport,10
pulsein
echoport,1,range
By setting the PULSEINSCALE to 5 we
will get a reading that indicates rough inches.
Hookup
Before you hookup the unit you will
have to attach wires/header or some other connector to the SRF04 as it
comes with 5 holes that must be soldered.

Here I attached a 5
pin right angle header.

Schematic 1
This program is
just a real simple example of how to read the SRF04. It will display
the distance in inches in the debug window.
Program
(download it here)
'SRF04 Demo
dim range
const ping 1
const echo 0
output ping
low ping
PULSEINSCALE = 6 'Will give reading in ~inches
loop:
pulseout ping,10
pulsein echo,1,range
print range
pause 100
goto loop
Parts
Easy RS232 Driver
Athena
7.5V AC Adapter
9 Pin Cable
Breadboard and
Wire Kit
Breadboard
Regulator
SRF04 Module: Sorry you will have to do an internet search on this
one.