Step 49:


Enter this code into your editor, and press F5 while the robot is connected:


readadc 0, b0


goto main

Now take your hand in front of the robot´s head and notice how the variable b0 changes value. You can use the knowledge gained to decide what should happen when (how close things should get before..)

You may notice how things start to go "wrong" if stuff is too close to the "eyes"; The Sharp is made to work with stuff that is from 10-80 CM away. Things that are closer appears to be further way, which can be quite a challenge to program.

You can get many other distance sensors that do not have this problem. However the Sharp is the cheapest, and easiset to program, so that's why I made such a "bad" choise for you, sorry ;) Look around and see what everyone are using, before you decide for an upgrade.

Now I advise you to put your robot up on a matchbox or similar, as the wheels will start turning.

Enter this code into your editor, and press F5 while the robot is connected:

high 4

low 5

One of the wheels should turn in one direction. Does your wheels turn forward? If so, this is the instruction for that wheel to turn forward.

If the wheel is turning backwards, you can try this:

low 4

high 5

To turn the other wheel, you need to enter

high 6

low 7

(or the other way around for opposite direction.)

What happens here is that by using only the options available to the microcontroller; power on or off (High / Low) on it's pins, it is commanding the motor controller to set motor A or B in forward or reverse mode.


low 4

low 5

low 6

low 7


stops all motors

The servo you have already tried.

All the way to one side is:


servo 0, 75 wait 2


the other side is: 


servo 0, 225 wait 2

- and center:


servo 0, 150 wait 2

Here is a small program that will (should, if all is well, and you insert the right parameters for high/low to suit your wiring to the motors) make the robot drive around, stop in front of things, look to each side to decide which is the best, turn that way, and drive towards new adventures. In the code I have made socalled remarks: Stuff written to explain you what is going on.

You can write such comments or remarks yourself in the code, it is a good idea to keep track.

They are writen with a ' sign. However, copying this text from here might alter that to something else, and you will have to fix that manually, sorry. Your programming editor has color codes, that will help showing you what it recognizes as comments and what as code.


Symbol dangerlevel = 70 ' 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

main: ' the main loop
readadc 1, b1 ' read how much distance ahead
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
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

gosub totalhalt ' first stop!

'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
readadc 1, b1
gosub totalhalt

'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
readadc 1, b2
gosub totalhalt

' Decide which is the better way:
if b1
gosub body_lturn
gosub body_rturn
end if

high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt

high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt

servo 0, 100 ' look to one side

servo 0, 200 ' look to the other side

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



With some clever programming and tweaking, you can make the robot drive, turn it´s head, make decisions, make small adjustments, turn towards “interesting holes” such as doorways, all working at the same time, while driving. It looks pretty cool if you make the robot spin while the head is turning ;)



Fun time

You could also attach a lamp or LED to pin 2 & ground, and write (remember LED´s need to turn the right way around)

High 2


to turn on the lamp, and 


Low 2

to turn it off ;)

- How about a Laser-pen, mounted on an extra servo? Then you could make the robot turn the laser around, and turn it on and off, pointing out places.. you can do anything now :)

Pressing "Help" in the programming editors brings out all sorts of interesting tutorials and info!


Perhaps try this:

Pull out the servo, and take up the yellow chip. Insert the Darlington that you took out earlier. Hook up the speaker to the 2 pins above where the servo was, tat is output 1. And throw in the LED, or whatever it was that you found on output 2. Then program it something like this:


sound 1, (100, 30)

high 2

wait 1

low 2

sound 1, (105, 60)


That should make a sound and turn something on, make a new sound and turn it off again.


Or the more interesting, make sure the Sharp is still in, hook a speaker up to pin 1, and then program this:



readadc 0, b0

sound 1, (b0, 2)

goto noise


Here is the program I used to make the video in the intro :)

Ce ya!
(I hang out on letsmakerobots.com most of the time)

