contact info:
info@jenlewinstudio.com

Studio Address:
437 University Ave
Boulder CO 80302
303-859-4345


BX-24 and the SRF04 prox sensor
Click here to download the SRF04 BasicX code zip file


Goto http://www.acroname.com/robotics/info/examples/srf04-1/srf04-1.html for wiring diagram and purchasing info.

'---------------------------------------------------

'The following code uses the SRF04 ultrasonic range finder (a sonic proximity
'sensor, that can sense a range of 3cm to 3 meters. The SRF04 can be purchased
'from www.acroname.com

'the following example wires the SRF04 echo output pin to pin 13 of the BX
'and the pulse trigger input to pin 14 of the BX.


dim distance as integer
dim pulsewidth as integer


Sub Main()
call flashme(6)

do

call pulseOut(14, 15.0, 1)' must be brought high for a min of 10microseconds (10us)
'Call PulseOut(Pin, PulseWidth, State)
'PulseWidth:Time interval. Units are in seconds, range is
'about 1.085 ms to 71.1 ms.
'State:Specifies either high (1) or low (0) pulse


pulsewidth = pulseIn(13, 1)

'Call PulseIn(Pin, State, PulseWidth)
'state :Specifies either high (1) or low (0) pulse
'pulsewidth: Time interval. Units are in seconds.
'Valid range is about 1.085 ms to 71.1 ms.
'Timeout returns 0.0.
'or PulseWidth = PulseIn(Pin, State)


Pulsewidth = pulsewidth \ 74
'use 74 to convert the distance to inches
'use 29 to convert distance to cm

debug.print; cStr(pulsewidth)
delay(0.01) 'Must have a min pause of 10 microseconds


loop

End Sub