You are on page 1of 51

How to build your first Robot !

Full, step by step


Instructions
How to make your first
Robot
By Frits fritsl Lyneborg
ttp!""letsmakerobots#com"user"$
%&F by ser'ello
For more info, latest 'ersion and
were to find te materials needed!
ttp!""letsmakerobots#com"start
This is an updated version, the original can be found here: The original instructions
This tutorial is the easiest way in the world
to give you a fast start into building robots.
Learn ow to make a robot, no skills needed, 'ery, 'ery easy#
(ime to build! ) ours
*RL to more information! ttp!""picasaweb#google#com"fritslyneborg"Let###
+ost to build! ,-.
/ctuators " output de'ices! ) geared motors
+%*! %ica0e
%ower source! $ // batteries
%rogramming language! %ica0e basic
1ensors " input de'ices! 1arp IR
(arget en'ironment! indoor
2elcome !3
4'eryting ere is so easy, tat after you a'e gone troug it, you can make a robot
in a couple of ours# 2y can5t you do tat now6
Because tere are so many little tings you need to know# (is is an attempt to let you
know e0actly all tese little tings, and noting more# Fast, and based on ) years of
e0perience of wat people need to know to get started# If you urry, you can run
troug tis, and be robot builder in a couple of ours# But e0pect to use a good
weekend 7 Learning takes time 7 e'en toug it is 'ery easy, it 8ust takes some time, all
te little tings to get to know !3
(ere are oter 9How to get started building robots9 out tere# (is one is focusing on
getting you around e'eryting e0tremely fast# :ou need no knowledge of ### anyting#
/nd you will learn e'eryting### well, te basics of e'eryting ;3
/ll images in ig7res ere#
/ttacment! sbot'ideoprogram#bas <.#$= >B3
Resources:
PICAXE Manual Part ! "etting #tarted $.%df& $?=>B
PICAXE Manual Part ' ! (A#IC Co))ands $.%df& $?.>B
PICAXE Manual Part * ! Interfacing Circuits $.%df& =?@>B
PICAXE Editor #oftware v+
If you are ready to begin, let5s start wit # # #
Materials needed
4'eryting you need can be found in websops, and 'ia Aoogle, and you can get it
were you are, in any country#
PICAXE!', Pro-ect (oard
(e )- pin pro8ect board is like a game of Bario Bros; Fun and full of e0tras and
idden features, making you want to play o'er and again# It is an e0tremely good
board to get you started, and it can be used for a fantacillion different pro8ects, don5t
get me started !3
Male .sna% off. /eader Pins0 at least 1 %ins on a stri%
Bany times te boards tat you buy 8ust a'e oles in tem, and tat makes it ard to
plug someting in " on# Cne way to o'ercome tis, is to solder wires into te oles#
/noter is to add tese pins, so you can plug on wires, like wit te ser'o and female
eaders sown below# 92y don5t tey 8ust put pins in all te oles from te factory9,
you may ask# 2ell, I don5t know# Baybe to gi'e us te option# It is also possible to
solder female eaders onto te board, peraps tis is wy#
:ou get tese in long rows, and simply break tem apart wit your fingers#
* #horting (loc2s0 To% Closed
%ut tese o'er ) pins ne0t to eac oter, and tere is a connection between tem!
+ or )ore 3e)ale!3e)ale /eader 4u)%er cables
:es# (ese are nice# 2en I started tis obby a couple of years ago, tese were
really ard to get# Dow tey are e'erywere, and tat is really good# Bost tings in tis
new robot7obby of yours a'e pins <or you solder some in ;3 7 and by using tese
8umpers, you can make Euick connections witout soldering# Dice!
5#( PICAXE Progra))ing Cable
:ou write your robots programs on your computer# %lug tis cable into te robot, and
transfer te program# *nplug, and te robot runs te program by itself#
PICAXE!',X IC
(is cip is a Bicroprocessor# (at is often e0plained as 9/ computer in a cip9# It can
be placed in te board described abo'e, after tat, it can be programmed from your
computer 'ia te programming cable#
:our program can tell te controller to 9listen for inputs9, 9tink about tem9, peraps
make some calculations or look in some datas, and make outputs to someting like
te motor dri'er below#
It is cosen ere, because it is Euite strong, yet 'ery easy to program, as you will see
below#
6'7*8 Motor 8river IC
I will describe tis later, wen we install it below !3
8I6 **1 9 , resistor array
(e :ellow cip! It is 'ery dull, 8ust a row of little resistors# :ou will be using it to set
your board up for ser'os#
#tandard servo
/ 1er'o is a cornerstone in most robotic appliances# (o put it sort it is a little bo0 wit
wires to it, and a saft tat can turn some )?? degrees, from side to side#
(e microcontroller can decide to were te saft sould turn, and stay tere# Like go
to 9= o5clock9# (at is it pretty andy; :ou can program someting to pysically mo'e to
a certain position# De0t ting <after tis pro8ect3 could be to let one ser'o lift anoter
ser'o# :ou would ten a'e wat is referred to as ) &CF <9&egrees of Freedom93# But
let5s start wit one ;3
:ou may wonder wy my ser'o as tat wite pin, were yours migt a'e a flat disc,
a cross, or someting# It does not matter, ser'os comes wit all kinds of 9ser'o orns9#
2e 8ust need someting tere to glue te ead on to!
#har% Analogue InfraRed Range 3inding #yste) $AER#&
with cable
(e one 9eye9 sends infra red ligt# (e oter sees te reflection of tis <if tere is
one3, and te unit returns te distance to te ob8ect in front of it# It as = wires <make
sure you get te cable for it, or it can be a little ard to ook up3# :ou gi'e it power on
) of te wires, and te tird one plugs into te microcontroller, and tells it te distance#
: 9 AA (attery /older if you are using rechargeable
batteries
! or !
* 9 AA (attery /older if you are using non!rechargeable
batteries
<1ee more below, regarding batteries, and wy te difference 7 %oint is tat you need
as close to .F as possible, one way or te oter, and you can use someting
completely different in terns of batteries if you want# /s long as it is 8ust about . Folts#3
' "eared )otors and wheels to fit
It is 'ery important tat your motors a'e gears# :ou want a slow robot; Ao for ig
ratios, like G)?!G or iger, as a slow robot is so muc more fun in te beginning,
because you can see wat it is doing#
/part from tat, tere is not muc to say# 2ell, tat would be, tat tere are many
ways of mo'ing and steering# (is way of only using ) weels, is sometimes referred
to as 9skid steering9# /nd it is wort remarking tat if you5d like to add belt tracks later
on, te basics are te same ;3
Roll of double sided foa) ta%e
C yes! If tere is someting you cannot fi0 wit tis tape, it is because you are not
using enoug! It is a 'ery, 'ery fast way of sticking ) items togeter# In fact we will be
using it to make tis entire robot! &epending on te make, of course, it is also
reasonably easy to take apart again#
%aint stirring sticks, tis tape, and a melt glue gun is te backbone for most of my fun
wit robots !3
/eat shrin2 tube $+ )) a%%ro9&
1ometimes you do need to solder ) wires togeter# For instance te 1arp IR Range
finder; It comes wit straigt up wires on te plug# 2at you do, is cut one of te
female cables <abo'e3 in ) parts, solder tem togeter## but before tat, you cut a little
piece of tis eat srink tube to slide o'er te place witout insulation# (en wit a
ligter, you can Euickly eat up te tube, and it srinks to fit#
(at is so muc smarter tan using tape ;3
Also needed:
(atteries
4iter = // Don recargeable, or $ // Recargeable#
(is robot needs . Folts# Bainly because te 1arp IR, really feels best on .#?F, tat5s
wat it5s made for# Botors and ser'o would like more, microcontroller could li'e wit
H#?F, but keeping it simple is te core ere, so we feed te wole robot wit as close
to .#?F as possible# /nd rater too little tan too muc, so we make sure not to fry
anyting, now tat tis is your first robot ;3
Dow, you may know, tat normal batteries pro'ide G#.F# Howe'er, you may not know
tat recargeable batteries only pro'ide G#)F!
Do matter if you knew tat or not, = times G#.F from normal batteries, is $#.F# If we
use $ times G#.F we would get H#?F, wic migt be a little scary to use on te 1arp,
rated for .#?F#
$ times G#)F from recargeables is $#-F, wic is nice and close to .F# /nd ten it is
muc ceaper in te long run# 1o I strongly recommend you to get some
recargeables and a carger#
(ip! (e best recargeables a'e te igest capacity, measured in 9m/9# (e ).??
m/ //7siIe is a fine battery#
A #oldering iron and solder
If you are new to soldering, tis migt interest you#
A lighter and a cutter
Ligter for eat srinking, cutter to## cut#
(ip! If you want to use te cutter to remo'e plastic from cables, turn it tis way;
Imagine tat you were sticking te cable rigt into te cutter from were you are now,
into te table it is laying on# (at way# /nd not from te table, and out to were you
are# (en gently close around te wire, and pull te plastic off#
A co)%uter with an internet connection and a free 5#(
%ort

+an be Bac, Linu0 or %+# (e software needed for tis is free#
;ice!to!have tools0 though not essential:
A )ulti)eter $a2a )easure!thingey&0 a wire stri%%er0 and a
screwdriver
Ready< 6et=s )a2e a robot :&
Pins in holes>
First unwrap your board <I am sure you already did tat !3, and ten see tat it may
a'e some red stuff underneat# (at is 8ust tere from wen tey made it; (ey insert
te components on te upper side, and dip te boards lower side into ot solder## and
areas were tey don5t want solder to be stuck, tey a'e placed tat red stuff# 1o 8ust
take it off !3
Let5s look at somewere were we for sure are going to add some pins## :es, te
motor7outs#
(e / J B on te board# 2e will get back to tem, but for now, snap off ) times ) pins,
and plug tem in#
It does not matter if you snap off single pins or anyting like tat# (ey are simply little
metal rods in plastic# 1ort side down into board#
*se some foam tape to old te pins in place#
(urn te board around and solder###
/nd now, tatataaaa## :ou can plug in any standard female eader, were you used to
a'e a ole !3
Dice, and wile you are at it, also solder a pin into analogue port ?, tat we are going
to use for te 1arp!
(en solder a pin into output ?##
/nd you are done wit pin7soldering#
If it was me, I5d 8ust solder pins in all te oles, but you may want to lea'e tat for later#
:ou a'e soldered all te pins tat we need for tis pro8ect now#

;e9t0 general instructions: E9tensions and alternations of
wires and cables:
+onnecting ) wires 9(e rigt way9 is almost a religion to some# Here is ow I do it !3
First, I simply twist togeter te ) wires
(en I solder tem togeter, cut some off, if it is too long, and bend it along te side of
one of tem#
Howe'er, B4FCR4 I do tis, I make sure tat I a'e cut off a little piece of eat
srinking tube, and placed it o'er one of te wires# (en I slide tat o'er###
/ ligter Euickly eats it up# (is makes it srink, ence te name, and it is a perfect
insulation#
I don5t tink you realiIe ow ard it was to take tat picture all by myself !3 It ad to be
in focus on te rigt spot, you know# /nd yes, te wire got a little burned !p Aood sot
toug, if I may say so myself#
3ro) now on0 I e9%ect you to -ust e9tend wires that are too short0 hoo2 u%
headers on wires when needed0 and if you need to connect so)ething to
the board0 where there is only a hole... you si)%ly add a %in :&
"et it together>
3i9ing u% the )otors
Bount te weels on te geared motors# :ou may a'e a completely different set tan
I do ere, but as long as tey are geared motors tat run fine on a few 'olts, and some
nice weels, you will be all rigt#
2en you a'e te weels on te motors, cut one of te female7to7female wires in
al'es, take away some of te plastic from te end of te wire, and solder it on# /nd
do te same for te oter motor#
Bake sure no solder or wires touces te metal on te motor !3
1ome weels come wit optional rubber tires# It can be a good idea to wait wit putting
on tis rubber, because if te robot is stuck, it can 8ust slide, wic is nice wen testing
and de'eloping#
Chi%s in the board>
(e %ica0e )-KG Bicrocontroller tat you a'e ere, and te board, is a pretty
amaIing and 'ery powerful little package#
I remember ow amaIed I was tat I could actually make tis control e'eryting I
could imagine, I ope you will get tat sensation at some point as well; 1eriously, you
can make tis ting do all sorts of stuff wit all sorts of electronics# 4'en if you know
noting about anyting, and electronics is as strange to you, as it is to me#
:ou can also make it andle your ser'os, motors, calculations, monitoring distance##
e'eryting a robot needs# /nd tat is wat we are going to set it up for now
(e microcontroller is te long cip# (at is te one you program, and ten tere are
inputs and outputs on te board tat it can use#

/ave a loo2 at this %age: ', %in Pro-ect (oard $AXE1'1&0 Pica9e for du))ies

