3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

How to build your first Robot ($ 85)

Step 21Heads up & go!

Heads up & go!
You're done building the basics!

You have actually made a robot. Now the fun starts, you can program it to do anything, and attach anything to it, expand in any way. I am sure you are already full of ideas, and you are likely not to have followed me all this way ;)

The design may wary, you may have used other parts etc.. But if you have connected as described, here are some tips to get started programming your robot:

Enter (copy-paste) this code into your editor, and press F5 while the robot is connected:

Note: The code will look a lot nicer once you get it into your editor, it will recognize commands and give them colors.

+++

main:

readadc 1, b1 ' takes the voltage returned to analogue pin 1, and puts it into variable b1
debug ' this draws out all variables to the editor.
goto main

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

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

Enter (copy-paste) 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.)

The servo you have already tried.

All the way to one side is:

servo 0, 75

the other side is:

servo 1, 225

- and center:

servo 1, 150

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.

+++

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
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
return

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 1, 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 1, 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
+++

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 ;)

Up for some more advanced code? Check this: http://letsmakerobots.com/node/25

Sound:

You can also add a small speaker to example (output) pin 1 & ground, and write

Sound 1, (100, 5)

- or within the example program above make it

Sound 1, (b1,5)

- to get funny sounds depending on the distance to objects ahead.

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..

  • Add a marker on it (perhaps on a second servo, so it can take it on and off the paper?), and teach it to write the number of times you wave your hand in front of it on a piece of paper.
  • Turn it into a "cat-get-down-from-the-chair"-guardian-robot, shaking when the cat comes near.
  • Make it chase another robot (or cat?) You will get into some good chase-routines this way!
  • Make it seek out the middle of a room
  • Make it act like a mouse; Freeze if there is movement in sight, and always move close to walls and seek out small gaps to get into.

You could also take an old toy-car apart, take out the electronics in it, save the motors and turning-device in it, and hook up your board, servo and sensor - you will have given life to your vehicle :)

Also try to read some of the documentation, it will make sense now that you got a head start, You can do anything now!

Welcome to a very funny world of homemade robots, there are thousands of sensors and actuators just waiting for you to hook them up and make robots out of them :)

Now take some pictures of your robot, and send them to me at letsmakerobots.com - C ya ;)
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
74
Followers
2
Author:fritsl