Let's Make Robots!

HY-SRF05

Anyone have experience with HY-SRF05 (blue board) and picaxe28x2?

Im newbie in robots and picaxe, so to enter in this world i decide to make my first robot with picaxe28.

The problem is i cant put the robot working i think the problem is with the srf05 because the robot don t detect any obstacles.

the code i use is below:

(thanks for the member who make this code)

Symbol dangerlevel = 50 ' how far away should thing be, before we react?
symbol turn = 300 ' this sets how much should be turned
symbol servo_turn = 700 ' This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance
symbol trig = 3 ' Define output pin for Trigger pulse
symbol echo = 6 ' Define input pin for Echo pulse
symbol range = w1 ' 16 bit word variable for range
 
main: ' the main loop
pulsout trig,2 ' produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ' measures the range in 10uS steps
pause 100
let range = range * 10 / 58 ' multiply by 10 then divide by 58
readadc range, b1
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
else
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines
 
 
nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 6 : low 4 : low 7
goto main
 
whichway:
gosub totalhalt ' first stop!
 
'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc range, b1
'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc range, b2
 
' Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
 
body_lturn:
high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return
 
body_rturn:
high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return
 
rturn:
servo 0, 100 ' look to one side
return
 
lturn:
servo 0, 200 ' look to the other side
return
 
totalhalt:
low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second
return

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks for all for the replies.

I found the problem, thanks to JAX!

The problem is in the version of the Picaxe.

Solve the problem with:

symbol trig = b.3

...

Thanks again JAX

Hi.

I bought the same sensor few weeks ago.

One question, what do you use in your project:

  • the AXE401 (28X2 board)?
  • the AXE401 (28X2 board) + AXE408 instant robot shield?

I have been using AXE401+AXE408 and still not work (just only hear one kind of sound, even if I bring my hand close of the sensor).

http://www.subirimagenes.cl/?v=2013012218.jpg

Also, I have been reading many topics and forums about two modes of wires connection (5 pins // 3 pins)

I did test with this:

 

'symbol trig = 3            ; Define output pin for Trigger pulse (A, M, X, X1 parts)

'symbol trig = s.5        ; Define output pin for Trigger pulse (M2, X2 parts)

symbol trig = b.3        ; Define output pin for Trigger pulse (M2, X2 parts)

'symbol echo  = 6           ; Define input pin for Echo pulse (A, M, X, X1 parts)

symbol echo  = c.6       ; Define input pin for Echo pulse (M2, X2 parts)

symbol range = w1          ; 16 bit word variable for range

main:

    pulsout trig,2         ; produce 20uS trigger pulse (must be minimum of 10uS)

    pulsin echo,1,range   ; measures the range in 10uS steps

    pause 20                ; recharge period after ranging completes

let range = range * 5 / 58

if range>20 then

sound S.12, (50, 20)

elseif range<10 then

    sound S.12, (112, 1)

    endif

    goto main ; and around forever

 

 

You say you have 

  • VCC
  • Trig
  • Echo
  • Out
  • GNC

Ok, GNC is gnd, got that one, but what is "OUT"? Do you have 5 pins on this unit? Also, we seem to be using "HY-SRF05" and "SRF05" interchangably.

What exactly are you using here? Is it a $4 sensor from Ebay --a HC-SR04? Or is it a SRF-04 that you paid $30 for? How many pins total come out the top, and what do you have these pins connected to on your picaxe?

 

No, not an HC-SR04, not an SRF005, but a whole new beast. I almost bought some these things thinking that you can make it run as a three-pin sonar. It doesn't help that sellers will even say that they will. The confusion mostly lies in the out pin. It is not a mode pin like the PING where you ground it and it changes how the sensor operates. From what I understand the out pin goes high when an object is detected, like for a parking sensor setup. Functionally it is otherwise identical to the HC-SR04.

I don't have this sensor but maybe it needs a longer trigger pulse to get it going. Try 3 instead of 2.

Also you have taken code from the X1 series of chips. With the X2 you can't define pins with just a number. You need port.pin like:

symbol trig = b.3

or

symbol trig = c.3

i make some tests and the problem is in comunication with the srf05 and the picaxe.

i tried this code to test the ultrasonic module:

symbol trig = 3   ' Define output pin for Trigger pulse
symbol echo = 6 'Define input pin for Echo pulse
symbol range = w1 ' 16 bit word variable for range

main:
pulsout trig,2 ' produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ' measures the range in 10uS steps
pause 10 '‘ recharge period after ranging completes
'‘ now convert range to cm (divide by 5.8) or inches (divide by 14.8)
'‘ as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range * 10 / 58' ‘ multiply by 10 then divide by 58
debug range' ‘ display range via debug command
goto main '‘ and around forever

in a debug mode nothing happens, so the problem maybe is in the srf05 or this version maybe has a different connection.

the connections of this ultrasonic module are:

VCC

Trig

Echo

OUT

GNC

Anybody have similar problems?

 

Take things step by step. First connect only the sensor to the picaxe and write some code to just read the distance from the sensor. Same thing with the servo...

You seemed to have changed the code at random. 

First off, you are using a digital sensor, but all the "readadc's" have been left in the code. Also, it seems that the word variable "range" is being used as a variable and also a pin number.