Dow, I do not e0pect you to read tat page now, because I a'e promised you tat you
will building building te robot as fast as possible !3 Howe'er, it is important tat you
read tat page at some point, to learn about te board, and te microcontroller#
%romise me to get back to tat, make a bookmark for ne0t step ;3
C>, enoug talk, insert te long black cip, tat is te microcontroller#
Bake sure to turn it te rigt way! It as a marking in one end, and so does te socket#
(ey sould matc#

Dow, wen you bougt te board, it sould already a'e a black cip in it, in te slot
were I a'e placed te yellow cip, in te picture below#
(ake up te black cip, and as I did, replace it wit te yellow one# It does not a'e
enoug pins, but see picture for wat end to lea'e open# <te inner side3
(e yellow cip is sitting between te microcontroller and te topmost row of pins on
te picture# (at row as <as you will know wen you read about te board, your
bookmark, remember63 te outputs#
2e are going to ook up te ser'o to one of tese# 1er'os are sending a lot of
electrical noise back on te line# (e :ellow cip is a series of ==? Cm resistors, tat
will reduce te amount of noise tat is sent back to te microcontroller# It is simply
straigt lines across, wit some resistance between, making te signals tra'elling bot
ways a little weaker# 1o it is tere to protect te microcontroller#
Frankly, I a'e ne'er eard of anyone frying a microcontroller because of ser'o noise,
but since manuals tells us to do tis, and te board is prepared for it, we migt as well#
I a'e also eard of black 'ersions of tis cip# How boring, but none te less, and
yes; :ou can use it, no matter te colour, if it as te same functionality#
(e black cip tat was in its place, is a so7called &arlington dri'er# If you need more
info tan tat, please read te manuals !3 But it is a good cip, if you are not ooking
up ser'os rigt on te board# It is amplifying te signals, so for instance you can ook
up a speaker rigt on it <were we now will be placing a ser'o3 7 and using te
command 91ound9, you can make it beep Euite loud, play tunes etcetera# :ou a'e got
to try tat as well! Lust not now ;3 &isad'antage of using te microcontroller and tis
board for e'eryting is, tat wen you want to play wit ser'os, you take out te
&arlington, and te fun it pro'ides# But tere is more, wait and see!
Last cip is te motor controller, trow tat in as well!
2en your microcontroller is placed in your board, it can switc power on"off# :ou
could use tat to dri'e motors# Howe'er, motors are 9roug9, and could fry te
microcontroller5s outputs# /nd anoter ting is tat if te microcontroller can only turn
power on"off, ten## ow do you dri'e backwards6
/ motor dri'er takes care of all tis;
(is little motor7dri'er7in7a7cip can dri'e a pair of small motors <H?? m/ eac, for te
tec interested3, witout frying te microcontroller# /nd furtermore; It can make te
motors go backwards# 2ic is andy wen facing a wall !3
:our nice board as a place for a motor dri'er tat can take a pair of small motors, and
make tem dri'e bot forward and re'erse#
(e board is set up, so te microcontroller5s outputs $, ., H, and M are fed into te
motor controller, and out comes ) fine pairs of wires tat you can ook up to a pair of
motors! Botor / and Botor B# /nd you 8ust soldered pins into tem, ow nice#
Ti%: ;ew chi%s in
Dew and unused cips usually a'e te two rows of legs a little too wide apart# 1o
gently pus down te side of te cip towards a table to correct it, before inserting it
into a slot# :ou will understand me once you try to place a new cip in a socket ;3
Ti%: ?ld chi%s out
It is easy to get a cip out of a socket, by inserting a flat screwdri'er below it, pus it
under, to te far end, and gently pus it up#
3act: Later in your life, you will want te microcontroller to 8ust be a microcontroller#
:ou ten buy e0tra oter boards for someting like ser'o control and motor control#
(ese boards will get teir commands from te microcontroller# /nd ten your robot
can do e'eryting muc more powerful, and simultaneously#
Howe'er, it is pretty amaIing wat you can make tis set7up do, as you a'e it rigt
ere! Bany, many cool robots and oter pro8ect use far simpler or 8ust tis set7up#
Ma2e the body.. without a body>
In order to keep tis as simple as possible, we are 8ust glueing all te parts togeter,
and call tat a robot! :es#
If you prefer, of course you can make it more ad'anced tan tis# Cnly ting to note as
suc is tat we use ) central weels, eac wit one motor# &ri'ing bot forward makes
te robot dri'e forward, and if one is going backwards wit one forward, it turns on a
plate# If one is still, and te oter is dri'ing, it is more like 9sliding9 to one side#
2at you can do, is simply to stick on te motors to te battery older, using te
foamy tape# If te batteries are in tere, and te weels are big enoug to a'e tem
placed below te a0le, te wole ting will simply balance on its own# Nuite strange,
actually, wen I tink about it !3
1omeow also lea'e some room for te ser'o in front# Cr stick it on to te front of it all#
Bost important is tat weels touc ground, and te rest is more or less in balance# It
does not matter if it is tipping a little backwards#
Feel free to make your own design, of course !3 If you do not like te balancing part, or
cannot make it work, you can 8ust add some smoot 9pads9, or e0tra weels# / pearl,
or an old L4& could make nice little 9tird weels9, tat usually are placed in te rear
of te robot#
Dow, as you can see, tis time, I used te $7battery older# Because tat is te biggest
one, wic makes it easier to stick it all on to it#
7 But if you are using non7recargeables, and only sould use = batteries, ere is a tip!
Find an old telescopic antenna, from a radio or someting#
+ut off a piece <Here is a tip on ow to cut it3, and insert it instead of one of te
batteries# Bingo ;3
C>, ne0t ting is to place te board on te robot, and ook e'eryting up <apart from
te 1arp, wait wit tat3#
First! (ake out te batteries again <or at least one of tem3# Lust to make sure you
don5t fry someting by accident# 2e don5t a'e an Cn"Cf on tis robot; Batteries in,
and it is ali'e# But we want it dead now, so one battery out! <and not like on ne0t
picture, do!3
1ome battery olders a'e wires <like te one I am using3, and some a'e a clip tat
fits rigt onto te clip on te board, as illustrated in te = battery older below# If you
a'e a clip, ten ook it up, you are done# If you a'e wires like me, cut off te clip
from te board, and connect black wit black and red wit red# <and use sorter wires
tan I did ;3
(e O from te battery sould go te were te R4& is ooked up on te board, from
te factory#
/oo2 u% stuff to the board
/oo2 u% the servo
:our ser'os wires colours may be different, but te ints are; Brown or Black <Around3
to te outside, Red <Folt3 in te middle, and yellow or wite <1ignal3 on te inside of
te board# (ese descriptions may make most sense to you, if you a'e read about
te board, as you promised me to do earlier# But for now you can 8ust note te colours,
and make sure to plug in your ser'o te rigt way around !3
Mount the board0 and hoo2 u% the )otors
2it some <more3 foam tape, stick on te board to te rest of te robot#
Bake sure te mini78ack <te metal ring in one end of te board3 is placed so it is easy
to plug in a cable, because you will be doing tat many times! /nd be careful to make
sure tat te bottom of te board does not touc any metal ;3 (at would cause sort
circuits#
Hook up te motor wires, into te /JB7pins tat you soldered on earlier!
Cne motor5s ) wires goes to / on te board, te oter two wires go to B# It does not
matter wic motor connects to wic output, we will manage te rest in te
programming#
Cops, one of my motors wires was too sort, so I added little blue e0tensions from a
scrap piece of wire tat I found#
(ere is a nice little room to stuff in e0cess lengts of wires !3
/nd 'oilP!
(rea2 out0 software
<:es, I know your robot still as no face !3
2e need to turn te ser'o to centre#
Cf course you could try and do it by and, and estimate it to be in centre, but te
smarter way is to let te microcontroller put te ser'o to centre# Because ten you can
mount 9te face9, facing forward, rigt were te microcontroller tinks it sould be,
wen facing forward#
:ou are going to take a 9(ime7Cut9 from tis tutorial, because you will need to set up
your computer to know tere is a programming cable attaced, and a piece of
programming software must be installed#
I cannot elp you muc wit tis, as it depends on te type of computer you a'e got,
and wat te folks at te %ica0e website a'e updated after I wrote tis#
Howe'er, go to
ttp!""www#re'7ed#co#uk"pica0e <or te easier to remember! pica0e#com 7 tat redirects
you3
&epending on your C1, you want eiter te
3ree PICAXE Progra))ing Editor or te AXE%ad <wic is also free, it is 8ust not in
te name ;3
&ownload and install wic e'er tey claim will make you able to program te %ica0e
cips!
(en you want to find te part tat says
AXE1'@ PICAXE 5#( 8ownload Cable
Install te dri'er and cable as described, and plug te 8ack into te board#
Insert all batteries in your robot## wait## wait## sniff## anyting smells funny6 Do sparks,
no smoke6 Do6 C>, go on ten#
Bost 'ersions of te %ica0e programming software a'e some form of menu item
called 9Cptions9# 4nter tat, and look for a page or tab tat says 9Bode9# 1ome editors
e'en open tis 'ery page for you wen you first start up te program#
Here you sould find a button tat says 9Firmware9 or 9+eck firmware 'ersion9# +lick
tat#
Dow wat sould appen is tat te editor talks to te cable, tat talks to te
microcontroller, and asks it wat kind of a %ica0e cip it is# It sould return someting
like 9)-KG"$?KG9, and tis sould be displayed on te screen for you#
If yes, ten good; :ou a'e contact# Dow somewere in te same screens, you sould
be able to set te mode of te editor, set it to )-KG"$?KG#
<It is a big mystery to me wy tis as to appen, by te way; /pparently te editor
can see wat kind of cip is tere, so wy on eart can it 8ust not set it by itself6#
mm## let me know if you find tis reason one day ;3
C>, if you get any errors, cannot find te microcontroller or someting is reported
wrong wit te cable, I will a'e to ask you to lean on %ica0e5s elp and manuals# It5s
usually 'ery simple, so try again if someting is wrong# Cr try from anoter computer,
8ust to see ow it sould work, and ten try te first one again, and bug track tat way#
Dow, enter te main programming editor; It is like a big te0t editor# If no pro8ect is open,
go to 9File9; and open 9Dew Basic9 " 9Dew9#
In ere write tis!
ser'o ?, G.?
wait )
(is is your first program, and it is 'ery simple# (e first line tells te microcontroller
tat tere is a ser'o on pin ?, and tat it sould be put in te centre <center3 position,
wic is +1#
(e ne0t line tells it to tink about life for ) seconds <wic gi'es te ser'o time to
turn3#
/nd after tis, te microcontroller will stop doing anyting at all, it will go Iombie!
2rite it in, and transfer te code to te microcontroller# (at is done on some systems
by pressing F.# Do, wait, I tink it is so on all systems# Cn all tat I can test from ere
anyway !3 :ou could also click 9%rogram9#
:ou sould be told tat te program is transferring, and ten magic sould appen;
(e ser'o sould turn to te centre position#
%eraps it did not do muc, but tat may be because it was already in centre#
(ry to old down te 9Reset9 switc tat is placed on te board, wile turning te ser'o
to one side# (en let go of te reset, and it sould turn back in place#
%eraps you do not tink it is centre, but it is# But maybe your ser'o 9orn9 is 8ust
mounted awkward# In te middle of it, tere is a screw# *nscrew and take of te orn,
make sure te microcontroller did put te ser'o in centre, and ten screw on te 9orn9
<disc, or wat e'er3 again, so it is te way you tink it sould look like wen centred#
Dow, let5s try to turn te ser'o to te sides, let5s e0tend te program!
ser'o ?, M.
wait )
ser'o ?, )).
wait )
ser'o ?, G.?
wait )
te ser'o command sould only be using 'alues from M. to ))., wic is te most a
standard ser'o can go to eiter side# Falues out of tis range are not recommended,
may produce funny results#
4'ery time you run tis program <you can unplug te cable, take out te batteries, and
turn it on again witout te cable3, it will start from te top# /nd e'ery time you press
reset, it will#
If you5d like it to go in a loop, you can add a label in te top, and in te bottom make it
go back to tat label# 2e make up any name for a label, 8ust a single word, followed by
a colon, watc!
ser'ofun!
ser'o ?, M.
wait )
ser'o ?, )).
wait )
ser'o ?, G.?
wait )
goto ser'ofun


Dow it 8ust goes on and on## (ry to play around some wit it, cange 'alues etcetera, if
you like !3
###
C>, back to building te robot ;3
%lug in te wire to te 1arp, if it was not in from te sop# in oter words; Bake sure
tere are = wires coming from te 1arp# :our colours may be different, but I a'e red,
black and wite, wic is pretty meaningful for F, A and 1ignal#
:ou may need to add female eaders to te wires, like I did below# (ese can also be
in any colour, of course# Howe'er, I a'e soldered = of same colours on, so you can
trust te ones in my picture to be leading you to wic cable goes to were#
Be careful to ceck tat you are plugging tis rigt in, because te 1arp can fry pretty
easily#
In te picture below, you can see wat goes to were# (e stick and strange set7up is
8ust to make sure you can see te wires and teir colours !3
:ou sould a'e = little black tings called 1ortening Blocks# 2at tey do is simply
connect ) pins ne0t to eac oter#
If you don5t a'e any, you can always 8ust use a female7to7female 8umper cable
instead, like I did on te last one, wit a little wite cable# (e blocks are smart
because tey don5t take up any space, a wire is smart, because it can reac from one
end to te oter of a board#
/s you can see I did on te ne0t picture, connect analogue input G, ) and = to F, using
sortening blocks or female7to7female#
2y tis6 / brief and not 'ery scientific e0planation is; tese $ inputs <?, G, ) and =3
are analogue# 2ic means tey measure 9ow muc pressure is on te line9#
Howe'er, tey are connected, if tey like it or not# /nd so, a little pressure on one of
tem actually does someting to te ne0t# (ey are 9left floating9# By tying te = tat
we do not use to F, tey are 8ust returning 9full 'alue9, and tey are not left floating# 1o
te last one, number ?, tat we use, is way more accurate#
I a'e not read documentation tat tells you to do tis, owe'er, I a'e at se'eral
occasions e0perienced strange readings, until I tied all unused analogue pins to eiter
ground or F# C### and in fact I am writing documentation ere <sort of !3 1o now it is
written in te documentation to do tis! !3

