Source Code Request: Picaxe 28x1 Making the SRF05 follow movement/objects?

I would like to see if my sonar SRF05 actually works, so using the "default" setup from the "Start Here" robot, can anyone post a code that makes the Sonar, attatched to the Servo follow movement, say a hand or something?

pulsout trig,2 ‘ produce

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
debug range

Try the above. It will get a reading and if you keep the editor open and connected to the board it will display the value. The lower the value the closer the object. Next add your own code to move the servo and take another reading. Code stolen from Frits and editted :wink:

You cannot easily follow an

You cannot easily follow an object with a single sensor. That sensor just tells you a number that gives the distance from an object in front of it.

If the object move, the value you read will decrease but you don’t know the direction in which the object moved. The best you can do is check if the value is under a certain theresold and then turn randomly left or right to see if you can catch up the target.

If you have 2 sensors instead, you could probably see which one decreases first and so rotate in the other direction. It would not be very performant anyway, i think.

Else you dan use something more advanced like the cmucam vision sensor and track objects based on color

Nicola is absolutely right!

Nicola is absolutely right!

However, there are tricks to simulate & work around…

https://www.robotshop.com/letsmakerobots/node/770