SlideShare a Scribd company logo
Wentworth Institute of Technology
ELEC2950-02 Embedded Computer Systems
Professor Marpaung:
Final Exam Arduino-Robot Lab
2 December 2016
Lab Group:
James Smith, Carlfred Malcolm
Section1: Objectives
Usingan Arduino,teamsof twoare taskedwithprogrammingarobot that can navigate a tape
playing-field,picturedbelow, inordertoeitherknockdowna numberof waterbottles,orhuntdown
the opposingteamsrobot.Thisisto be accomplishedusinganumberof sensors,including ultrasonic
and infraredsensors.A whisker,orlance,maybe employedinthe knockingdownthe waterbottles,
requiringamajoritytobe knockeddownbythe victoriousteam.Likewise,the whiskermaybe employed
inhuntingdownthe opposingteams’robots. Huntingdownarobotrequiresthe robotor lance to make
contact witheitherthe backor the sidesof the opposingrobot,the frontof the robotis notvulnerable
to such attacks.These robotsare pittedagainstone another,inordertodiscover whose programwas
mostsuccessful incompletingthe statedobjectives.Thiscompetitionwillbe organized intoasetof
brackets.
Playing-Field Design
Section2: Flowchart Descriptionof Code
Overall Flowchart
Picturedabove isa simplifiedview of how the code we producedoperates.Whatoccursis,upon
beginningthe code,infraredsensorsare readfromthe bottomof the robot, relaying information
regardingthe colorvalue of the material underneaththe robot.Fromthese values,itcanbe attained
howthe robot musttravel in orderto follow the blacktape linesof the playing-field;adjustingto
continue onthe line,orcontinuingstraight.Thisinformation alsotellsuswhetherornotthe robothas
reachedan intersectioninthe tape path.Withthisinformation,the robotproceedstocompletea
specifiedtaskinorderto fulfillthe objectivesof the lab.This includes,butisnotlimitedto, turningleft
at a four-wayor‘T’ intersection,decidingtoturnright or continue straight,ordecidingwhethertoturn
leftor continue straight.Uponthe completionof anyof these tasks,includingthe tasksrequiredto
followthe line,the code returnstothe beginningof the voidloop,inordertoscan the infraredsensors
once again to receive uptodate informationaboutwhere onthe course the robotlies.
In-Depth Flowchart
In more detail,the code begins; proceedstoreadinfraredsensorsonthe bottomof the robot,
of whichthere are five.Thisinformationis thenrelayedbacktothe Arduino,where these longvalues
are roundedintoBooleanvalues,inordertomake themmore easilyusable.Withthisinformation,we
can tell where onthe line the robotlies,forexample if the robothasdriftedtothe rightof the line,then
the sensorsmayread that the centerand rightsensorsare on the black line,while the restof the
sensorsremainabove the white playingfield.Withthisinformation,the robotentersanif statement
that slowsdownthe opposite motorinordertoallow the robotto readjust,centeringthe robotonce
again.
The information gatheredbythe infraredsensors alsotellsuswhen the robothasenteredan
intersection,readingall blacksduringafour-wayor‘T’intersectionforexample.Usingthisinformation,
the type of intersection canbe conceived,allowingthe code toenterspecificif statements.If the robot
detectsthatit has enteredafour-wayor‘T’ intersection,thenthe robotentersanif statement,witha
for loopinorderto move the forwardslightly,becoming perpendiculartothe turn itis aboutto
navigate;enteringanotherforloopthatspinsthe robotroughly90o
to the left.Whenthe robotenters
an intersectionforastraightor rightturn, theninitiallythe robotproceedsstraight.However,the robot
thenaddsa unitof 1 to a counterfor these typesof intersectionswhichforcesthe robottotake a right
wheneveritencounters anotherintersectionof thistype.Whenthe sensorstell usthatthe robothas
enteredaleftor straightintersection,itwillinitiallyturnleft.Aftercompletingthisleft,avalue of 1 is
addedto anotherseparate counter,forcingthe robottotravel straight duringthe itsnextencounter.
Once the robot has traveledstraightthroughthisintersection,avalue of 1 issubtractedfrom this
counter, allowingthe robottoturnleftduringthe nextintersectionof thistype.Afteranyof these
commandshave beencompleted,the code returnstothe beginning,where itonce againscansthe
infraredsensors,and relaystothe robothow to furtherproceed.
Section3: Explanation ofCode
Thisrobot reliesonanarray of five infraredsensorsinordertonavigate a tape playing-field,
picturedabove insection1.These infraredsensorstell the robotwhere itisinrelationtothe linesof the
playingfield,andisorganizedusingif statementstodecide how the enginesshouldmove.Inthe act of
followingthese playing-fieldlines,the infraredsensorstell the robotwhere itisonthe playing-field,
allowingthe programmingof the motorstoreact differently dependingonthe binarycombinationof
these infraredsensors.Whenthe robothasdriftedrightorleft,the oppositemotoris slowedslightlyin
orderto compensate forthis,andrecenterthe roboton the playing-fieldlines.These line following
statementsonlyoccurduringtimesof none totwo sensorsregisteringablackline beneathit.Thisallows
the robot to distinguishwhenitissimplyreadjustingtothe line,comparedtowhenitentersan
intersection.
Whena robot entersandintersection,the infraredsensorswillidentifythatthe entiretyof one
side of the array is readinga blackline,withatleastthe far,opposite side sensorseeingthe white
playingfield,orboththe far side sensorandthe sensorjustopposite the side of the intersection.What
thismeansisthat, forexample,whenanintersectiononthe rightoccurs,eitheronlythe farleftsensor
will detectthe white playingfield,orboththe leftandfar leftsensorwill.Itwasalsoclearwhena four-
wayor ‘T’intersectionwasreached,becausebothof the outside sensorswoulddetectablacktape line.
Upon enteringthese if statements,forloopsare employedinordertodirectthe robotto complete tasks
that we dictate itto do. These include turningleftduringafour-wayor‘T’intersection,alternating
betweenturningleftandproceedingstraightduringaleftside intersection,orrunningstraightforthe
firstrightintersection,andturningrightduringthe restof them.
The goal of these intersectioncommandswastoknock overthe water bottle objectivesas
quicklyandconsistentlyaspossible.Inordertocomplete thisgoal,these intersectionswere strategically
coded.The firstintersectionwasarightsidedintersection,whichthe robotcontinuedstraightthrough.
The nextwas alsoa right sidedintersection,whichthe robotturnedrightandproceededtowardthe
centerbottle.Uponhittingthe bottle,the robotenteredafour-wayintersection,whichitturnedleft
and proceededtothe topof the playingfield. Thisledthe robottoa ‘T’ intersection,whichforcedthe
robot to once againturn leftandproceedtothe bottle directlyinfrontof it,duringthe startof the
competition.Afterhittingthisbottle,the robotturnsleftandbeginsalternatingbetweenstraight and
leftacrossthe remainingleftsidedintersections.Thisallowedthe robottobegincircumnavigatingthe
playing-field,keepingitfromreenteringthe middleof the field,andeventuallyreachingthe thirdbottle.
Section4: Process and Creationof Code
The developmentof thiscode wasnota linearpathbetweenbeginningtoend.Originally,for
aroundthree weeks,the objective of the labandthe progressionof the code reliedonsolvingamaze
designedintape,whichcontainedafewobstaclesinorderto maintainasense of randomnessand
chaos.This employedthe use of infraredsensors,aswell asanultrasonicsensorwhichwasable to
detectthe distance of an obstacle infrontof it usingsonartechnology.Astime continued,we beganto
fleshoutthe workingsof bothtypesof sensors,aswell asan algorithmtocomplete amaze as quicklyas
possible,usingideasfromthe Trémaux'salgorithm inordertomark intersectionsthe robothas
previouslyvisitedinordertofindthe exitquicklyaswell asavoid travelingthroughthe same
intersectiontwice unlessthere werenootheroptionspresent. Thisalgorithmwasscrappeduponthe
redefiningof the labobjectives,changingthe goal of the labfromcompletingamaze,toknockingover
bottlesina 2x2 square tile playingfield.
Initially,muchof the time wasspenttweakingthe robotinorderto have enoughinformationto
complete the course asquicklyaspossible.Thisrequiredaddingmore sensorstothe robot,addingtwo
more sensorsto the bottomof the robot;the array now includesfiveinfraredsensorsascomparedto
the original three.A photovoltaicsensorwasalsoaddedtothe frontof the robot inorderto distinguish
whenan intersectionwasacorner of the playingfield,orwhenthe intersectionalsocontainedthe
optionforthe robot to continue straight.The use of thisphotovoltaicsensorswasdumpedwhen
consistencyof the readingvaluesbecameaproblemdue toshadowsit,amongotherthings,cast below
thissensor,causingitto reada blackline beingthere regardlessof whetheritwasthere ornot. The
ultrasonicsensorwasalsoplacedoutof commissionwhenthe robotnolongerneededtodetect
whetherornot an obstacle stoodinitspath,and the objectiveswhereknownpriortothe start of the
competition.
Aftersuccessfullygettingthe sensorstoworkfairlyconsistentlyintandemwithone another,we
beganto attemptto getthe robot to follow ablackline,experimentingwithmanystilesof loopsand
statements.Startingwithwhile loops,whichseemedlikeanobviouschoice atthe time,buthavinglittle
successwithoutlarge amountsorredundancy,readingthe sensorswithinmostloopsinorderto exitthe
currentwhile loopandenteranother.Thismethodwastoyedwithforalong time,makingprogressand
minorbreakthroughs,butafteralong time withslow progress,the entire code wasscrappedandbegun
againwithif statements.Thisallowedforthe readingof the sensorstooccur initiallyinthe code,andbe
returnedtouponthe completionof the if statement.Duringtesting,anelse statementwaspresentin
orderto detectwhenthe robotenteredanarea,or receivedacombinationof sensorreadingsthatit
had no combinationfor.Thiselse statementcausedthe robotprintthe phrase “Error!”, inorder to mark
the combinationthatwaspreviouslyunaccountedfor,andspinina circle inplace until the robotwas
shutoff.Thisstrategyallowedforthe fleshingoutof all possible combinationsinordertofollow aline
veryrobustly,andwas testedunderconsiderablyroughcircumstances.
Afterthe robotcouldaccuratelyand consistentlyfollow aline,astrategywasfleshedoutasto
howthe robot was intendedtoproceedinordertoknockdownall three bottlesasquicklyaswe found
possible.Usingcombinationsof binaryinputs,we were abletogothroughall possible combinationsof
sensorreadings,from0.0.0.0.0 to 1.1.1.1.1, decidingwhateachcombinationwouldmeantothe robot,
and whatcombinationswere unlikelyorimpossible tooccur underthese circumstances.Forloopswere
usedinorderto have the robotreact to the intersectionsconsistently,requiringonlytweakingtoallow
the robot to turn 90o
, as well asfall centeredonthe nextline andcontinue straight.The elsestatement
remained,allowingustoinclude combinationsthatoccurredwhichwe didnotfullyconsiderlikely,but
occurredoccasionally,forexamplerunningintoanintersectionatthe same time thatthe robot was
attemptingtoreadjusttofollowthe line.Thesemethodswere usedforroughlythreedifferent
generationsof the same code,becomingbothmore robustandmore efficientwitheachnew iteration.
Section5: Code Limitations
The limitationsof the code include minorglitches,lackof anytype of defense from ahunting
robot,as well asa predictabilityastowhere the robotisgoingto travel duringthe course.Much of the
limitationsalsocame fromthe hardware of the robot,where duringthe competition,asensorwas
disconnectedfromitsgroundingandnolongerreadproperly.The code itself alsoactedstrangely,
stutteringoccasionallyduringtimesof steepadjustmenttofollowingthe line,whichdoesn’toccurwhile
the robot itturningduringan intersectionnorwhenitisfollowingthe line straightforward,abugwhich
I couldnot explainnorcouldIfix intime forthe competition.Of these minorglitchesincludedrare
occasionswhere the robotwasveryoff track fromthe line while itenteredanintersection,providing
false informationtothe robotand allowingittoact erraticallyinresponse tothese inputs.Because
these glitcheshappenedveryrarely,the onlythingtobe done inorderto correct themismake the line
followingalgorithmmore rigorousinordertonotbecome veryoff track often.Anotherlimitationof our
code was originallythe code detectingafour-wayor‘T’intersectionrequiredall the sensorstodetecta
blackline,causingproblemswhenthe robotcame inat an angle,thiswasfixedhoweverwhenthe
parametersforthese intersectionswere changedinordertodetectwhenatleastboththe outside
detectorsrecognize the blackline,insteadof all of themrecognizingthem.
Section6: Photo Documentationof Process
Step1: Travel through Step2: Turn Leftto Attack Step3: Turn Towards the
PrimaryIntersection FirstBottle Outside of the Playing-Field
Step4: Turn Leftto Attack Step5: Continue TowardsCorner Step6: BeginCircumnavigating
SecondBottle Of the Playing-Field the Outside of the Playing-Field
Section7: SkillsDevelopedandTested
Thislab challengedmyabilitytothinkbothobjectivelyandcreativelyinordertocomplete the
assignedtaskwithasmuch efficiencyandconsistencyaspossible withinalimitedtime span.Alongwith
testingmyabilitytodesignandcreate workingcode, Iwasalso taskedwithcomingupwitha strategy
for completingthe competitionfasterandmore consistentlythanmyfellow classmates. Inorderto
compete withmyfellow classmates,Ineededtoemploythe use of sensorsasefficientlyandeffectively
as possible.Thisallowedme toexperimentwithcodingnew typesof sensorsincludingthe ultrasonic
sensor,the photovoltaicsensor,andthe infraredsensorswhichbecame the backbone of the code’s
design.Duringthe original portionof the labalsoallowedme tolearnaboutsome of the many
strategiesemployedinordertosolve a maze,aswell ashow to ussensorsinorderto make the robot
react predictablytostimuli whichincludedfollowingaline,aswell asexecutingcommandsdepending
on the orientation of saidline.Byimplementingall of the skillslearnedinthiscourse andthroughother
codingprojects,Iwas able tomanipulate motorsandsensors,aswell asorganize the code intoefficient
and understandablepieces.
Otherskillstriedduringthisprocesswasorganizational,includingwritingdown the thought
processthat I undertookinordertotry and solidifythe code andminimize redundancyandunnecessary
pieceswithinthe code thatwouldotherwise provideglitches,andinefficiencieswithinthe code.This
triedmyabilityasan engineertodefinethe problemasaccuratelyandeffectivelyaspossible inorderto
approach an applicable solution.
Section8: ClosingNotes
Thislab provedtobe incrediblydifficultforanumberof reasons,of which the greatestenemy
for me was time.Beingpresentedwithuniqueandchallengingproblems,likethislab,onlyworksto
improve myabilitiesasanengineer.Ilookforwardtobeingpresentedwithotherchallengesinthe
future andbelieve thatsome of the lessonsthatIhave gatheredthroughoutthisassignmentwill helpto
shape unique andeffective solutionstoengineeringproblemsinthe future.
AppendixA: Developmental Diary
Date Time Things Accomplished Things Remaining
11/4 13:00 Attach three infrared sensorstothe
robot.
Attach ultrasonicsensortothe
robot.
Write code to read infraredsensors.
Write code to read
ultrasonicsensor.
RoundSensorsintousable
data.
Code motorsto move
whena blackline is
detected.
Designmaze solving
algorithm.
11/9 12:00 CodedUltrasonicSensortodetect
objectsinfrontof robot.
RoundSensorsintousable
data.
Code motorsto move
whena blackline is
detected.
Designmaze solving
algorithm.
11/11 13:00 Addadditional infraredsensors,
makingthe total numberof infrared
sensors5.
Adda photocell andwrite code to
include it.
RoundsensorvaluestoBooleanor
intin centimetersforthe ultrasonic
sensors.
Code motorsin orderto
follow aline.
Designanalgorithmto
solve amaze.
11/16 12:00 Attempttofollow aline usingwhile
loops,little success.
Reevaluate new goalsbasedonnew
labparameters.
Decide ona strategyto
knockdownbottles,or
huntdownopposing
robots.
Code motorsto followa
line.
11/18 13:00 Decide onhow to proceedwithnew
labparameters,begintodiscuss
Successfullyfollow aline.
Date Time Things Accomplished Things Remaining
possible optionsforcompleting
assignment.
Redesignstrategyemployedin
followingaline,beganworkingwith
if statementsopposedtowhile
loops.
Discontinue the use of boththe
Ultrasonicsensoras well asthe
photovoltaiccell.
Solidifyaplanof action
for knockingdownbottles,
huntingopposingrobots
deemedtooinefficient
and unreliable.
11/22 12:00 Beginto follow aline,andfleshout
sumtotal of all possibilitiesof
adjustingtofollow the line.
Developastrategyforknocking
downbottles.
Effectivelyand
consistentlyfollow aline.
Code decisionmakinginto
the robot to take turns
that knockoverall the
bottles.
11/23 12:00 Successfullyfollow aline 9/10 times
and undermoderatelytough
circumstances.
Codingthe abilitytoturn
at intersectionsinorderto
knockoverbottles.
11/25 19:00 Write downobjectivesof the code,
allowingforamore solidifiedideaof
whatthe robothas to accomplish
and how it maybe able todo that.
Scrap original code,savingsome
piecesfromthe line following
algorithm.
Codingthe abilitytoturn
at intersectionsinorderto
knockoverbottles.
Effectivelyand
consistentlyfollow aline.
11/26 18:30 Write code that allowsforthe
turningof the robotat intersections
usingforloops.
Tweakfor loopstoturn
90o
and remainonthe
targetedline.
Effectivelyand
consistentlyfollow aline.
11/27 15:00 Write algorithmthatreliesona
counterto decide whetherornot to
take the turn presentedtothe
robot,a keypart inthe actual
functioningof the robot.
Testthe code on the robot
and continue tofleshout
if statementsasthe robot
detectserrors.
11/29 12:00 Addmore if statementsandtweak
statementconditionsinorderto
have a robust algorithmthatrarely
ran intoproblemsthatwould
otherwise stopthe robot.
Tweakfor loopstobecome more
precise duringturns.
Complete the course with
consistency.
Tweakcode to try and
workpast minorglitches
that occurred,including
reachingan intersection
while alsoadjustingtothe
line.
12/1 12:00 Complete the course withthe robot
knockingdownall the bottlesa
majorityof the time.
Minor tweakingtothe
code to fix minorbugsand
make turns more precise
Date Time Things Accomplished Things Remaining
12/2 7:00 Solidifyforloopsandconfirmthe
properfunctioningof the robotprior
to the competition’sopening.
Compete.
AppendixB-1: Code on November5, 2016
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);//TX,RX
intleft;
intcenter;
intright;
longresult=0;
voidsetup(void)
{
Serial.begin(9600);
pinMode(13,OUTPUT); //RightWheel
pinMode(12,OUTPUT); //LeftWheel
pinMode(11,INPUT);//UltrasonicSensor
}
voidloop()
{
left=IRScan(6);
center=IRScan(7);
right=IRScan(8);
delay(10);
Serial.print("Left");
Serial.print(left);
Serial.print("Center");
Serial.print(center);
Serial.print("Right");
Serial.print(right);
Serial.println("");
}
longIRScan(intsensPin)
{
longresult= 0;
pinMode(sensPin,OUTPUT);//make pinOUTPUT
digitalWrite(sensPin,HIGH);//make pinHIGH to discharge capacitor - studythe schematic
delay(1);//waita ms tomake sure cap isdischarged
pinMode(sensPin,INPUT);//turnpinintoan inputand time till pingoeslow
digitalWrite(sensPin,LOW);//turnpullupsoff - or itwon't work
while(digitalRead(sensPin)){ //waitforpintogo low
result++;
}
returnresult;//WithLight:Black=White=Blue=
}
AppendixB-2: Code on November12, 2016
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);//TX,RX
intleft;
intcenter;
intright;
inti = 0;
longresult=0;
unsignedlongDistance =0;
intUSsensor= 11; // Ultrasoundsignal pin
unsignedlongUSvalue =0;
voidsetup(void)
{
Serial.begin(9600);
pinMode(13,OUTPUT); //RightWheel
pinMode(12,OUTPUT); //LeftWheel
pinMode(USsensor,OUTPUT);//UltrasonicSensor
}
voidloop()
{
left=IRScan(6);
center=IRScan(7);
right=IRScan(8);
delay(10);
Serial.print("Left");
Serial.print(left);
Serial.print("Center");
Serial.print(center);
Serial.print("Right");
Serial.print(right);
Serial.println("");
i = US();
Serial.print(i);
Serial.println("CM");
delay(250);//delay1/4seconds.
}
longIRScan(intsensPin)
{
longresult= 0;
pinMode(sensPin,OUTPUT);//make pinOUTPUT
digitalWrite(sensPin,HIGH);//make pinHIGH to discharge capacitor- studythe schematic
delay(1);//waita ms tomake sure cap isdischarged
pinMode(sensPin,INPUT);//turnpinintoan inputand time till pingoeslow
digitalWrite(sensPin,LOW);//turnpullupsoff - or itwon't work
while(digitalRead(sensPin)){ //waitforpintogo low
result++;
}
returnresult;//WithLight:Black=White=Blue=
}
unsignedlongUS()
{
pinMode(USsensor,OUTPUT);//Switchsignalpintooutput
digitalWrite(USsensor,LOW);//Sendlow pulse
delayMicroseconds(2);//Wait for 2 microseconds
digitalWrite(USsensor,HIGH);//Sendhighpulse
delayMicroseconds(5);//Waitfor 5 microseconds
digitalWrite(USsensor,LOW);//Holdoff
pinMode(USsensor,INPUT);//Switchsignalpintoinput
digitalWrite(USsensor,HIGH);//Turn on pullupresistor
// please note thatpulseInhasa1sec timeout,whichmay
// notbe desirable.Dependingonyoursensorspecs,you
// can likelyboundthe time like this -- marcmerlin
// Distance = pulseIn(USsensor,HIGH,38000)
Distance = pulseIn(USsensor,HIGH);//ListenforDistance
USvalue = (Distance /58.138); //converttoCM
returnUSvalue;
}
AppendixB-3: Code on November19, 2016
intFleft,left,Fright,right,center,reach,i=0,pivot=0;
booleanFL,L, C, R, FR;
longresult=0;
unsignedlongDistance =0;
intUSsensor= 11; // Ultrasoundsignal pin
unsignedlongUSvalue =0;
voidsetup(void)
{
Serial.begin(9600);
pinMode(13,OUTPUT); //RightWheel
pinMode(12,OUTPUT); //LeftWheel
pinMode(USsensor,OUTPUT);//UltrasonicSensor
}
voidloop()
{
// ScanningUnderbelly,IRScanners
Fright=IRScan(8);
right=IRScan(5);
center=IRScan(7);
left=IRScan(9);
Fleft=IRScan(6);
if(Fright>200){
FR=1;
}
else FR=0;
if(right>200){
R=1;
}
else R=0;
if(center>200){
C=1;
}
else C=0;
if(left>200){
L=1;
}
else L=0;
if(Fleft>200){
FL=1;
}
else FL=0;
Serial.print("FarLeft");
Serial.print(FL);
Serial.print("Left");
Serial.print(L);
Serial.print("Center");
Serial.print(C);
Serial.print("Right");
Serial.print(R);
Serial.print("FarRight");
Serial.print(FR);
Serial.println("");
if( FL==0 && L==0 && C==1 && R==0 && FR==0){//StraightForward
digitalWrite(13,HIGH);
delayMicroseconds(1400);
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,HIGH);
delayMicroseconds(1600);
digitalWrite(12,LOW);
delay(10);
}
else if( FL==0 && L==0 && C==1 && R==1 && FR==0){//AdjustLeft
digitalWrite(13,HIGH);
delayMicroseconds(1350);
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,HIGH);
delayMicroseconds(1600);
delay(10);
}
else if( FL==0 && L==0 && C==1 && R==1 && FR==1){
for (pivot=0;pivot<60;pivot++)//Pivotthe Robotright,approximately90 degrees
{
digitalWrite(13,HIGH);
delayMicroseconds(1300);//RigthMotorStandstill
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorBackwards
digitalWrite(12,LOW);
delay(10);
}
}
else if( FL==0 && L==0 && C==1 && R==1 && FR==1){//RigthTurn or Straight
}
else if( FL==0 && L==1 && C==1 && R==0 && FR==0){//AdjustRight
digitalWrite(13,HIGH);
delayMicroseconds(1300);
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,HIGH);
delayMicroseconds(1550);
delay(10);
}
else if( FL==1 && L==1 && C==1 && R==0 && FR==0){
for (pivot=0;pivot<60;pivot++)//Pivotthe Robotleft,approximately90degrees
{
digitalWrite(13,HIGH);
delayMicroseconds(1700);
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,HIGH);
delayMicroseconds(1700);
digitalWrite(12,LOW);
delay(10);
}
}
else if( FL==1 && L==1 && C==1 && R==0 && FR==0){//LeftTurn or Straight
}
else if( FL==1 && L==1 && C==1 && R==1 && FR==1){//T-Intersection
}
else if( FL==0 && L==0 && C==1 && R==0 && FR==0){//4-WayIntersection
}
}
longIRScan(intsensPin)
{
longresult= 0;
pinMode(sensPin,OUTPUT);
digitalWrite(sensPin,HIGH);
delay(1);
pinMode(sensPin,INPUT);
digitalWrite(sensPin,LOW);
while(digitalRead(sensPin))
{
result++;
}
returnresult;
}
AppendixC: Final Code
intFright,right,center,left,Fleft,motion,d=0,a=0;
booleanFL,L, C, R, FR;
longresult=0;
voidsetup(void)
{
Serial.begin(9600);
pinMode(13,OUTPUT);//RightWheel Forward == 1700
pinMode(12,OUTPUT);//LeftWheel Forward== 1300
}
voidloop() {
//ScanningUnderbelly,IRScanners ------------------------------------------------------------------
right=IRScan(5);
Fleft=IRScan(6);
center=IRScan(7);
Fright=IRScan(8);
left=IRScan(9);
//RoundingIRSensorstoBinary -----------------------------------------------------------------------
if(Fright>200){
FR=1;}
else FR=0;
if(right>200){
R=1;}
else R=0;
if(center>200){
C=1;}
else C=0;
if(left>200){
L=1;}
else L=0;
if(Fleft>200){
FL=1;}
else FL=0;
//PrintSensorValuesforTroubleshooting ------------------------------------------------------------
Serial.print("FarLeft");
Serial.print(FL);
Serial.print("Left");
Serial.print(L);
Serial.print("Center");
Serial.print(C);
Serial.print("Right");
Serial.print(R);
Serial.print("FarRight");
Serial.print(FR);
Serial.println("");
//BasicLine FollowingCommands ------------------------------------------------------------------------
if( FL==0 && L==0 && C==1 && R==0 && FR==0){//StraightForward
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12, HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==0 && C==0 && R==0 && FR==0){//StraightForward
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13, LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==0 && C==1 && R==1 && FR==0){//AdjustLeft
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1475);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==1 && C==1 && R==0 && FR==0){//AdjustRight
digitalWrite(13,HIGH);
delayMicroseconds(1525);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==1 && C==0 && R==0 && FR==0){//AdjustRight
digitalWrite(13,HIGH);
delayMicroseconds(1525);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==1 && L==1 && C==0 && R==0 && FR==0){//AdjustRight
digitalWrite(13,HIGH);
delayMicroseconds(1525);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==1 && L==0 && C==0 && R==0 && FR==0){//AdjustRight
digitalWrite(13,HIGH);
delayMicroseconds(1500);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==0 && C==0 && R==1 && FR==0){//AdjustLeft
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1475);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==0 && C==0 && R==1 && FR==1){//AdjustLeft
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1475);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
else if( FL==0 && L==0 && C==0 && R==0 && FR==1){//AdjustLeft
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightWheel
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1500);//LeftWheel
digitalWrite(12,LOW);
delay(5);
}
//IntersectionCommands
//StraightRight-------------------------------------------------------------------------------------
else if((FL==0&& L==0 && C==1 && R==1 && FR==1)||(FL==0 && L==1 && C==1 && R==1 &&
FR==1)){//StraightRight
if(d==0){//FirstIntersection,Straight
for(motion=0;motion<20;motion++){//StraighttoExitIntersection
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
d++;
}
else if (d==1){//SecondIntersection,Right
for(motion=0;motion<13;motion++){//InchForwardSlightly
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
for(motion=0;motion<42;motion++){//TurnRight
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1700);//LeftMotorBackward
digitalWrite(12,LOW);
delay(5);
}
}
}
//LeftAnything--------------------------------------------------------------------------------------
else if((FL==1&& L==1 && C==1 && R==0 && FR==0)||(FL==1 && L==1 && C==1 && R==1 &&
FR==0)){//LeftAnything
if(a==0){//TurnLeft
for(motion=0;motion<13;motion++){//InchForward
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
for(motion=0;motion<42;motion++){//TurnLeft
digitalWrite(13,HIGH);
delayMicroseconds(1300);//RightMotorBackward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
a++;
}
else if(a==1){//Move Straight
for(motion=0;motion<20;motion++){
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
a--;
}
}
//T-Intersection/4-Way-----------------------------------------------------------------------------
else if( FL==1 && FR==1){
for(motion=0;motion<13;motion++){//InchForwardSlightly
digitalWrite(13,HIGH);
delayMicroseconds(1700);//RightMotorForward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
for(motion=0;motion<42;motion++){//TurnLeft
digitalWrite(13,HIGH);
delayMicroseconds(1300);//RightMotorBackward
digitalWrite(13,LOW);
delay(5);
digitalWrite(12,HIGH);
delayMicroseconds(1300);//LeftMotorForward
digitalWrite(12,LOW);
delay(5);
}
}
}
//IRScannerStatement ---------------------------------------------------------------------------------
longIRScan(intsensPin){
longresult= 0;
pinMode(sensPin,OUTPUT);
digitalWrite(sensPin,HIGH);
delay(15);
pinMode(sensPin,INPUT);
digitalWrite(sensPin,LOW);
while(digitalRead(sensPin)){
result++;}
returnresult;
}

More Related Content

Viewers also liked

La révision des comptes, pour qui, pourquoi?
La révision des comptes, pour qui, pourquoi?La révision des comptes, pour qui, pourquoi?
La révision des comptes, pour qui, pourquoi?
Pierre Drevon Consulting
 
Beauty products
Beauty productsBeauty products
Beauty products
Md. Kamrul hasan Chowdory
 
Buried Alive
Buried AliveBuried Alive
Buried Alive
MUZAMMIL KHAN
 
RJ Lauridsen resume 10-2016
RJ Lauridsen resume 10-2016RJ Lauridsen resume 10-2016
RJ Lauridsen resume 10-2016
RJ Lauridsen
 
Be social - Le logiche dei social network
Be social - Le logiche dei social networkBe social - Le logiche dei social network
Be social - Le logiche dei social network
fscrigner
 
Presentacion
PresentacionPresentacion
Presentacion
jorge_power
 

Viewers also liked (7)

La révision des comptes, pour qui, pourquoi?
La révision des comptes, pour qui, pourquoi?La révision des comptes, pour qui, pourquoi?
La révision des comptes, pour qui, pourquoi?
 
чгп 4
чгп 4чгп 4
чгп 4
 
Beauty products
Beauty productsBeauty products
Beauty products
 
Buried Alive
Buried AliveBuried Alive
Buried Alive
 
RJ Lauridsen resume 10-2016
RJ Lauridsen resume 10-2016RJ Lauridsen resume 10-2016
RJ Lauridsen resume 10-2016
 
Be social - Le logiche dei social network
Be social - Le logiche dei social networkBe social - Le logiche dei social network
Be social - Le logiche dei social network
 
Presentacion
PresentacionPresentacion
Presentacion
 

Similar to Final Lab, Arduino Robot Challenge

embedded system report
embedded system reportembedded system report
embedded system report
manish katara
 
Robot navigation in unknown environment with obstacle recognition using laser...
Robot navigation in unknown environment with obstacle recognition using laser...Robot navigation in unknown environment with obstacle recognition using laser...
Robot navigation in unknown environment with obstacle recognition using laser...
IJECEIAES
 
Impediment detection robot using Arduino
Impediment detection robot using ArduinoImpediment detection robot using Arduino
Impediment detection robot using Arduino
Ayush Chhangani
 
Sphero Write Up
Sphero Write UpSphero Write Up
Sphero Write Up
Sahil Parikh
 
Line maze solver
Line maze solverLine maze solver
Line maze solver
Sushil Dahal
 
A new approach for an intelligent swarm robotic system
A new approach for an intelligent swarm robotic systemA new approach for an intelligent swarm robotic system
A new approach for an intelligent swarm robotic system
eSAT Journals
 
Design and Construction of Line Following Robot using Arduino
Design and Construction of Line Following Robot using ArduinoDesign and Construction of Line Following Robot using Arduino
Design and Construction of Line Following Robot using Arduino
ijtsrd
 
Line Maze Solver Presentation
Line Maze Solver PresentationLine Maze Solver Presentation
Line Maze Solver Presentation
SoujanyaChatterjee1
 
Independent design project
Independent design projectIndependent design project
Independent design project
Fabian Okidi
 
Robotics- Naved
Robotics- NavedRobotics- Naved
Robotics- Naved
khwaja naved
 
Maze Solver Robot using Arduino
Maze Solver Robot using ArduinoMaze Solver Robot using Arduino
Maze Solver Robot using Arduino
GautamJagdhish
 
2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt
r_sadoun
 
Obstacle avoiding robot
Obstacle avoiding robotObstacle avoiding robot
Obstacle avoiding robot
Electronics - Embedded System
 
Obstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro ControllerObstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro Controller
Electronics - Embedded System
 
For hurdle detector using arduino and LM35
For hurdle detector using arduino and LM35For hurdle detector using arduino and LM35
For hurdle detector using arduino and LM35
ZainAhmed16414
 
Modelling of walking humanoid robot with capability of floor detection and dy...
Modelling of walking humanoid robot with capability of floor detection and dy...Modelling of walking humanoid robot with capability of floor detection and dy...
Modelling of walking humanoid robot with capability of floor detection and dy...
ijfcstjournal
 
Design and Fabrication of Obstacle Avoiding Robotic Vehicle
Design and Fabrication of Obstacle Avoiding Robotic VehicleDesign and Fabrication of Obstacle Avoiding Robotic Vehicle
Design and Fabrication of Obstacle Avoiding Robotic Vehicle
IRJET Journal
 
Paper robot
Paper robotPaper robot
Paper robot
Akhil Ajith
 
Ijetcas14 308
Ijetcas14 308Ijetcas14 308
Ijetcas14 308
Iasir Journals
 
Firebot
FirebotFirebot
Firebot
zaminkamil
 

Similar to Final Lab, Arduino Robot Challenge (20)

embedded system report
embedded system reportembedded system report
embedded system report
 
Robot navigation in unknown environment with obstacle recognition using laser...
Robot navigation in unknown environment with obstacle recognition using laser...Robot navigation in unknown environment with obstacle recognition using laser...
Robot navigation in unknown environment with obstacle recognition using laser...
 
Impediment detection robot using Arduino
Impediment detection robot using ArduinoImpediment detection robot using Arduino
Impediment detection robot using Arduino
 
Sphero Write Up
Sphero Write UpSphero Write Up
Sphero Write Up
 
Line maze solver
Line maze solverLine maze solver
Line maze solver
 
A new approach for an intelligent swarm robotic system
A new approach for an intelligent swarm robotic systemA new approach for an intelligent swarm robotic system
A new approach for an intelligent swarm robotic system
 
Design and Construction of Line Following Robot using Arduino
Design and Construction of Line Following Robot using ArduinoDesign and Construction of Line Following Robot using Arduino
Design and Construction of Line Following Robot using Arduino
 
Line Maze Solver Presentation
Line Maze Solver PresentationLine Maze Solver Presentation
Line Maze Solver Presentation
 
Independent design project
Independent design projectIndependent design project
Independent design project
 
Robotics- Naved
Robotics- NavedRobotics- Naved
Robotics- Naved
 
Maze Solver Robot using Arduino
Maze Solver Robot using ArduinoMaze Solver Robot using Arduino
Maze Solver Robot using Arduino
 
2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt
 
Obstacle avoiding robot
Obstacle avoiding robotObstacle avoiding robot
Obstacle avoiding robot
 
Obstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro ControllerObstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro Controller
 
For hurdle detector using arduino and LM35
For hurdle detector using arduino and LM35For hurdle detector using arduino and LM35
For hurdle detector using arduino and LM35
 
Modelling of walking humanoid robot with capability of floor detection and dy...
Modelling of walking humanoid robot with capability of floor detection and dy...Modelling of walking humanoid robot with capability of floor detection and dy...
Modelling of walking humanoid robot with capability of floor detection and dy...
 
Design and Fabrication of Obstacle Avoiding Robotic Vehicle
Design and Fabrication of Obstacle Avoiding Robotic VehicleDesign and Fabrication of Obstacle Avoiding Robotic Vehicle
Design and Fabrication of Obstacle Avoiding Robotic Vehicle
 
Paper robot
Paper robotPaper robot
Paper robot
 
Ijetcas14 308
Ijetcas14 308Ijetcas14 308
Ijetcas14 308
 
Firebot
FirebotFirebot
Firebot
 

Final Lab, Arduino Robot Challenge

  • 1. Wentworth Institute of Technology ELEC2950-02 Embedded Computer Systems Professor Marpaung: Final Exam Arduino-Robot Lab 2 December 2016 Lab Group: James Smith, Carlfred Malcolm
  • 2. Section1: Objectives Usingan Arduino,teamsof twoare taskedwithprogrammingarobot that can navigate a tape playing-field,picturedbelow, inordertoeitherknockdowna numberof waterbottles,orhuntdown the opposingteamsrobot.Thisisto be accomplishedusinganumberof sensors,including ultrasonic and infraredsensors.A whisker,orlance,maybe employedinthe knockingdownthe waterbottles, requiringamajoritytobe knockeddownbythe victoriousteam.Likewise,the whiskermaybe employed inhuntingdownthe opposingteams’robots. Huntingdownarobotrequiresthe robotor lance to make contact witheitherthe backor the sidesof the opposingrobot,the frontof the robotis notvulnerable to such attacks.These robotsare pittedagainstone another,inordertodiscover whose programwas mostsuccessful incompletingthe statedobjectives.Thiscompetitionwillbe organized intoasetof brackets. Playing-Field Design Section2: Flowchart Descriptionof Code Overall Flowchart
  • 3. Picturedabove isa simplifiedview of how the code we producedoperates.Whatoccursis,upon beginningthe code,infraredsensorsare readfromthe bottomof the robot, relaying information regardingthe colorvalue of the material underneaththe robot.Fromthese values,itcanbe attained howthe robot musttravel in orderto follow the blacktape linesof the playing-field;adjustingto continue onthe line,orcontinuingstraight.Thisinformation alsotellsuswhetherornotthe robothas reachedan intersectioninthe tape path.Withthisinformation,the robotproceedstocompletea specifiedtaskinorderto fulfillthe objectivesof the lab.This includes,butisnotlimitedto, turningleft at a four-wayor‘T’ intersection,decidingtoturnright or continue straight,ordecidingwhethertoturn leftor continue straight.Uponthe completionof anyof these tasks,includingthe tasksrequiredto followthe line,the code returnstothe beginningof the voidloop,inordertoscan the infraredsensors once again to receive uptodate informationaboutwhere onthe course the robotlies. In-Depth Flowchart
  • 4. In more detail,the code begins; proceedstoreadinfraredsensorsonthe bottomof the robot, of whichthere are five.Thisinformationis thenrelayedbacktothe Arduino,where these longvalues are roundedintoBooleanvalues,inordertomake themmore easilyusable.Withthisinformation,we can tell where onthe line the robotlies,forexample if the robothasdriftedtothe rightof the line,then the sensorsmayread that the centerand rightsensorsare on the black line,while the restof the sensorsremainabove the white playingfield.Withthisinformation,the robotentersanif statement that slowsdownthe opposite motorinordertoallow the robotto readjust,centeringthe robotonce again. The information gatheredbythe infraredsensors alsotellsuswhen the robothasenteredan intersection,readingall blacksduringafour-wayor‘T’intersectionforexample.Usingthisinformation, the type of intersection canbe conceived,allowingthe code toenterspecificif statements.If the robot detectsthatit has enteredafour-wayor‘T’ intersection,thenthe robotentersanif statement,witha for loopinorderto move the forwardslightly,becoming perpendiculartothe turn itis aboutto navigate;enteringanotherforloopthatspinsthe robotroughly90o to the left.Whenthe robotenters an intersectionforastraightor rightturn, theninitiallythe robotproceedsstraight.However,the robot thenaddsa unitof 1 to a counterfor these typesof intersectionswhichforcesthe robottotake a right wheneveritencounters anotherintersectionof thistype.Whenthe sensorstell usthatthe robothas enteredaleftor straightintersection,itwillinitiallyturnleft.Aftercompletingthisleft,avalue of 1 is addedto anotherseparate counter,forcingthe robottotravel straight duringthe itsnextencounter. Once the robot has traveledstraightthroughthisintersection,avalue of 1 issubtractedfrom this counter, allowingthe robottoturnleftduringthe nextintersectionof thistype.Afteranyof these commandshave beencompleted,the code returnstothe beginning,where itonce againscansthe infraredsensors,and relaystothe robothow to furtherproceed. Section3: Explanation ofCode Thisrobot reliesonanarray of five infraredsensorsinordertonavigate a tape playing-field, picturedabove insection1.These infraredsensorstell the robotwhere itisinrelationtothe linesof the playingfield,andisorganizedusingif statementstodecide how the enginesshouldmove.Inthe act of followingthese playing-fieldlines,the infraredsensorstell the robotwhere itisonthe playing-field, allowingthe programmingof the motorstoreact differently dependingonthe binarycombinationof these infraredsensors.Whenthe robothasdriftedrightorleft,the oppositemotoris slowedslightlyin orderto compensate forthis,andrecenterthe roboton the playing-fieldlines.These line following statementsonlyoccurduringtimesof none totwo sensorsregisteringablackline beneathit.Thisallows the robot to distinguishwhenitissimplyreadjustingtothe line,comparedtowhenitentersan intersection. Whena robot entersandintersection,the infraredsensorswillidentifythatthe entiretyof one side of the array is readinga blackline,withatleastthe far,opposite side sensorseeingthe white playingfield,orboththe far side sensorandthe sensorjustopposite the side of the intersection.What thismeansisthat, forexample,whenanintersectiononthe rightoccurs,eitheronlythe farleftsensor will detectthe white playingfield,orboththe leftandfar leftsensorwill.Itwasalsoclearwhena four- wayor ‘T’intersectionwasreached,becausebothof the outside sensorswoulddetectablacktape line. Upon enteringthese if statements,forloopsare employedinordertodirectthe robotto complete tasks that we dictate itto do. These include turningleftduringafour-wayor‘T’intersection,alternating
  • 5. betweenturningleftandproceedingstraightduringaleftside intersection,orrunningstraightforthe firstrightintersection,andturningrightduringthe restof them. The goal of these intersectioncommandswastoknock overthe water bottle objectivesas quicklyandconsistentlyaspossible.Inordertocomplete thisgoal,these intersectionswere strategically coded.The firstintersectionwasarightsidedintersection,whichthe robotcontinuedstraightthrough. The nextwas alsoa right sidedintersection,whichthe robotturnedrightandproceededtowardthe centerbottle.Uponhittingthe bottle,the robotenteredafour-wayintersection,whichitturnedleft and proceededtothe topof the playingfield. Thisledthe robottoa ‘T’ intersection,whichforcedthe robot to once againturn leftandproceedtothe bottle directlyinfrontof it,duringthe startof the competition.Afterhittingthisbottle,the robotturnsleftandbeginsalternatingbetweenstraight and leftacrossthe remainingleftsidedintersections.Thisallowedthe robottobegincircumnavigatingthe playing-field,keepingitfromreenteringthe middleof the field,andeventuallyreachingthe thirdbottle. Section4: Process and Creationof Code The developmentof thiscode wasnota linearpathbetweenbeginningtoend.Originally,for aroundthree weeks,the objective of the labandthe progressionof the code reliedonsolvingamaze designedintape,whichcontainedafewobstaclesinorderto maintainasense of randomnessand chaos.This employedthe use of infraredsensors,aswell asanultrasonicsensorwhichwasable to detectthe distance of an obstacle infrontof it usingsonartechnology.Astime continued,we beganto fleshoutthe workingsof bothtypesof sensors,aswell asan algorithmtocomplete amaze as quicklyas possible,usingideasfromthe Trémaux'salgorithm inordertomark intersectionsthe robothas previouslyvisitedinordertofindthe exitquicklyaswell asavoid travelingthroughthe same intersectiontwice unlessthere werenootheroptionspresent. Thisalgorithmwasscrappeduponthe redefiningof the labobjectives,changingthe goal of the labfromcompletingamaze,toknockingover bottlesina 2x2 square tile playingfield. Initially,muchof the time wasspenttweakingthe robotinorderto have enoughinformationto complete the course asquicklyaspossible.Thisrequiredaddingmore sensorstothe robot,addingtwo more sensorsto the bottomof the robot;the array now includesfiveinfraredsensorsascomparedto the original three.A photovoltaicsensorwasalsoaddedtothe frontof the robot inorderto distinguish whenan intersectionwasacorner of the playingfield,orwhenthe intersectionalsocontainedthe optionforthe robot to continue straight.The use of thisphotovoltaicsensorswasdumpedwhen consistencyof the readingvaluesbecameaproblemdue toshadowsit,amongotherthings,cast below thissensor,causingitto reada blackline beingthere regardlessof whetheritwasthere ornot. The ultrasonicsensorwasalsoplacedoutof commissionwhenthe robotnolongerneededtodetect whetherornot an obstacle stoodinitspath,and the objectiveswhereknownpriortothe start of the competition. Aftersuccessfullygettingthe sensorstoworkfairlyconsistentlyintandemwithone another,we beganto attemptto getthe robot to follow ablackline,experimentingwithmanystilesof loopsand statements.Startingwithwhile loops,whichseemedlikeanobviouschoice atthe time,buthavinglittle successwithoutlarge amountsorredundancy,readingthe sensorswithinmostloopsinorderto exitthe currentwhile loopandenteranother.Thismethodwastoyedwithforalong time,makingprogressand minorbreakthroughs,butafteralong time withslow progress,the entire code wasscrappedandbegun againwithif statements.Thisallowedforthe readingof the sensorstooccur initiallyinthe code,andbe
  • 6. returnedtouponthe completionof the if statement.Duringtesting,anelse statementwaspresentin orderto detectwhenthe robotenteredanarea,or receivedacombinationof sensorreadingsthatit had no combinationfor.Thiselse statementcausedthe robotprintthe phrase “Error!”, inorder to mark the combinationthatwaspreviouslyunaccountedfor,andspinina circle inplace until the robotwas shutoff.Thisstrategyallowedforthe fleshingoutof all possible combinationsinordertofollow aline veryrobustly,andwas testedunderconsiderablyroughcircumstances. Afterthe robotcouldaccuratelyand consistentlyfollow aline,astrategywasfleshedoutasto howthe robot was intendedtoproceedinordertoknockdownall three bottlesasquicklyaswe found possible.Usingcombinationsof binaryinputs,we were abletogothroughall possible combinationsof sensorreadings,from0.0.0.0.0 to 1.1.1.1.1, decidingwhateachcombinationwouldmeantothe robot, and whatcombinationswere unlikelyorimpossible tooccur underthese circumstances.Forloopswere usedinorderto have the robotreact to the intersectionsconsistently,requiringonlytweakingtoallow the robot to turn 90o , as well asfall centeredonthe nextline andcontinue straight.The elsestatement remained,allowingustoinclude combinationsthatoccurredwhichwe didnotfullyconsiderlikely,but occurredoccasionally,forexamplerunningintoanintersectionatthe same time thatthe robot was attemptingtoreadjusttofollowthe line.Thesemethodswere usedforroughlythreedifferent generationsof the same code,becomingbothmore robustandmore efficientwitheachnew iteration. Section5: Code Limitations The limitationsof the code include minorglitches,lackof anytype of defense from ahunting robot,as well asa predictabilityastowhere the robotisgoingto travel duringthe course.Much of the limitationsalsocame fromthe hardware of the robot,where duringthe competition,asensorwas disconnectedfromitsgroundingandnolongerreadproperly.The code itself alsoactedstrangely, stutteringoccasionallyduringtimesof steepadjustmenttofollowingthe line,whichdoesn’toccurwhile the robot itturningduringan intersectionnorwhenitisfollowingthe line straightforward,abugwhich I couldnot explainnorcouldIfix intime forthe competition.Of these minorglitchesincludedrare occasionswhere the robotwasveryoff track fromthe line while itenteredanintersection,providing false informationtothe robotand allowingittoact erraticallyinresponse tothese inputs.Because these glitcheshappenedveryrarely,the onlythingtobe done inorderto correct themismake the line followingalgorithmmore rigorousinordertonotbecome veryoff track often.Anotherlimitationof our code was originallythe code detectingafour-wayor‘T’intersectionrequiredall the sensorstodetecta blackline,causingproblemswhenthe robotcame inat an angle,thiswasfixedhoweverwhenthe parametersforthese intersectionswere changedinordertodetectwhenatleastboththe outside detectorsrecognize the blackline,insteadof all of themrecognizingthem.
  • 7. Section6: Photo Documentationof Process Step1: Travel through Step2: Turn Leftto Attack Step3: Turn Towards the PrimaryIntersection FirstBottle Outside of the Playing-Field Step4: Turn Leftto Attack Step5: Continue TowardsCorner Step6: BeginCircumnavigating SecondBottle Of the Playing-Field the Outside of the Playing-Field Section7: SkillsDevelopedandTested Thislab challengedmyabilitytothinkbothobjectivelyandcreativelyinordertocomplete the assignedtaskwithasmuch efficiencyandconsistencyaspossible withinalimitedtime span.Alongwith testingmyabilitytodesignandcreate workingcode, Iwasalso taskedwithcomingupwitha strategy for completingthe competitionfasterandmore consistentlythanmyfellow classmates. Inorderto compete withmyfellow classmates,Ineededtoemploythe use of sensorsasefficientlyandeffectively as possible.Thisallowedme toexperimentwithcodingnew typesof sensorsincludingthe ultrasonic sensor,the photovoltaicsensor,andthe infraredsensorswhichbecame the backbone of the code’s design.Duringthe original portionof the labalsoallowedme tolearnaboutsome of the many strategiesemployedinordertosolve a maze,aswell ashow to ussensorsinorderto make the robot react predictablytostimuli whichincludedfollowingaline,aswell asexecutingcommandsdepending on the orientation of saidline.Byimplementingall of the skillslearnedinthiscourse andthroughother codingprojects,Iwas able tomanipulate motorsandsensors,aswell asorganize the code intoefficient and understandablepieces. Otherskillstriedduringthisprocesswasorganizational,includingwritingdown the thought processthat I undertookinordertotry and solidifythe code andminimize redundancyandunnecessary pieceswithinthe code thatwouldotherwise provideglitches,andinefficiencieswithinthe code.This
  • 8. triedmyabilityasan engineertodefinethe problemasaccuratelyandeffectivelyaspossible inorderto approach an applicable solution. Section8: ClosingNotes Thislab provedtobe incrediblydifficultforanumberof reasons,of which the greatestenemy for me was time.Beingpresentedwithuniqueandchallengingproblems,likethislab,onlyworksto improve myabilitiesasanengineer.Ilookforwardtobeingpresentedwithotherchallengesinthe future andbelieve thatsome of the lessonsthatIhave gatheredthroughoutthisassignmentwill helpto shape unique andeffective solutionstoengineeringproblemsinthe future. AppendixA: Developmental Diary Date Time Things Accomplished Things Remaining 11/4 13:00 Attach three infrared sensorstothe robot. Attach ultrasonicsensortothe robot. Write code to read infraredsensors. Write code to read ultrasonicsensor. RoundSensorsintousable data. Code motorsto move whena blackline is detected. Designmaze solving algorithm. 11/9 12:00 CodedUltrasonicSensortodetect objectsinfrontof robot. RoundSensorsintousable data. Code motorsto move whena blackline is detected. Designmaze solving algorithm. 11/11 13:00 Addadditional infraredsensors, makingthe total numberof infrared sensors5. Adda photocell andwrite code to include it. RoundsensorvaluestoBooleanor intin centimetersforthe ultrasonic sensors. Code motorsin orderto follow aline. Designanalgorithmto solve amaze. 11/16 12:00 Attempttofollow aline usingwhile loops,little success. Reevaluate new goalsbasedonnew labparameters. Decide ona strategyto knockdownbottles,or huntdownopposing robots. Code motorsto followa line. 11/18 13:00 Decide onhow to proceedwithnew labparameters,begintodiscuss Successfullyfollow aline.
  • 9. Date Time Things Accomplished Things Remaining possible optionsforcompleting assignment. Redesignstrategyemployedin followingaline,beganworkingwith if statementsopposedtowhile loops. Discontinue the use of boththe Ultrasonicsensoras well asthe photovoltaiccell. Solidifyaplanof action for knockingdownbottles, huntingopposingrobots deemedtooinefficient and unreliable. 11/22 12:00 Beginto follow aline,andfleshout sumtotal of all possibilitiesof adjustingtofollow the line. Developastrategyforknocking downbottles. Effectivelyand consistentlyfollow aline. Code decisionmakinginto the robot to take turns that knockoverall the bottles. 11/23 12:00 Successfullyfollow aline 9/10 times and undermoderatelytough circumstances. Codingthe abilitytoturn at intersectionsinorderto knockoverbottles. 11/25 19:00 Write downobjectivesof the code, allowingforamore solidifiedideaof whatthe robothas to accomplish and how it maybe able todo that. Scrap original code,savingsome piecesfromthe line following algorithm. Codingthe abilitytoturn at intersectionsinorderto knockoverbottles. Effectivelyand consistentlyfollow aline. 11/26 18:30 Write code that allowsforthe turningof the robotat intersections usingforloops. Tweakfor loopstoturn 90o and remainonthe targetedline. Effectivelyand consistentlyfollow aline. 11/27 15:00 Write algorithmthatreliesona counterto decide whetherornot to take the turn presentedtothe robot,a keypart inthe actual functioningof the robot. Testthe code on the robot and continue tofleshout if statementsasthe robot detectserrors. 11/29 12:00 Addmore if statementsandtweak statementconditionsinorderto have a robust algorithmthatrarely ran intoproblemsthatwould otherwise stopthe robot. Tweakfor loopstobecome more precise duringturns. Complete the course with consistency. Tweakcode to try and workpast minorglitches that occurred,including reachingan intersection while alsoadjustingtothe line. 12/1 12:00 Complete the course withthe robot knockingdownall the bottlesa majorityof the time. Minor tweakingtothe code to fix minorbugsand make turns more precise
  • 10. Date Time Things Accomplished Things Remaining 12/2 7:00 Solidifyforloopsandconfirmthe properfunctioningof the robotprior to the competition’sopening. Compete. AppendixB-1: Code on November5, 2016 #include <SoftwareSerial.h> SoftwareSerial BTserial(2,3);//TX,RX intleft; intcenter; intright; longresult=0; voidsetup(void) { Serial.begin(9600); pinMode(13,OUTPUT); //RightWheel pinMode(12,OUTPUT); //LeftWheel pinMode(11,INPUT);//UltrasonicSensor } voidloop() { left=IRScan(6); center=IRScan(7); right=IRScan(8); delay(10); Serial.print("Left"); Serial.print(left); Serial.print("Center"); Serial.print(center); Serial.print("Right");
  • 11. Serial.print(right); Serial.println(""); } longIRScan(intsensPin) { longresult= 0; pinMode(sensPin,OUTPUT);//make pinOUTPUT digitalWrite(sensPin,HIGH);//make pinHIGH to discharge capacitor - studythe schematic delay(1);//waita ms tomake sure cap isdischarged pinMode(sensPin,INPUT);//turnpinintoan inputand time till pingoeslow digitalWrite(sensPin,LOW);//turnpullupsoff - or itwon't work while(digitalRead(sensPin)){ //waitforpintogo low result++; } returnresult;//WithLight:Black=White=Blue= } AppendixB-2: Code on November12, 2016 #include <SoftwareSerial.h> SoftwareSerial BTserial(2,3);//TX,RX intleft; intcenter; intright; inti = 0; longresult=0; unsignedlongDistance =0; intUSsensor= 11; // Ultrasoundsignal pin unsignedlongUSvalue =0; voidsetup(void) {
  • 12. Serial.begin(9600); pinMode(13,OUTPUT); //RightWheel pinMode(12,OUTPUT); //LeftWheel pinMode(USsensor,OUTPUT);//UltrasonicSensor } voidloop() { left=IRScan(6); center=IRScan(7); right=IRScan(8); delay(10); Serial.print("Left"); Serial.print(left); Serial.print("Center"); Serial.print(center); Serial.print("Right"); Serial.print(right); Serial.println(""); i = US(); Serial.print(i); Serial.println("CM"); delay(250);//delay1/4seconds. } longIRScan(intsensPin) { longresult= 0; pinMode(sensPin,OUTPUT);//make pinOUTPUT digitalWrite(sensPin,HIGH);//make pinHIGH to discharge capacitor- studythe schematic delay(1);//waita ms tomake sure cap isdischarged
  • 13. pinMode(sensPin,INPUT);//turnpinintoan inputand time till pingoeslow digitalWrite(sensPin,LOW);//turnpullupsoff - or itwon't work while(digitalRead(sensPin)){ //waitforpintogo low result++; } returnresult;//WithLight:Black=White=Blue= } unsignedlongUS() { pinMode(USsensor,OUTPUT);//Switchsignalpintooutput digitalWrite(USsensor,LOW);//Sendlow pulse delayMicroseconds(2);//Wait for 2 microseconds digitalWrite(USsensor,HIGH);//Sendhighpulse delayMicroseconds(5);//Waitfor 5 microseconds digitalWrite(USsensor,LOW);//Holdoff pinMode(USsensor,INPUT);//Switchsignalpintoinput digitalWrite(USsensor,HIGH);//Turn on pullupresistor // please note thatpulseInhasa1sec timeout,whichmay // notbe desirable.Dependingonyoursensorspecs,you // can likelyboundthe time like this -- marcmerlin // Distance = pulseIn(USsensor,HIGH,38000) Distance = pulseIn(USsensor,HIGH);//ListenforDistance USvalue = (Distance /58.138); //converttoCM returnUSvalue; } AppendixB-3: Code on November19, 2016 intFleft,left,Fright,right,center,reach,i=0,pivot=0; booleanFL,L, C, R, FR; longresult=0;
  • 14. unsignedlongDistance =0; intUSsensor= 11; // Ultrasoundsignal pin unsignedlongUSvalue =0; voidsetup(void) { Serial.begin(9600); pinMode(13,OUTPUT); //RightWheel pinMode(12,OUTPUT); //LeftWheel pinMode(USsensor,OUTPUT);//UltrasonicSensor } voidloop() { // ScanningUnderbelly,IRScanners Fright=IRScan(8); right=IRScan(5); center=IRScan(7); left=IRScan(9); Fleft=IRScan(6); if(Fright>200){ FR=1; } else FR=0; if(right>200){ R=1; } else R=0; if(center>200){ C=1; }
  • 15. else C=0; if(left>200){ L=1; } else L=0; if(Fleft>200){ FL=1; } else FL=0; Serial.print("FarLeft"); Serial.print(FL); Serial.print("Left"); Serial.print(L); Serial.print("Center"); Serial.print(C); Serial.print("Right"); Serial.print(R); Serial.print("FarRight"); Serial.print(FR); Serial.println(""); if( FL==0 && L==0 && C==1 && R==0 && FR==0){//StraightForward digitalWrite(13,HIGH); delayMicroseconds(1400); digitalWrite(13,LOW); delay(10); digitalWrite(12,HIGH); delayMicroseconds(1600); digitalWrite(12,LOW); delay(10);
  • 16. } else if( FL==0 && L==0 && C==1 && R==1 && FR==0){//AdjustLeft digitalWrite(13,HIGH); delayMicroseconds(1350); digitalWrite(13,LOW); delay(10); digitalWrite(12,HIGH); delayMicroseconds(1600); delay(10); } else if( FL==0 && L==0 && C==1 && R==1 && FR==1){ for (pivot=0;pivot<60;pivot++)//Pivotthe Robotright,approximately90 degrees { digitalWrite(13,HIGH); delayMicroseconds(1300);//RigthMotorStandstill digitalWrite(13,LOW); delay(10); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorBackwards digitalWrite(12,LOW); delay(10); } } else if( FL==0 && L==0 && C==1 && R==1 && FR==1){//RigthTurn or Straight } else if( FL==0 && L==1 && C==1 && R==0 && FR==0){//AdjustRight digitalWrite(13,HIGH); delayMicroseconds(1300); digitalWrite(13,LOW);
  • 17. delay(10); digitalWrite(12,HIGH); delayMicroseconds(1550); delay(10); } else if( FL==1 && L==1 && C==1 && R==0 && FR==0){ for (pivot=0;pivot<60;pivot++)//Pivotthe Robotleft,approximately90degrees { digitalWrite(13,HIGH); delayMicroseconds(1700); digitalWrite(13,LOW); delay(10); digitalWrite(12,HIGH); delayMicroseconds(1700); digitalWrite(12,LOW); delay(10); } } else if( FL==1 && L==1 && C==1 && R==0 && FR==0){//LeftTurn or Straight } else if( FL==1 && L==1 && C==1 && R==1 && FR==1){//T-Intersection } else if( FL==0 && L==0 && C==1 && R==0 && FR==0){//4-WayIntersection } } longIRScan(intsensPin) { longresult= 0; pinMode(sensPin,OUTPUT);
  • 18. digitalWrite(sensPin,HIGH); delay(1); pinMode(sensPin,INPUT); digitalWrite(sensPin,LOW); while(digitalRead(sensPin)) { result++; } returnresult; } AppendixC: Final Code intFright,right,center,left,Fleft,motion,d=0,a=0; booleanFL,L, C, R, FR; longresult=0; voidsetup(void) { Serial.begin(9600); pinMode(13,OUTPUT);//RightWheel Forward == 1700 pinMode(12,OUTPUT);//LeftWheel Forward== 1300 } voidloop() { //ScanningUnderbelly,IRScanners ------------------------------------------------------------------ right=IRScan(5); Fleft=IRScan(6); center=IRScan(7); Fright=IRScan(8); left=IRScan(9);
  • 19. //RoundingIRSensorstoBinary ----------------------------------------------------------------------- if(Fright>200){ FR=1;} else FR=0; if(right>200){ R=1;} else R=0; if(center>200){ C=1;} else C=0; if(left>200){ L=1;} else L=0; if(Fleft>200){ FL=1;} else FL=0; //PrintSensorValuesforTroubleshooting ------------------------------------------------------------ Serial.print("FarLeft"); Serial.print(FL); Serial.print("Left"); Serial.print(L); Serial.print("Center"); Serial.print(C); Serial.print("Right"); Serial.print(R); Serial.print("FarRight"); Serial.print(FR);
  • 20. Serial.println(""); //BasicLine FollowingCommands ------------------------------------------------------------------------ if( FL==0 && L==0 && C==1 && R==0 && FR==0){//StraightForward digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12, HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==0 && C==0 && R==0 && FR==0){//StraightForward digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13, LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==0 && C==1 && R==1 && FR==0){//AdjustLeft digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH);
  • 21. delayMicroseconds(1475);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==1 && C==1 && R==0 && FR==0){//AdjustRight digitalWrite(13,HIGH); delayMicroseconds(1525);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==1 && C==0 && R==0 && FR==0){//AdjustRight digitalWrite(13,HIGH); delayMicroseconds(1525);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==1 && L==1 && C==0 && R==0 && FR==0){//AdjustRight digitalWrite(13,HIGH); delayMicroseconds(1525);//RightWheel digitalWrite(13,LOW); delay(5);
  • 22. digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==1 && L==0 && C==0 && R==0 && FR==0){//AdjustRight digitalWrite(13,HIGH); delayMicroseconds(1500);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==0 && C==0 && R==1 && FR==0){//AdjustLeft digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1475);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==0 && C==0 && R==1 && FR==1){//AdjustLeft digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13,LOW);
  • 23. delay(5); digitalWrite(12,HIGH); delayMicroseconds(1475);//LeftWheel digitalWrite(12,LOW); delay(5); } else if( FL==0 && L==0 && C==0 && R==0 && FR==1){//AdjustLeft digitalWrite(13,HIGH); delayMicroseconds(1700);//RightWheel digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1500);//LeftWheel digitalWrite(12,LOW); delay(5); } //IntersectionCommands //StraightRight------------------------------------------------------------------------------------- else if((FL==0&& L==0 && C==1 && R==1 && FR==1)||(FL==0 && L==1 && C==1 && R==1 && FR==1)){//StraightRight if(d==0){//FirstIntersection,Straight for(motion=0;motion<20;motion++){//StraighttoExitIntersection digitalWrite(13,HIGH); delayMicroseconds(1700);//RightMotorForward digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorForward
  • 25. //LeftAnything-------------------------------------------------------------------------------------- else if((FL==1&& L==1 && C==1 && R==0 && FR==0)||(FL==1 && L==1 && C==1 && R==1 && FR==0)){//LeftAnything if(a==0){//TurnLeft for(motion=0;motion<13;motion++){//InchForward digitalWrite(13,HIGH); delayMicroseconds(1700);//RightMotorForward digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorForward digitalWrite(12,LOW); delay(5); } for(motion=0;motion<42;motion++){//TurnLeft digitalWrite(13,HIGH); delayMicroseconds(1300);//RightMotorBackward digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorForward digitalWrite(12,LOW); delay(5); } a++; } else if(a==1){//Move Straight for(motion=0;motion<20;motion++){ digitalWrite(13,HIGH);
  • 26. delayMicroseconds(1700);//RightMotorForward digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorForward digitalWrite(12,LOW); delay(5); } a--; } } //T-Intersection/4-Way----------------------------------------------------------------------------- else if( FL==1 && FR==1){ for(motion=0;motion<13;motion++){//InchForwardSlightly digitalWrite(13,HIGH); delayMicroseconds(1700);//RightMotorForward digitalWrite(13,LOW); delay(5); digitalWrite(12,HIGH); delayMicroseconds(1300);//LeftMotorForward digitalWrite(12,LOW); delay(5); } for(motion=0;motion<42;motion++){//TurnLeft digitalWrite(13,HIGH); delayMicroseconds(1300);//RightMotorBackward digitalWrite(13,LOW); delay(5);