Where do you get all of the things from like literally that's why I don't know
<p>where could i buy the shorting blocks to ship to finland, there is a website called pololu which is the only one i could find which ships internationally but i dont trust it so please help me!</p>
<p>go to usa</p>
<p>Pololu is a great site for robot components and other electronic components. I've used them many times for a different projects and I've always been satisfied with the quality of their parts and the depth of their documentation.</p>
<p>wow it is so easy they told you the wrong thing dudes</p>
<p>how do u code it. like when u conect it to your computer how does it work</p>
<p>can i use a ping insted of a sharp</p>
<p>I bought your project and i want to go a step forward, instead of using the board for sensor robot i want to make a remote control walking robot. I need your help!! How could i contact u privately. thank you :3 Chaknithg@gmail.com Facebook:Chak Nith</p>
<p>sorry i didnt made it yet</p>
I love ur project and o want to make it,please please tell me the price of this project<br>
<p>its about 300 euros if you do not live in USA</p>
<p>Niiiiicccccceeee! You're great! Thanks for this ible:)!</p>
<p>Cool dude!</p>
<p>Hello fritsl what kind of solder do you need does it matter because ive never really heard of a solder and imgonna buy one and I wondered if there is a certain type of solder or solder iron</p>
<p>Thank you so much for the instructable, I just finished it!</p><p>The only issue I had was in the programming, where in the sample program you used &quot;readadc1&quot;, unlike the &quot;readadc0&quot; used when introducing the range of values from Sharp. So &quot;readadc1, b1&quot; caused b1 to always be 255, b/c the analog pin 1 was connected to V by the shorting block. Seems simple now, but took me ages to pinpoint this as the problem! I hope this can help someone else! :)</p>
hi! where can i buy the materials?? does it have online selling? <br>and how much will it cost?
This is really cool. Thank you for adding this. Will the store(solarbotics) be getting your kit in stock any time soon? I was also wondering if this kit is RoHS compliant? Thanks.
where do i find these?
where do i find these?
I&nbsp;have wanted to build a robot like this for a long time, but I have been putting it off because of all the support behind Arduino. Would it be possible to get advice on how to build this same robot, but with an Arduino. It seems like I&nbsp;am going to invest in a microcontroller, I&nbsp;should do so with something that I&nbsp;am more likey going to do more with besides the bot... any suggestions? I&nbsp;am not dissing Pic, just so much maker momentum seems to be with Arduino...<br />
Check out Scratch for Arduino!
I always wanted to do this walkthrough with an Arduino based setup, as a parallel, so people could chose.<br /> <br /> However, things are just that more &quot;complex&quot; with Arduino. One line of code makes a servo go to a direction with Picaxe. And that is even one simple and logic line of code, that your dog can understand:<br /> <br /> servo 1, 150<br /> <br /> With Arduino, you'd have to upload a library first, and then deal with many lines of hard-to explain-for-the-novice-code and syntax.<br /> <br /> - For doing the excact same thing. And that's just the servo, things just get so much hairier. I want people to get a good start, not to meet a wall.<br /> <br /> But I like Arduino, and every now and then I think about how to present it as &quot;your first project&quot;, in the spirit of the walkthrough above. I Just have not found a way yet :)<br /> <br /> There are, however, tons of walkthroughs on how to get started with Arduino. I am just focusing on how to get started building robots here. And for that purpose, I have chosen the components listed, because I believe they are the best mix for a starter who wants to dive in to fun-zone right away :)<br />
I have had experience with Parallax's Basic Stamp board. As you said with Pic, it takes only a line of code for a servo to go in a direction. Same with Basic Stamp, it doesn't require much more then pic, PULSIN 1, 150. I believe that is the right way to write it. I haven't used it in awhile. But Basic Stamp can be very easy. <br> <br>http://www.parallax.com/ <br> <br>You can go here to find more about it. <br> <br>I never have used Picaxe or Arduino before. I hope to use both. <br> <br>This is still very good.
Thanks, that makes a lot of sense. Do you think Picaxe is the way to get started with Microcontrollers in general?<br />
You could also put a 5v voltage regulator on it and use 6 rechargeable batteries, you would get 5v and for a longer time because you could use more batteries.
you are a genius. you make robotics easy to understand. thank you<br>
Not that your robots not good (i actually luv it) but i think i can make an easier and cooler one. 1 rc car and 1 picaxe 08 motor controller board. Thats Practicelly all it takes. And sensors for a good and cool robot. Nice job though.
could you give me the artist's name who sings the song in part 1 of your instructional video?<br><br>I tried looking it up on Google and there are people in forums wondering the same thing (they heard it on a you tube video) but no answers so far.<br><br>Great song and great video
can i use an ultrasonic range finder instead of the sharp, without having to change the program?
wow,its ousom,great
how to do that?????
Yeah! Mario Bros!<br> <br>
fritsl, i need help, im 12 years old and very smart, i bought the robot and put it together but im having trouble programming it, sometimes when i type in engine codes like: high 4 low 5 high 6 low 7 i hear the engines moving but the wheels arent, the wheels arent touching anything either. ill try recharging the batteries but dont think thats it. Plz respond, i need help and this was a pretty decent investment for me. all i have left to do is figure out the right engine codes and ill be done completely, unless the wheels wont turn like now. THANKS!! and to all who are wondering if they should uy this I RECCOMEND IT!!! =]
Great job, with one caviat though.&nbsp; If you use a lighter to activate heat shrink tubing, you need to keep the flame from having too much direct contact with the tubing.&nbsp; A heat gun, or a hair dryer,&nbsp;works better and is more appropriate anyway.&nbsp; I've caught heat shrink on fire before by using a lighter.&nbsp;
I do not agree with you, but thanks for the points, now people can try both ways :)<br />
I'm sorry you don't agree, but you admitted yourself, that you burnt the wires.&nbsp; You can deny reality all you want but eventually it bites you in the butt.&nbsp;&nbsp; Good luck.<br />
Pkranger88, Your opinion may be based on the type of heat shrink tubing you are using.&nbsp; There are several types of heat shrink tubing available, and they are not all created equally.&nbsp; One of my favorites is polyolefin.&nbsp; I&nbsp;personally use heat shrink tubing almost every day of my life, and have done so since the early 80's.&nbsp; I carry a Bic lighter for that explicit purpose.&nbsp; While in some cases a heat gun is more appropriate, in many cases it is not.&nbsp; Your version of &quot;reality&quot; does not necessarily coincide with someone else's.&nbsp; In my experience and my &quot;reality&quot; you'd have to be a real dunce to catch good quality shrink tubing on fire!&nbsp; The fact that the author disagrees with you doesn't indicate a denial of reality.&nbsp; It may simply indicate a difference in experience and or skill level.&nbsp; Good luck to you as well.
Most heat shrink tubes are flame retardant anyway, I usually use my soldering iron to shrink them.
Once you get the hang of it it's not too hard, as you probably know.<br />
Did you think about putting the &quot;head&quot; on the back of the robot facing forward? That should give you enough space so that it won't freak out when something's close, shouldn't it?
If you are thinking about the &quot;dead zone&quot; within 10 CM's in front of the Sharp, you are absolutely right!
Cool, it's not very often that that happens. ;)
Very well presented and detailed instructable, can't wait for payday to make this badboy<br /> <br /> 5*'s<br />
Yay! The kit's on sale!<br /> <br /> ...damn.... bit expensive. Looks like I'll have to save up!<br />
&nbsp;good job.
<big>Hey, you should sell kits here on Instructables:</big><br /> <tt><br /> https://www.instructables.com/community?categoryGroup=marketplace&amp;category=kits</tt><br />
Agreed!<br />
I think &quot;Wholes&quot; is&nbsp;should to be &quot;Holes&quot;

About This Instructable



More by fritsl:Your first real robot the easy way, learn all the basics while at it :) How to build your first Robot ($ 85) 
Add instructable to: