Ultra sonic rang sensor

hi;

this is a program which is written at the page of the ultra sonic sensor:

[code]left_dist var word
right_dist var word
left var byte
right var byte
x var bit
y var byte

ECHO1 con 0
ECHO2 con 0
INIT1 con 4
INIT2 con 5
left_stop con 176
right_stop con 168

left = left_stop
right = right_stop

start:
if x=1 then skip1
x=1
pulsout INIT1,5
pulsin ECHO1,1,left_dist
left_dist=left_dist/74
’ pause 10
goto skip2
skip1:
x=0
pulsout INIT2,5
pulsin ECHO2,1,right_dist
right_dist=right_dist/74
’ pause 10
skip2:
if left_dist < 12 and right_dist < 12 then backup
if left_dist < 12 then turn_right
if right_dist < 12 then turn_left

forward:
left = left + 1 max left_stop + 20
right = right + 1 max right_stop + 20
for y=1 to 15
pulsout 2, (left * 5)
pulsout 3, (right * 5)
pause 30
next
goto start

turn_left:
left = left - 1 min left_stop - 20
'right = right + 1 max right_stop + 20
for y=1 to 5
pulsout 2, (left * 5)
pulsout 3, (right * 5)
pause 30
next
goto start

turn_right:
'left = left + 1 max left_stop + 20
right = right - 1 min right_stop - 20
for y=1 to 5
pulsout 2, (left * 5)
pulsout 3, (right * 5)
pause 30
next
goto start

backup:
for y=1 to 15
left = left - 1 min left_stop - 20
right = right - 1 min right_stop - 20
pulsout 2, (left * 5)
pulsout 3, (right * 5)
pause 20
next
left=left_stop
right=right_stop
for y=1 to 15
left = left - 1 min left_stop - 20
right = right + 1 max right_stop + 20
pulsout 2, (left * 5)
pulsout 3, (right * 5)
pause 20
next
goto start[/code]

but i dont know the connection that is compatible with this program so can you show how to connect the ultra sonic sensors with the bot board II and the arrangement of t he pins a s shown in the program and the jumper position…also can you clarify what is meant by (echo1 con 0 )…

It appears like this code is setup to have two outputs on pins 4 and 5, that send out the pulse. And one input pin on pin 0 to receive the echos.

Since you did not mention which range finder or provide a link to it, it is hard to tell you how to do the actual wiring. Also need to know if the device runs with +5 volts or not. If it does, then my guess is that there are at least 5 pins on this sensor. You will need to make a connection to a +5v Pin on the BB2, plus a connection to ground, plus 3 signal pins that are connected to P0, P4 and P5). Not sure if your device comes with wires or not?

Kurt

hii kurt we work on this project together

so first of all we use more than one Ultrasonic Range Sensor
and here is its link

lynxmotion.com/Product.aspx? … tegoryID=8

second we use the Bot Board II
and here is its link

lynxmotion.com/Product.aspx? … egoryID=66

and which we want to know is how to connect the these sensors to the bot board II as the 2 input pins are on the same pin 0 also the output pins are 4 and 5, which are far from pin 0, as we are using
the Ultrasonic Range Sensor Cable - 8"

here is its link
lynxmotion.com/Product.aspx? … egoryID=44

which u get what i mean and help me
thanks in advance
:slight_smile:

Sigh… Perhaps you could provide a link to where the code is posted…

It looks like SRF-04 code. But the echoes are received on one pin. If memory serves there is a way using diodes to save an I/O pin. I’m not up to a wild goose chase this morning…

actually it is the SRF-04 code
and here is the link to this code

lynxmotion.com/Product.aspx? … tegoryID=8

scroll down till information then click on the word here then u will have the code
thanks alot :slight_smile:

What processor are you running this on? The code was written for a Basic Stamp. It looks like it was setup to have two sensors. Is that what you want as well?

On something like that Atom Pro, you should probably simply use two pins per sensor and use the cable that you can purchase that has two IO pins plus the power and ground pin.

Kurt

actually i’m using basic atom pro 28
and using 2 pins for each sensor but also the program is not working at all .
i’m connecting each sensor to 1 input and 1 output, +ve and ground to the input pin.
so i dont know whats wrong and why its not working ???

Your code is for the BS2!

You are using an Atom Pro… There is your first problem.

I found the Atom Pro code by clicking on the forum:

Bot Board & BASIC Atom / Pro

Atom Pro example code (sensors / sound)
viewtopic.php?f=4&t=4714

Two links to threads with working Atom Pro code…