Bake sure te ser'o faces middle, G.?!
2it a new piece of tape, mount te 1arp IR on te ser'o orn, facing forward#

Tadaa> :&
:ou5re done building te basics!
(e design may 'ary, you may a'e used oter parts etc### But if you a'e connected
as described, ere are some tips to get started programming your robot!
Progra))ing
4nter tis code into your editor, and press F. wile te robot is connected!
main!
readadc ?, b?
debug
goto main
Dow take your and in front of te robotQs ead and notice ow te 'ariable b?
canges 'alue# :ou can use te knowledge gained to decide wat sould appen and
wen <ow close tings sould get before##3
:ou may notice ow tings start to go 9wrong9 if stuff is too close to te 9eyes9; (e
1arp is made to work wit ob8ects G?7-? cm away# (ings tat are closer tan G? cm
<$ inces3 appear to be furter way, wic can be Euite a callenge to program#
:ou can get many oter distance sensors tat do not a'e tis problem# Howe'er te
1arp is te ceapest, and easiest to program, so tat5s wy I made suc a 9bad9
coice for you, sorry ;3 Look around and see wat e'eryone else is using, before you
decide on an upgrade#
Dow I ad'ise you to put your robot up on a matcbo0 or similar, as te weels will start
turning#
4nter tis code into your editor, and press F. wile te robot is connected!
ig $
low .
Cne of te weels sould turn in one direction# &oes your weels turn forward6 If so,
tis is te instruction for tat weel to turn forward#
If te weel is turning backwards, you can try tis!
low $
ig .
(o turn te oter weel, you need to enter
ig H
low M
<or te oter way around for opposite direction#3
2at appens ere is tat by using only te options a'ailable to te microcontroller;
power on or off <Hig " Low3 on te pins, it is commanding te motor controller to set
motor / or B in forward or re'erse mode#

low $
low .
low H
low M

stops all motors
(e ser'o you a'e already tried#
/ll te way to one side is!

ser'o ?, M. wait )

7 te oter side is!

ser'o ?, )). wait )
7 and centre!

ser'o ?, G.? wait )
Here is a small program tat will <sould, if all is well, and if you inserted te rigt
parameters for ig"low to suit your wiring to te motors3 make te robot dri'e around,
stop in front of tings, look to eac side to decide wic is te best, turn tat way, and
dri'e towards new ad'entures# In te code I a'e made so called remarks! e0plaining
you wat is going on#
:ou can write suc comments or remarks yourself in te code, it is a good idea to
keep track#
(ey are written wit an apostrope <or single Euote3 sign# Howe'er, copying tis te0t
from ere migt alter tat to someting else, and you will a'e to fi0 tat manually,
sorry# :our programming editor as colour codes, tat will elp sowing you wat it
recogniIes as comments and wat as code#

1ymbol dangerle'el R M? 5 ow far away sould ting be, before we react6
symbol turn R =?? 5 tis sets ow muc sould be turned
symbol ser'oSturn R M?? 5 (is sets for ow long time we sould wait for te ser'o to
turn <depending on itQs speed3 before we measure distance
main! 5 te main loop
readadc G, bG 5 read ow muc distance aead
if bG T dangerle'el ten
gosub nodanger 5 if noting aead, dri'e forward
else
gosub wicway 5 if obstacle aead ten decide wic way is better
end if
goto main 5 tis ends te loop, te rest are only sub7routines
nodanger!5 tis sould be your combination to make te robot dri'e forward, tese you
most likely need to ad8ust to fit te way you a'e wired your robots motors
ig . ! ig H ! low $ ! low M
return
wicway!
gosub totalalt 5 first stop!
5Look one way!
gosub lturn 5 look to one side
pause ser'oSturn 5 wait for te ser'o to be finised turning
readadc G, bG
gosub totalalt
5Look te oter way!
gosub rturn 5 look to anoter side
pause ser'oSturn 5 wait for te ser'o to be finised turning
readadc G, b)
gosub totalalt
5 &ecide wic is te better way!
if bGTb) ten
gosub bodySlturn
else
gosub bodySrturn
end if
return
bodySlturn!
ig H ! low . ! low M ! ig $ 5 tis sould be your combination tat turns te robot one
way
pause turn ! gosub totalalt
return
bodySrturn!
ig . ! low H ! low $ ! ig M 5 tis sould be your combination tat turns te robot te
oter way
pause turn ! gosub totalalt
return
rturn!
ser'o ?, G?? 5 look to one side
return
lturn!
ser'o ?, )?? 5 look to te oter side
return
totalalt!
low $ ! low . ! low H ! low M 5 low on all $ alts te robot!
1er'o ?,G.? 5 face forward
wait G 5 freeIe all for one second
return


2it some cle'er programming and tweaking, you can make te robot dri'e, turn its
ead, make decisions, make small ad8ustments, turn towards 9interesting oles9 suc
as doorways, all working at te same time, wile dri'ing# It looks pretty cool if you
make te robot spin wile te ead is turning ;3
3un ti)e
:ou could also attac a lamp or L4& to pin ) J ground, and write <remember L4&s
need to turn te rigt way around3
Hig )

to turn on te lamp, and

Low )
to turn it off ;3
7 How about a Laser7pen, mounted on an e0tra ser'o6 (en you could make te robot
turn te laser around, and turn it on and off, pointing out places## you can do anyting
now !3
%ressing 9Help9 in te programming editors brings out all sorts of interesting tutorials
and info!

%eraps try tis!
%ull out te ser'o, and take up te yellow cip# Insert te &arlington tat you took out
earlier# Hook up te speaker to te ) pins abo'e were te ser'o was, tat is output G#
/nd trow in te L4&, or wate'er it was tat you found on output )# (en program it
someting like tis!

sound G, <G??, =?3
ig )
wait G
low )
sound G, <G?., H?3

(at sould make a sound and turn someting on, make a new sound and turn it off
again#

Cr te more interesting, make sure te 1arp is still in, ook a speaker up to pin G,
and ten program tis!

noise!
readadc ?, b?
sound G, <b?, )3
goto noise

"o to htt%:AAlets)a2erobots.co)Astart to download a %rogra) for the robot
+e ya!
%&F created by ser'ello
<feel free to send comments or corrections3

You might also like