Let's Make Robots!

How to build your first robot - Part II - navigation


Your browser is not able to display this multimedia content.

Your browser is not able to display this multimedia content.

clean_navigation.BAS6.17 KB

This is Part II of How to build your first robot - tutorial.

you can just take the cool navigation-code in here and have fun with it, or you can follow the whole instruction, or the parts that you like. I try to make it as general and open as possible.

Here is part III of this tutorial - I recomend that you browse this as well!


You have made a robot, something like this: How to build your first robot

You have read my deep thoughts on how to move on with the programming "Don't program your robot.. Teach it!", and you have made tricks with your robot, messed around with it, had some fun and is ready to move on.

Perhaps you have tried out this little trick of seeing what your robot sees.

You have seen on the video of "Making Skiwalker", and seen on the pictures of "Yellow Drum Machine" (the pics in the bottom) - that you do not need much for materials to make a robot; Melt-glue, double sided tape, sticks, and you are go!

If so, this part II should be a breeze! You can make this robot in 45 minutes, no sweat.


First, let's make the robot on the picture above. Try to duplicate the main parts, that is the main task here.

It shuld not need much explantion, it is excaxtly like the one from How to build your first robot - only differences:

  • Instead of Sharp sensor, I use SRF05
  • The servo is a smaller one, and a fast one - you can get these in any size and speed
  • The gearing on the motors is lower, so I have a faster robot (though it is not a speed-king, lol)
  • instead of just taping it all together, I have used 3 sticks to form some sort of a "chassis"

The closer you get to this, the easier it will be to follow the rest, but of course you can just do it your way, with whatever parts you have etc.

In the first tutorial I wrote that you could make some fancy code for the robot.

I now present you for some code that I have made, it is what is used on the video. It is an example, there are thousands and millions of ways to evolve, you should do it your way. This is just to try to open your eyes, and share what I have learned after countless hours of trial and error.

Try to alter some of the numbers to tune in to your setup, and read the guidelines in the code. That way you can get a robot like the one on the video, and we are going to use that as a base for Part III in this tutorial...

Find the attached code in the top of the post.

.. And the screwdriver-trick on the video?

Well.. Look for places where the code says

servo Servopin,head

and add, just after it

servo 1,head

If you are adding another servo on pin 1.

Think about what to attach instead of the screwdriver?

Something with an LED on? And insert some on/off in the code for the LED? Or a fan? or.. :D


Stay tuned. This bot is getting more enhancements now..

And if some of the comments below does not make sense, please understand that I am changing this over time, so the comments may have been for an earlier text here :)

Thanks, and do post what robots you make, to inspire back. Thank you.

/ Fritsl

Comment viewing options

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

I was wondering about the speaker. I am using a mylar speaker and I need to know where to solder that speaker. DESPERATE HELP! I'm almost finished this robot and its my FIRST ONE!!!!!! All help appreciated.

BTW il probably post fotos.

With the clean_navigation code, I seem to have a problem. At the beginning, when I turned it on, the servo jiggles around a bit and then the wheels turn and nothing happens. No sensor pulse (from the led). But the sensor definitely works because when I used that sensor code in part 1 , the led started flashing. Its finished, fully built but I NEED HELP WITH THE CODE.

btw, the wheels go on and on and after a while, the servo jiggles again.


Hi Fritsl

Another great robot and tutorial :)

I have just a few questions I hope you can answer.

1) Should the clean navigation code work with the exact robot in the start here tutorial 1?
I have tried it but with no luck. I guess it is because I am using IR Sensor GP2D12? Can you advise on code modification for this?
  When I run the program the head moves to the left then it steps to the right (2 small steps) then it moves left again (1 small step) and at this point the wheels rotate forwards, and this is how it stays.

2) Line 202 gives me a syntax error
201- totalhalt:
202- low 4, low 5, low 6, low 7
203- return
  I got rid of the error by changing the comma's to colon's (low 4 : low 5 : low 6 : low 7)
 I ask this because you say that the code is exact as entered in the program and I would like to understand why I get the error.

Thanks again for all the great work you do here


1) No, the code should be adapted. It is not very often that you can take code from one robot and use it in another without modifications. Alone how you hooked up your motors will affect stuff.

If you use the sharp, you will have to adapt. And note that as far as I remember, the shapr returns higher values the closer an object comes. The SRF05 standard routine returns lower the closer :)

3) The editors are a little different on this, you can use low 4 low 5 low 6 low 7


low 4
low 5
low 6
low 7


low 4 : low 5 : low 6 : low 7

point is to set all them ports low ;)


Mostly I think you should understand the code, and then adapt it to your own project. It is the principle of looking around while driving, then acting if.. that is the point here :)

Just use the code in Pt1. Yes you are right. It doesn't work because of the code. It is made for the SRF05. The SRF05 has inputs and outputs blah blah. And for once ... Frits got it wrong. It's supposed to be low 4 : low 5 : low 6 : low 7. And if you want to use this code, you probably need an SRF05 and most likely, an SRF05 mounting brackets.


PS. If you need the mounts, if you are in America, I recommend Lynxmotion or Trossen Robotics.

... And this is my first post that help sombody :D :D :D

and I fixed my code problem.
how pixace work

Hi frits,

I've built this robot as my first one. First I downloaded the clean_navigator in the 28X1. The SRF05 turns from one side to the other than stops in the center only once,then the wheels are going backwards. The sonar doesn't detect objects and consequences are that there is no direction changes on the wheels.

I've done the SRF05 range test and it's ok. I also checked the motors polarities and directions according to the clean_navigator (forward ,reverse,spins and slides) and it's ok. I've been trying to study the code as much as I can but I don't find the problem. Hope you could give me a hint on that one,it would be appreciated from you. Thanks for your help and keep up the great work.

You must adapt the code to your own hardware inputs and outputs.

Thanks for your reply my friend ,got it work.