LAFVIN 4WD Smart Robot Car Kit V2.2-compressed.pdf

xn761 59 views 184 slides Aug 21, 2024
Slide 1
Slide 1 of 256
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149
Slide 150
150
Slide 151
151
Slide 152
152
Slide 153
153
Slide 154
154
Slide 155
155
Slide 156
156
Slide 157
157
Slide 158
158
Slide 159
159
Slide 160
160
Slide 161
161
Slide 162
162
Slide 163
163
Slide 164
164
Slide 165
165
Slide 166
166
Slide 167
167
Slide 168
168
Slide 169
169
Slide 170
170
Slide 171
171
Slide 172
172
Slide 173
173
Slide 174
174
Slide 175
175
Slide 176
176
Slide 177
177
Slide 178
178
Slide 179
179
Slide 180
180
Slide 181
181
Slide 182
182
Slide 183
183
Slide 184
184
Slide 185
185
Slide 186
186
Slide 187
187
Slide 188
188
Slide 189
189
Slide 190
190
Slide 191
191
Slide 192
192
Slide 193
193
Slide 194
194
Slide 195
195
Slide 196
196
Slide 197
197
Slide 198
198
Slide 199
199
Slide 200
200
Slide 201
201
Slide 202
202
Slide 203
203
Slide 204
204
Slide 205
205
Slide 206
206
Slide 207
207
Slide 208
208
Slide 209
209
Slide 210
210
Slide 211
211
Slide 212
212
Slide 213
213
Slide 214
214
Slide 215
215
Slide 216
216
Slide 217
217
Slide 218
218
Slide 219
219
Slide 220
220
Slide 221
221
Slide 222
222
Slide 223
223
Slide 224
224
Slide 225
225
Slide 226
226
Slide 227
227
Slide 228
228
Slide 229
229
Slide 230
230
Slide 231
231
Slide 232
232
Slide 233
233
Slide 234
234
Slide 235
235
Slide 236
236
Slide 237
237
Slide 238
238
Slide 239
239
Slide 240
240
Slide 241
241
Slide 242
242
Slide 243
243
Slide 244
244
Slide 245
245
Slide 246
246
Slide 247
247
Slide 248
248
Slide 249
249
Slide 250
250
Slide 251
251
Slide 252
252
Slide 253
253
Slide 254
254
Slide 255
255
Slide 256
256

About This Presentation

for lafvin4wd smart robot kit


Slide Content

4WDSmartRobotCarKitV2.2

Content
LAFVINSmartRobotCarKitV2Introduction.................................................................................................2
Lesson1GettingStartedwithArduinoIDE.......................................................................................................7
HowtoInstallArduinoIDE...........................................................................................................................7
HowtoInstallArduinoDriver.....................................................................................................................15
HowtoAddLibraries...................................................................................................................................22
BlinkTest(Testyourfirstprogram)..............................................................................................................26
Lesson2GettingStartedwithMixly................................................................................................................41
IntroductionofMixlySoftware...................................................................................................................41
HowtoInstallMixlySoftware.....................................................................................................................46
HowtoAddMixlyLibraries........................................................................................................................49
HowtoUploadtheReferenceProgram.......................................................................................................54
Lesson3MotorSpeedandDirectionControl.................................................................................................104
Lesson4LineTrackingSmartCar..................................................................................................................112
Lesson5UltrasonicInfraredObstacleAvoidanceRobotCar........................................................................133
Lesson6UltrasonicFollowRobotCar...........................................................................................................169
Lesson7InfraredRemoteControlRobotCar................................................................................................179
Lesson8LightSeekingRobotCar..................................................................................................................186
Lesson9BluetoothControlRobotCar...........................................................................................................196
6in1Multi-purposeBluetoothRobotCar......................................................................................................232

CompanyProfile
Establishedin2011,LAFVINisamanufacturerandtraderspecializedinresearch,developmentandproductionofMega2560,UNO,Nano
boards,andallkindsofaccessoriesorsensorsuseforArduino,raspberry.Wealsocompletestarterkitsdesignedforinterestedloversofanylevels
tolearnArduinoorRaspberry.WearelocatedinShenzhen,China.Allofourproductscomplywithinternationalqualitystandardsandaregreatly
appreciatedinavarietyofdifferentmarketsthroughouttheworld.
CustomerService
Wearecooperatingwithalotofcompaniesfromdifferentcountries.Alsohelpthemtopurchaseelectroniccomponentproductsinchina,and
becamethebiggestsupplierofthem.Welookforwardtobuildcooperatewithmorecompaniesinfuture.
Bytheway,Wealsolookforwardtohearingfromyouandanyofyourcriticalcommentorsuggestions.Plsemailusbylafvin_service@163.com
ifyouhaveanyquestionsorsuggestions.Asacontinuousandfastgrowingcompany.Wekeepstrivingourbesttoofferyouexcellentproducts
andqualityservice.
OurStore
Aliexpressstore:https://www.aliexpress.com/store/1942043BrandinAmazon:LAFVIN
ProductCatalog
https://drive.google.com/drive/folders/0BwvEeRN9dKllblZING00TkhYbGs?usp=sharing
Tutorial
Thistutorialincludecodes,libraries,lessonsandinstallationguidevideo.Itisdesignedforbeginners.Itwillteacheveryusershowtoassembly
therobotcaranduseArduinoUNOcontrollerboard,sensors,servoandBluetoothmodule.SimultaneouslysupportsMixlygraphical
programmingandArduinoIDEcodeprogramming,whichisconvenientforbeginnerstolearn.Provide3Ddynamicinstallationtutorialto
quicklybuildyourrobotcar.Thepowersupplyusestwo18650lithiumbatterieswithlong-lastingbatterylife.ThenewlycreatedAPPcontrol
software,the6majorfunctionsoftherobotcarkitarecomprehensivelycontrolledbytheAPP,andthefunctionmodecanbeswitchedfreely.

1/252

2/252
LAFVINSmartRobotCarKitV2Introduction
SmartRobotCarKitV2.0ismainlymanufacturedusingtheArduinoUNOR3maincontrolandtheMotordriveexpansion
board,tworeductionmotors,Acrylicframechassisandsomesensors.
LAFVINSmartRobotCarKitV2havethefollowingadvantages:
1)Arduinomotordriveshieldintegratesthedriverchip,eliminatingthetraditionalcomplexwiringandinstallation
space.Theshieldusesstandardinterfacewiring,simpleandeasytounderstand,fastinstallationwiring.

3/252
2)ThenewlycreatedAPPcontrolsoftware,the6majorfunctionsoftherobotcarkitarecomprehensivelycontrolledbythe
APP,andthefunctionmodecanbeswitchedfreely.6in1Multi-purposeBluetoothRobotCar

4/252
3)ThenewlydesignedBluetoothmoduleisconnectedtothecircuit,andtheuploadprogramdoesnotrequiremanual
disconnectionoftheBluetoothmodule.Helpbeginnerlearnerstosuccessfullyavoidthetrapofuploadingprogramfailure.

5/252
4)SimultaneouslysupportsmixlygraphicalprogrammingandarduinoIDEcodeprogramming,whichisconvenientfor
beginnerstolearn.

6/252
5)Provide3Ddynamicinstallationtutorialtoquicklybuildyourrobotcar.Thepowersupplyusestwo18650lithium
batterieswithlong-lastingbatterylife.

7/252
Lesson1GettingStartedwithArduinoIDE
HowtoInstallArduinoIDE
Introduction
TheArduinoIntegratedDevelopmentEnvironment(IDE)isthesoftwaresideoftheArduinoplatform.InthisProject,you
willlearnhowtosetupyourcomputertouseArduinoandhowtosetabouttheProjectsthatfollow.TheArduinosoftware
thatyouwillusetoprogramyourArduinoisavailableforWindows,MacandLinux.Theinstallationprocessisdifferentfor
allthreeplatformsandunfortunatelythereisacertainamountofmanualworktoinstallthesoftware.
STEP1:Gotohttps://www.arduino.cc/en/Main/Softwareandfindbelowpage.
Theversionavailableatthiswebsiteisusuallythelatestversion,andtheactualversionmaybenewerthanthe
versioninthepicture.

8/252
STEP2

Downloadthedevelopmentsoftwarethatiscompatiblewiththeoperatingsystemofyourcomputer.
TakeWindowsasanexamplehere.

9/252
ClickWindowsInstaller.
ClickJUSTDOWNLOAD.
Alsoversion1.8.0isavailableinthematerialweprovided,andtheversionsofour
materialsarethelatestversionswhenthiscoursewasmade.

10/252
InstallingArduino(Windows)
InstallArduinowiththeexe.Installationpackage.
ClickIAgreetoseethefollowinginterface

11/252
ClickNext

12/252
YoucanpressBrowse
tochooseaninstallationpathordirectlytypeinthedirectoryyouwant.
ClickInstalltoinitiateinstallation

13/252
Waitfortheinstallingprocess,ifappeartheinterfaceofWindowSecurity,justcontinuetoclick
Installtofinishtheinstallation.
Next,thefollowingiconappearsonthedesktop

14/252
Double-clicktoenterthedesireddevelopmentenvironment

15/252
HowtoInstallArduinoDriver
Next,wewillintroducethedriverinstallationofUNOR3developmentboard.Thedriverinstallationmayhaveslight
differencesindifferentcomputersystems.Sointhefollowinglet’smoveontothedriverinstallationintheWindowsystem.
TheArduinofoldercontainsboththeArduinoprogramitselfandthedriversthatallowtheArduinotobeconnectedtoyour
computerbyaUSBcable.BeforewelaunchtheArduinosoftware,youaregoingtoinstalltheUSBdrivers.
WhenyouconnectUNOboardtoyourcomputeratthefirsttime,rightclicktheiconofyour
“Computer”—>for“Properties”—>clickthe“Devicemanager”,
under“OtherDevices”or“USB-Serial”,youshouldseeaniconfor“Unknowndevice”withalittleyellowwarningtriangle
nexttoit.ThisisyourArduino.Oryoucansearchfor"devi"inyourcomputer,oryoucanopenthedevicemanagerofyour
computer.

16/252

17/252
Thenright-clickonthedeviceandselectthetopmenuoption(UpdateDriverSoftware...)shownasthefigurebelow.

18/252
Thenitwillbepromptedtoeither“SearchAutomaticallyforupdateddriversoftware”or“Browsemycomputerfordriver
software”.Shownasbelow.Inthispage,select“Browsemycomputerfordriversoftware”.
Right-clickonthedeviceandselectthetopmenuoption(UpdateDriverSoftware...).

19/252
Youwillthenbepromptedtoeither‘SearchAutomaticallyforupdateddriversoftware’or‘Browsemycomputerfordriver
software’.Selecttheoptiontobrowseandnavigatetothe:C\ProgramFiles(x86)\Arduino\drivers.(Note:Hereisthepath
youchoosetoinstallarduinoIDE.Thepathchosenintheinstallationtutorialintheprevioussectionisthat,sothepathI
choseisC\ProgramFiles(x86)\Arduino\drivers)

20/252
Click“Next”andyoumaygetasecuritywarning,ifso,allowthesoftwaretobeinstalled.
Oncethesoftwarehasbeeninstalled,youwillgetaconfirmationmessage.Installationcompleted,click“Close”.

21/252
Uptonow,thedriverisinstalledwell.Thenyoucanrightclick“Computer”—>“Properties”—>“Devicemanager”,you
shouldseethedeviceasthefigureshownbelow.

22/252
HowtoAddLibraries
InstallingAdditionalArduinoLibraries
OnceyouarecomfortablewiththeArduinosoftwareandusingthebuilt-infunctions,youmaywanttoextendtheabilityof
yourArduinowithadditionallibraries.
WhatareLibraries?
Librariesareacollectionofcodethatmakesiteasyforyoutoconnecttoasensor,display,module,etc.Forexample,the
built-inLiquidCrystallibrarymakesiteasytotalktocharacterLCDdisplays.Therearehundredsofadditionallibraries
availableontheInternetfordownload.Thebuilt-inlibrariesandsomeoftheseadditionallibrariesarelistedinthereference.
Tousetheadditionallibraries,youwillneedtoinstallthem.
HowtoInstallaLibrary

23/252
Importinga.zipLibrary
LibrariesareoftendistributedasaZIPfileorfolder.Thenameofthefolderisthenameofthelibrary.Insidethefolderwill
bea.cppfile,a.hfileandoftenakeywords.txtfile,examplesfolder,andotherfilesrequiredbythelibrary.youcaninstall
3rdpartylibrariesintheIDE.Donotunzipthedownloadedlibrary,leaveitasis.
IntheArduinoIDE,navigatetoSketch>IncludeLibrary.Atthetopofthedropdownlist,selecttheoptionto"Add.ZIP
Library''.

24/252
Youwillbepromptedtoselectthelibraryyouwouldliketoadd.Navigatetothe.zipfile'slocationandopenit.
(Note:Thisisjusttodemonstratehowtoaddaziplibraryfile,whetheryouneedtoaddalibraryfiledependsonyouractual
programneeds)

25/252
ReturntotheSketch>ImportLibrarymenu.Youshouldnowseethelibraryatthebottomofthedrop-downmenu.Itis
readytobeusedinyoursketch.ThezipfilewillhavebeenexpandedinthelibrariesfolderinyourArduinosketches
directory.
NB:theLibrarywillbeavailabletouseinsketches,butexamplesforthelibrarywillnotbeexposedintheFile>Examples
untilaftertheIDEhasrestarted.
Thosetwoarethemostcommonapproaches.MACandLinuxsystemscanbehandledlikewise.Themanualinstallationto
beintroducedbelowasanalternativemaybeseldomusedanduserswithnoneedsmayskipit.

26/252
BlinkTest(Testyourfirstprogram)
youwilllearnhowtoprogramyourUNOcontrollerboardtoblinktheArduino’sbuilt-inLED,andhowtodownload
programsbybasicsteps.
TheUNOboardhasrowsofconnectorsalongbothsidesthatareusedtoconnecttoseveralelectronicdevicesandplug-in
'shields'thatextendsitscapability.
ItalsohasasingleLEDthatyoucancontrolfromyoursketches.ThisLEDisbuiltontotheUNOboardandisoften
referredtoasthe'L'LEDasthisishowitislabeledontheboard.

27/252
YoumayfindthatyourUNOboard's'L'LEDalreadyblinkswhenyouconnectittoaUSBplug.Thisisbecausetheboards
aregenerallyshippedwiththe'Blink'sketchpre-installed.
InthisProject,wewillreprogramtheUNOboardwithourownBlinksketchandthenchangetherateatwhichitblinks.
Inthepreviouschapter-HowtoinstallArduinoIDE,yousetupyourArduinoIDEandmadesurethatyoucouldfindthe
rightserialportforittoconnecttoyourUNOboard.Thetimehasnowcometoputthatconnectiontothetestandprogram
yourUNOboard.
TheArduinoIDEincludesalargecollectionofexamplesketchesthatyoucanloadupanduse.Thisincludesanexample
sketchformakingthe'L'LEDblink.
Loadthe'Blink'sketchthatyouwillfindintheIDE'smenusystemunderFile>Examples>01.Basics

28/252
Whenthesketchwindowopens,enlargeitsothatyoucanseetheentiresketchinthewindow.

29/252
TheexamplesketchesincludedwiththeArduinoIDEare'read-only'.Thatis,youcanuploadthemtoanUNOR3board,but
ifyouchangethem,youcannotsavethemasthesamefile.
Sincewearegoingtochangethissketch,thefirstthingyouneedtodoissaveyourowncopy.
FromtheFilemenuontheArduinoIDE,select'SaveAs..'andthensavethesketchwiththename'MyBlink'.

30/252
Youhavesavedyourcopyof'Blink'inyoursketchbook.Thismeansthatifyoueverwanttofinditagain,youcanjust
openitusingtheFile>Sketchbookmenuoption.

31/252
AttachyourArduinoboardtoyourcomputerwiththeUSBcableandcheckthatthe
'BoardType'and'SerialPort'aresetcorrectly.

32/252

33/252

34/252
Note:TheBoardTypeandSerialPortherearenotnecessarilythesameasshowninpicture.IfyouareusingUNO,
thenyouwillhavetochooseArduinoUNOastheBoardType,otherchoicescanbemadeinthesamemanner.And
theSerialPortdisplayedforeveryoneisdifferent,despiteCOM6chosenhere,itcouldbeCOM3orCOM4onyour
computer.ArightCOMportissupposedtobeCOMX(arduinoXXX),whichisbythecertificationcriteria.
TheArduinoIDEwillshowyouthecurrentsettingsforboardatthebottomofthewindow.
Clickonthe'Upload'button.Thesecondbuttonfromtheleftonthetoolbar.
IfyouwatchthestatusareaoftheIDE,youwillseeaprogressbarandaseriesofmessages.Atfirst,itwillsay'Compiling
Sketch...'.Thisconvertsthesketchintoaformatsuitableforuploadingtotheboard.

35/252
]
Next,thestatuswillchangeto'Uploading'.Atthispoint,theLEDsontheArduinoshouldstarttoflickerasthesketchis
transferred.

36/252
Finally,thestatuswillchangeto'Doneuploading'.
Afteruploadingthecode,youwillseethatthe"L"LEDontheArduinoUNOmotherboardwilllightupfor1second,and
thenturnofffor1second,andtheprocesswillcontinuetoloop.

37/252

38/252
Ifyouaremissingsomesteps,ArduinoIDEmayreportsomeerrors.Youcanrefertothefollowingsolutions.
(1)Itmeansthatyourboardisnotconnectedatall,orthedrivershavenotbeeninstalled(ifnecessary)orthatthewrong
serialportisselected.HowtoInstallArduinoDriver

39/252
(2)Itmeansthatthecommunicationserialportforuploadingcodeisoccupied.IfyouconnecttheBluetoothmodulewhen
uploadingthecode,youneedtodisconnecttheBluetoothmodulefromtheArduinoUNOexpansionboard,andthen
reinstalltheBluetoothmoduleafteruploading.
AnotherpossibilityisthattheUSBinterfaceoftheArduinoUNOisinsufficientlypowered,andyouneedtoturnonthe
externalpowerswitchoftheexpansionboard.

40/252
(3)Ifyouneedtouselibraryfilesinsomeprojectprograms,youmayencounterthiserror.
Itmeansthatsomelibraryfilesareusedinthecode,butyoudidnotaddthecorrespondinglibraryfilestothearduinoIDE
beforeuploadingthecode.HowtoAddLibraries

41/252
Lesson2GettingStartedwithMixly
IntroductionofMixlySoftware
Mixlyisafreeopen-sourcegraphicalArduinoprogrammingsoftware,basedonGoogle’sBlocklygraphicalprogramming
framework,anddevelopedbyMixlyTeam@BNU.Itisafreeopen-sourcegraphicalprogrammingtoolforcreative
electronicdevelopment;acompletesupportecosystemforcreativee-education;astageformakereducatorstorealize
theirdreams.AlthoughthereisanArdublockgraphicalprogrammingsoftwarelaunchedbyArduinoofficial,Ardublockis
notperfectenough,andmanycommonfunctionscannotberealized.
DesignConcept:
(1)Usability
Mixlyisdesignedtobecompletelygreen.Currently.ItcanrunonWindowsxpandabove.
(2)Simplicity
MixlyusestheBlocklygraphicalprogrammingenginetoreplacecomplextextmanipulationwithgraphicalbuilding
blocks,providingagoodfoundationforbeginnerstogetstartedquickly.

42/252
1Usethedifferentcoloriconstorepresentdifferenttypesoffunctionalblocks,veryconvenientforuserstoclassify.
2Providedefaultoptionsinthecompositefunctionblocktoeffectivelyreducethenumberofuserdrags.
3Integrateallthefeaturesofthesoftwareinthesameinterface.
4Providethereferencetutorialandcodeexamples.
(3)Functionality
Ithasversatilefunctions.MixlycanalmostimplementallthefunctionsthatArduinoIDEhas.Supportallofficial
developmentboardsofarduino.
(4)Continuity
Thegoalofthegraphicalprogrammingsystemisdefinitelynottoreplacetheoriginaltextprogrammingmethod,butto
betterunderstandtheprogrammingprinciplesandprogramthinkingthroughgraphicalprogramming,andlaythe
foundationforfuturetextprogramming.ItisalsothedesignphilosophyforMixly.Morecontinuouscontenthasbeen
addedtothedesignofthesoftwaretoprotecttheuser'slearningoutcomes.Tobespecific,itincludestheintroductionof
variabletypes,theconsistencyoftextprogrammingasmuchaspossibleinthedesignofthemodule,andthesupportof

43/252
bothgraphicalandtextprogramming.
(5)Ecological
ThemostimportantdesignconceptofMixlyisitsecologicalfeature,whichcandistinguishitfromotherArduino
graphicalprogramming.Inordertoachievesustainabledevelopment,Mixlyisdesignedtoallowmanufacturersto
developtheirownuniquemodules.ButusersrequireJavaScriptprogrammingfoundationtomakethispartofthe
module).ItalsoallowsusersdirectlyuseMixly'sgraphicalprogrammingfunctiontogeneratecommonmodules(suchas
LEDdigitaldisplay,buzzerbroadcast,etc.UsersareabletomakethispartofthemoduleonlyusingMixly).Bothofthe
twokindsofmodulesmentionedabovecanbeimportedintotheMixlysystemthroughthe"Import"function,thereby
realizingtheuser'sownvalueinthepopularityofMixlysoftware.
UserGroups:
Fromtheabovedesignconcept,itcanbeseenthatMixlyissuitableforprimaryandsecondaryschoolstudentsto
cultivateprogrammingthinking.Itisalsoavailableforquickprogrammingwhencreatingawork.itisgoodforthose
lovelyfriendswhodon'twanttolearntextprogramming,butwanttodosomesmallworkswithintelligentcontrol.

44/252
MixlyBlocksFunctions:
SystemFunctions
LookatthemaininterfaceofMixly,itincludesfiveparts,thatis,Blocksselection,codeedit,textcode(hidden),
systemfunctionandmessagepromptarea.Shownbelow.

45/252
Somecommonfunctions:
Throughthisinterface,youcancompletethecodecompile、upload、saveandmanage.Itsupportfourremove
methods:dragitleftoutcodewindow,ordragtoRecycleBin,deletekey,orright-clicktodeleteblock.Itsupports
fourlanguages:English、Español(Spanish)、䞭文简䜓(ChineseSimplified)、䞭文繁䜓(ChineseTraditional).

46/252
HowtoInstallMixlySoftware
Firstdecompressthemixlyprogrammingsoftwarefile
Afterunzippingyouwillgetthefollowingfiles(Note:DonotincludespecialcharacterssuchasChinese,spaces,
brackets,etc.intheunzippeddirectory.Thenameoftheuncompressedpathcannothaveadoublespacebar.Ifthenamed
nameneedsaseparator,youcanuseanunderscoretoreplacethedoublespacebar,forexample,youshouldnamethefolder
Mixly_SofewaveinsteadofMixlySofewave)

47/252

48/252
Double-clickthemixlyapplicationfiletoopenthesoftware.AndselectthemaincontrolboardasArduino/GenuinoUno

49/252
HowtoAddMixlyLibraries
Themixlylibraryfileisanintegratedgraphicalcodecustomizedforacertaincontrolboard.Forexample,wehavewrittena
mixlylibraryfileforsmarthomelearningkit.Youcandirectlyloaditintomixlysoftwareanduseitdirectly,whichbrings
conveniencetoyourprogrammingprocess.Thegenerallibraryfilecontainsthefollowingfiles,thelast.xmlfileisthe
readablelibraryfileofthemixlysoftware
(Note:Aftercompletingtheinstallationofthemixlysoftware,thelibraryfile<LAFVINSmartRobotCarKit>already
containstheautomaticadditiontotheprogrammingsoftware,youcanuseitdirectlywithoutaddingandaddingrepeatedly.)

50/252
Ifyouneedtoaccidentallydeletethelibraryfile,oryouwanttoaddotherfunctionallibraryfiles,youcanrefertothe
followingstepstoaddlibraryfiles.
Afteropeningthemixlysoftware,select"import"andclicklocalimport.thenselectthepathwherethe"SmartRobot
CarKit"folderislocated,selectthefile--”SmartRobotCarKit.xml”,andclick"open"

51/252

52/252
Thefigurebelowshowsthatthe”Smart_Robot_Tank”libraryfilehasbeensuccessfullyimportedintothemixlysoftware.

53/252
Nextwewriteaprogramonthesoftwareanduploadittosmartrobotcar.
Dragtheprogramblocknamed"Moveforward"totheprogrammingarea,andmodifythePWMvariableto200.

54/252
HowtoUploadtheReferenceProgram
Click"Open"onthemixlysoftwareandselectthereferenceprogram.TakethereferenceprogramfromLesson3asan
example,OpenthissourceprograminMixly_Code>Lesson_3>”Test_1_Motor_Speed_and_Direction_Control.mix”.

55/252

56/252

57/252
ConnecttheArduinoUNOdevelopmentboardtothecomputerwithaUSBdatacable,andturnonthepowerswitch.Select
thedevelopmentboardtypeas"Arduino/GenuinoUno"onthesoftwareandyouwillseeanewconnectionserialport
"COM17"appears.
Tip:TheserialnumberofyourarduinounoonyourPCisother.Everycomputerisdifferent,checkthecorrectserial
numberinthedevicemanagerofyourcomputer.IfnoavailableCOMinterfaceisfound,youneedtoinstallthearduino
driver.HowtoInstallArduinoDriver

58/252

59/252

60/252
ClickUploadandwaitfortheuploadtocomplete.Aftertheprogramuploadiscompleted,smartcargoesforwardandback
for2s,turnsleftandrightfor2s,andstopsfor2salternately.

61/252
Intheprocessofuploadingthecode,ifyoureportanerror,theremaybethefollowingreasons:
(1)TheUSBdatacableinterfaceisnotfirmlyconnected,orthedrivershavenotbeeninstalled(ifnecessary)orthatthe
wrongserialportisselected.HowtoInstallArduinoDriver
(2)Itmeansthatthecommunicationserialportforuploadingcodeisoccupied.IfyouconnecttheBluetoothmodulewhen
uploadingthecode,youneedtodisconnecttheBluetoothmodulefromtheArduinoUNOexpansionboard,andthen
reinstalltheBluetoothmoduleafteruploading.
(3)AnotherpossibilityisthattheUSBinterfaceoftheArduinoUNOisinsufficientlypowered,andyouneedtoturnonthe
externalpowerswitchoftheexpansionboard.

62/252
Theuseofeachstatementblockisdescribedbelow
In/OutBlock:

63/252
NO. BLOCKICON DEFINITION
1 ReturnsHIGHorLOWvoltage
2
WritedigitalvaluetoaspecificPort.Digital
Output:settheHIGHorLOWoutputforIOpins
3
ReturnsadigitalvalueofaspecificPort.Digital
IOReadPin,generallyusedtoreadtheHIGHor
LOWleveldetectedbyDigitalsensor

64/252
4
Writeanalogvaluebetween2and255toa
specificPort.AnalogOutput:settheAnalog
valueoutputbyAnalogIOpins(0~255).
5
Returnsvaluebetween0and1023ofaspecific
Port.AnalogIOReadPin,generallyusedtoread
theAnalogvaluedetectedbyAnalogsensor.
6
ExternalInterruptsfunction,withthreetrigger
interruptmodesRISING,FALLING,CHANGE.
7
DetachsinterrupttoaspecificPort.Turnoffthe
giveninterruptfunction.

65/252
8 SettheIOpinsasOutputorInputstate
9
ReadthecontinuoustimeofHIGHorLOWpulse
fromIOpins(generallyusedforultrasonic
ranging)

66/252
ControlBlock:

67/252
NO
.
BLOCKICON DEFINITION
1 Initialization(runonlyonce)
2
Endtheprogram,meanstheprogramwillstop
runningwhenusethisblock.
3
Delayfunction,clicktoselectmsorus(pausethe
programfortheamountoftime(inmilliseconds)

68/252
specifiedasparameter.Thereare1000millisecondsin
asecond.)
4
if_dofunction(firstevaluateavaluebetrueorfalse,if
avalueistrue,thendosomestatement.Youcanclick
thebluegearicontoselecttheelseifblockorelse
block.)

69/252
5
switchfunction.Youcanclickthebluegeariconto
selectthecaseblockordefaultblock.(usedto
evaluateseveralprogramsthenexecutethe
correspondingfunctionmatchedwithprogram.)
6 Equaltoforstatement.

70/252
7 Awhileloopstatement.
8 breakfunction,usedtoexitfromthecontainingloop.

71/252
9
millis()function,returnsthesystemrunningtimesince
theprogramstarted.(Theunitcanbems
(milliseconds)orÎŒsmicrosecond)).
10
Timerinterruptfunction,thatis,setatriggerinterrupt
fortheamountoftime(inmilliseconds)specifiedas
parameter.

72/252
11 Timerinterruptstartblock
12 Timerinterruptstopblock

73/252
MathBlock:

74/252
NO. BLOCKICON DEFINITION
1 Anumber
2
ClicktoselecttheArithmeticOperators:
(addition);(subtraction);x(Multiplication);÷
(division);%(remainder);^(bitwisexor)
3
Clicktoselectthe&(bitwiseend);l(bitwiseor);<<
(bitshiftleft);>>(bitshiftright)

75/252
4
Clicktoselectthesin;cos;tan;asin;acos;atan;ln;
log10;e^;10^;++(increment);--(decrement)
5
ClicktoselecttheRound;Ceil;Floor;abs;sq;sqrt
Round:Returnstheintegerpartanumberusing
around.Ceil:Returnstheintegerpartanumberusing
ceil.Floor:Returnstheintegerpartanumberusing
floor.abs:Returntheabsolutevalueofanumber.sq:

76/252
Returnthesquareofanumber.sqrt:Returnthe
squarerootofanumber.
6
Ifselectthemax,returnsthelargernumber;
ifselectthemin,returnsthesmallernumber.

77/252
TextBlock:

78/252
NO. BLOCKICON DEFINITION
1 characterstring:aletter,word,orlineoftext.
2 Acharacter
3
Createsapieceoftextbyjoiningtogethertwopieceof
text.(HereHellojoinMixlyequalsHelloMixly)
4 Convertsastringintoanintegeroranfloat.

79/252
5
ReturnsthecharcorrespondingtoanASCIIcode
(Decimalnumber97correspondingtoa)
6 ReturnstheASCIIcodecorrespondingtoachar.
7 Convertsanumberintoastring.
8 Calculatesthelengthofastring
9 Outputthecharofastring(thecharat0ofhelloish)

80/252
10
ThefirststringequalsorstartsWithorendsWiththe
secondstring,returns1,otherwisereturns0.(ifequals,
bothstringsareabc,returns1.)
11
Returnsadecimalvalueofthefirststringsubtractsthe
secondstring.

81/252
ListBlock:

82/252
NO. BLOCKICON DEFINITION
1
Createalistwithanynumberofitems
2
Creatsalistfromatext.(intmylist[]={0,0,0};)
3
Returnsthelengthofalist
4
Returnsthevalueofatthespecifiedpositioninalist.
5
Setsthevalueofatthespecifiedpositioninalist.
Setthefirstiteminmylisttoanotheritem.

83/252
LogicBlock:

84/252
NO
.
BLOCKICON DEFINITION
1
logiccomparision=:Returntrueifbothinputsequaleach
other.≠:Returntrueifbothinputsarenotequaltoeach
other.<:Returntrueifthefirstinputissmallerthanthe
secondinput.≀:Returntrueifthefirstinputissmaller
thanorequaltothesecondinput.>:Returntrueifthe
firstinputisgreaterthanthesecondinput.≥:Returntrue
ifthefirstinputisgreaterthanorequaltothesecond
input.

85/252
2
and:Returntrueifbothinputsaretrue;or:Returntrueif
atleastoneoftheinputsistrue
3
Returnstrueiftheinputisfalse.Returnsfalseiftheinput
istrue.
4 Returnseithertrueorfalse.
5 Returnsnull
6
Ifthefirstnumberistrue,thesecondnumberisreturned,
otherwisethethirdnumber.

86/252
SerialPortBlock:

87/252
NO. BLOCKICON DEFINITION
1 Settheserialbuadrateto9600
2 Writethespecifiednumber,textorothervalue.
3
Printthespecifiednumber,textorothervalue
onmonitor.
4
Printthespecifiednumber,textorothervalue
onnewlineofmonitor.

88/252
5
Printthespecifiednumberinhexademical
formatonnewlineofmonitor.
6
Iftheserialportisavailable,itreturnstrue,
otherwisereturnsfalse.(generallyusedin
Bluetoothcommunication)
7 Returnsastringinserialport
8
Astringreadfromserialporttoastringvariable,
pauseuntilreadthespecifiedcharacter.

89/252
9
Readtheserialdatabybyte(generallyusedto
readthevaluesentfromBluetooth)(deletethe
datahasbeenread)
10 Waitfortheoutputdatacompleted
11
Setthesoftwareserialport(callthisfunctionif
needtouseseveralserialports)
12
Eventfunctiontriggerbyserialportdata,thatis,
serialportisreadytocallthisfunction.(equalto
aninterruptfunction)

90/252
MonitorBlock:

91/252
NO. BLOCKICON DEFINITION
1 SettheIICLCD1602address
2
InputthevalueonLCDline1andline2fromleftto
right.
3 SettherowandcolumnofLCDtoprintthechar
4 CleartheLCDscreen

92/252
VariablesBlock

93/252
NO. BLOCKICON DEFINITION
1 Defineanintegervariable
whosenameisitem
2 Mandatorytypeconversionof
constantsorvariables

94/252
FunctionsBlock:

95/252
NO. BLOCKICON DEFINITION
1
Createsafunctionwithnooutput.Clicktheblueicontosetthe
procedureparameter.(noreturnvalue)
2
Createsafunctionwithanoutput.Clicktheblueicontosetthe
procedureparameter.(withreturnvalueandcansetthedata
types)
3 Ifavalueistrue,thenreturnasecondvalue.

96/252
Smart_Robot_TankBlock:

97/252

98/252
NO. BLOCKICON DEFINITION
1 Controltherobotcartomoveforward,and
thedigitalPWMcanbefilledtocontrolthe
speed.TherangeofthePWMvalueis
0~255.WhenthePWMequals255,thetank
movesatthemaximumspeed,andthe
PWMequals0meansstop.
2 Controltherobotcartomovebackward,
andthedigitalPWMcanbefilledtocontrol
thespeed.TherangeofthePWMvalueis
0~255.WhenthePWMequals255,thetank
movesatthemaximumspeed,andthe
PWMequals0meansstop.

99/252
3 Controltherobotcartorotate
counterclockwise(rotatetotheleft),the
digitalPWMcanbefilledtocontrolthe
speed,therangeofPWMvalueis0~255,
whenthePWMisequalto255,thetank
movesatthemaximumspeed,andthe
PWMequals0meansstop
4 Theleftwheelandtherightwheelmove
forwardatthesametime,andthespeedof
eachwheelcanbesetseparately.Sincethe
forwardspeedofthetwowheelsisdifferent,
theturningcanberealized.
Controlthetanktorotateclockwise(rotate

100/252
5
totheright),thedigitalPWMcanbefilledto
controlthespeed,therangeofPWMvalue
is0~255,whenthePWMisequalto255,the
tankmovesatthemaximumspeed,andthe
PWMequals0meansstop
6 Theleftwheelandtherightwheelmove
backwardatthesametime,andthespeed
ofeachwheelcanbesetseparately.Since
thetwowheelshavedifferentbackward
speeds,turningcanberealized.
7
Controltankstop

101/252
8 Controltherotationangleoftheservo
motor,theanglerangeofrotationis0~180
degrees
9 Thisprogramblockisinitializedanddefines
theIOdatainterfaceconnectedtothe
infraredreceiver
Whenthekeycommandoftheremote
controlisreceivedandthevaluesetbythe
programblockisthesame,theprogram
blockoutputslogicture.
10 Usetheultrasonicmoduletomeasurethe
distance,theprogramblockreturnsthe
measureddistancevalue,theunitiscm

102/252
11
Thefunctionofthisprogramblockisto
receivethedetectionresultoftheinfrared
obstacleavoidancesensorandsavethe
receivedresulttothevariable
left_infrared_avoidance_sensoror
right_infrared_avoidance_sensor
12
Thisprogramblockisusedtoreceivethe
informationsentbytheBluetoothmodule,
andstorethereceivedinformationinthe
variablebluetooth_val

103/252
13
Thisprogramblockobtainstheoutput
resultoftheinfraredline-followingsensor.
Whentheinfraredsensordetectsblack,it
outputsahighlevel"1",andwhennoblack
isdetected,itoutputsalowlevel"0".
14
Thisprogramblockobtainstheoutput
resultofthephotosensitivesensor.The
photosensitivesensorcandetectthelight
intensityintheenvironmentandconvertit
intoarangeof0-1024.0representsthe
maximumlightintensity,and1024
representstheweakestlightintensity.

104/252
Lesson3MotorSpeedandDirectionControl
Overview
Inthislessonwewilllearnhowtocontrolthedirectionandspeedcontroloftherobotcar.
MotorDriver
Theexpansionboardhasintegratedthemotordrivechip.Currentmotordrivedevice,whichhasalargecurrentMOSFET-H
bridgejunctionStructure,dual-channelcircuitoutput,candrive2motorsatthesametime.Itoutputscontinuousdrivepower
upto1AperchannelCurrent,startingpeakcurrentupto2A/3A(continuouspulse/singlepulse(Punch);4motorcontrol
modes:forward/reverse/brake/stopEnd;
Specifications:
Recommendedmotorvoltage(VMOT):7.4–13.5V
•Logicvoltage(VCC):2.7–5.5V
•Outputcurrentmaximum:3Aperchannel
•Outputcurrentcontinuous:1Aperchannel(canbeparalleledtodeliver2Acontinuous)

105/252

106/252
A1A2B1B2ofthemotorArduinoshieldistheinterfaceofthemotor.
ThemotorsconnectedtotheA1interfaceandtheA2interfacehavethesamespeedandthesamedirection.
ThemotorsconnectedtotheB1andB2portshavethesamespeedandthesamedirection.
TheD2digitalI/OportcontrolsthedirectionofthemotoroftheportA,andtheD5digitalI/OportoutputsthePWMsignal
tocontrolthespeedofthemotoroftheportA.
TheD4digitalI/OportcontrolsthedirectionofthemotoroftheinterfaceB,andtheD6digitalI/OportoutputsthePWM
signaltocontrolthespeedofthemotoroftheinterfaceB.

107/252
ThePWMvalueisintherangeof0-255.Thegreaterthevalue,thefasterthemotorsturn.
4WDRobot D2 D5(PWM) D4 D6(PWM)
Forward HIGH 0-255 LOW 0-255
Backward LOW 0-255 HIGH 0-255
Rotatetoleft LOW 0-255 LOW 0-255
Rotatetoright HIGH 0-255 HIGH 0-255
Stop / 0 / 0

108/252
Howtoconnectthecircuit
Let'sprogram
Test1--MotorSpeedandDirectionControl

109/252
Inexperimentaltest1,wewillwritecodetocontroltherobotcartomoveforward,backward,rotatetoleft,rotatetoright,
stop.
MixlyCode
Wireitupwellastheabovediagram.Okay,let’smoveontowritethetestcode.Openmixlysoftware.Click“New”toadd
newproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Motor_Speed_and_Direction_Control.mix"inthereferencefilesweprovided.
ProgrammingThinking

110/252
Thisblockcontrolsthedirectionoftherobotcartoforwardorbackward,255representsthemaximumspeed,andtherange
thatcanbemodifiedis0-255.Whenthespeedissetto0,itmeansstop.
The"RotateLeft"programblockcontrolstherobotcartomakeacircletotheleft.Speed90PWMmeansthatthecar
movesataspeedof90.Theminimumspeed0PWMmeansstop,andthemaximumspeedratiois255PWM.

111/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.Openthereferencecodeforthislesson
"Test_1_Motor_Speed_and_Direction_Control.ino"inthereferencefileweprovided.
ProgrammingThinking
/*MoveForward*/
digitalWrite(2,HIGH);//D2digitalI/OportcontrolsthedirectionofthemotorofinterfaceA
analogWrite(5,50);//D5digitalI/OportoutputsPWMsignaltocontrolthespeedofthemotorofportA.
digitalWrite(4,LOW);//D4digitalI/OportcontrolsthedirectionofthemotorofinterfaceB
analogWrite(6,50);//D6digitalI/OportoutputsPWMsignaltocontrolthespeedofinterfaceBmotor.
delay(2000);//delay2s
Whatwillyousee
Hookupbyconnectiondiagram,uploadcodeandpoweron,smartcargoesforwardandbackfor2s,turnsleftandright
for2s,andstopsfor2salternately.

112/252
Lesson4LineTrackingSmartCar
Overview
Inthislesson,wewillcompletethetestoftwoexperimentalcodes.Inexperimentaltest1,welearnedhowtousethe
infraredline-followingsensor,andobservedtheresultsreturnedbythesensortodistinguishblackandwhiteobjects.Inthe
experimentaltest2,welearnedtocombinetheinfraredline-followingsensorwiththemotortocontroltherobotcarto
completetheline-followingfunction.

113/252
Whatislinetrackingsensor
Thetrackingsensorisactuallyaninfraredsensor.ThecomponentusedhereistheTCRT5000infraredtube.Itsworking
principleistousethedifferentreflectivityofinfraredlighttothecolor,thenconvertthestrengthofthereflectedsignalinto
acurrentsignal.Duringtheprocessofdetection,blackisactiveatHIGHlevel,butwhiteisactiveatLOWlevel.The
detectionheightis0-3cm.
Byrotatingtheadjustablepotentiometeronthesensor,itcanadjustthedetectionsensitivityofthesensor.
Howtousethelinetrackingsensor
OperatingVoltage:3.3-5V(DC)
Interface:G(GND)V+(VCC)S(Signal)
OutputSignal:Digitalsignal
DetectionHeight:0-3cm
Specialnote:beforetesting,turnthepotentiometeronthesensortoadjustthedetectionsensitivity.WhenadjusttheLEDat

114/252
thethresholdbetweenONandOFF,thesensitivityisthebest.

115/252
Howtoconnectthecircuit

116/252
Let'sprogram
Test1--LineTrackingSensor
Themainpurposeofthetestexperimentistoreadthereturnsignalofthelinetrackingsensorandprintittotheserialport
monitor.Whendetectswhitepaper,sensor’ssignalpinoutputsLOW(display0),andstatusLEDison;Whendetectsblack,
sensor’ssignalpinoutputsHIGH(display1),andstatusLEDisoff.
MixlyCode
Wireitupwellastheabovediagram.Okay,let’smoveontowritethetestcode.OpenMixlysoftware.Click“New”toadd
newproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Line_Tracking_Sensor.mix"inthereferencefileweprovidedonCD.

117/252
Afteruploadingtheprogram,opentheserialmonitortoviewthesignalreturnedbytheinfraredobstacle
avoidancesensor.

118/252
Thenyoucanseethedataasblow:
Whendetectswhitepaper,sensor’ssignalpinoutputsLOW(display0),andstatusLEDison;Whendetectsblack,sensor’s
signalpinoutputsHIGH(display1),andstatusLEDisoff.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill

119/252
occupythecommunicationinterfaceoftheuploadedprogram.
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Line_Tracking_Sensor.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance
Thenyoucanseethedataasblow:

120/252
Whendetectswhitepaper,sensor’ssignalpinoutputsLOW(display0),andstatusLEDison;Whendetectsblack,sensor’s
signalpinoutputsHIGH(display1),andstatusLEDisoff.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill
occupythecommunicationinterfaceoftheuploadedprogram.

121/252
Test2--LineTrackingSmartCar
Intheexperimentaltest2,welearnedtocombinetheinfraredline-followingsensorwiththemotortocontroltherobotcar
tocompletetheline-followingfunction.

122/252
MixlyCode
Thinkaboutthecodelogic.OpenMixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.Openthereferencecodeforthislesson
"Test_2_Line_Tracking_Smart_Car.mix"inthereferencefileweprovidedonCD.
ProgrammingThinking
Thelineinspectionpartoftherobotcarincludesthreeinfraredlinetrackingsensors,namelytheleftlinetrackingsensor,the
middlelinetrackingsensor,andtherightlinetrackingsensor.Arollofblackelectricaltapeisincludedinthekitparts.The
widthofthetapeis15mm,youcanuseittoplanthetrajectoryofthecar.Whentherobotcompletestheline-following
function,thefollowingsituationsmayoccur.

123/252

124/252
WhenintheAstate,onlythemiddleline-followingsensordetectstheblackline,andtherobotcarmovesstraightataspeed
of120.
WhenintheBstate,theleftline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotheleftataspeedof80%.
WhenintheDstate,therightline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotherightataspeedof80%.

125/252
WhenintheCstate,theleftline-followingsensordetectstheblackline,andtherobotcarrotatestotheleftataspeedof
120%.

126/252
WhenintheEstate,therightline-followingsensordetectstheblackline,andtherobotcarrotatestotherightataspeedof
120%.
Whenthethreeline-followingsensorsdetecttheblacklineatthesametime,therobotcarstops.

127/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_2_Line_Tracking_Smart_Car.ino"inthereferencematerialsweprovided.
ProgrammingThinking
WhenintheAstate,onlythemiddleline-followingsensordetectstheblackline,andtherobotcarmovesstraightataspeed
of120.
if(Left_Tra_Value!=Black&&(Center_Tra_Value==Black&&Right_Tra_Value!=Black))
{
digitalWrite(2,HIGH);
analogWrite(5,120);
digitalWrite(4,LOW);
analogWrite(6,120);

128/252
}
WhenintheBstate,theleftline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotheleftataspeedof80%.
elseif(Left_Tra_Value==Black&&(Center_Tra_Value==Black&&Right_Tra_Value!=Black))
{
digitalWrite(2,LOW);
analogWrite(5,80);
digitalWrite(4,LOW);
analogWrite(6,80);
}
WhenintheDstate,therightline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotherightataspeedof80%.

129/252
elseif(Left_Tra_Value!=Black&&(Center_Tra_Value==Black&&Right_Tra_Value==Black))
{
digitalWrite(2,HIGH);
analogWrite(5,80);
digitalWrite(4,HIGH);
analogWrite(6,80);
}
WhenintheCstate,theleftline-followingsensordetectstheblackline,andtherobotcarrotatestotheleftataspeedof
120%.
elseif(Left_Tra_Value==Black&&(Center_Tra_Value!=Black&&Right_Tra_Value!=Black))
{
digitalWrite(2,LOW);

130/252
analogWrite(5,120);
digitalWrite(4,LOW);
analogWrite(6,120);
}
WhenintheEstate,therightline-followingsensordetectstheblackline,andtherobotcarrotatestotherightataspeedof
120%.
elseif(Left_Tra_Value!=Black&&(Center_Tra_Value!=Black&&Right_Tra_Value==Black))
{
digitalWrite(2,HIGH);

131/252
analogWrite(5,120);
digitalWrite(4,HIGH);
analogWrite(6,120);
}
Whenthethreeline-followingsensorsdetecttheblacklineatthesametime,therobotcarstops.
elseif(Left_Tra_Value==Black&&(Center_Tra_Value==Black&&Right_Tra_Value==Black))
{
digitalWrite(2,LOW);
analogWrite(5,0);
digitalWrite(4,HIGH);
analogWrite(6,0);
}

132/252
Whatwillyousee
UploadthetestcodetoUNOR3controlboard,turnthePOWER
switchON.Thenthesmartcarwillmovealongtheblackline.
Note:Thefloorsofdifferentmaterialsinthehomehavedifferentdegreesoflightreflection.Youcanadjustthe
potentiometerontheline-followingsensortochangetheresponsesensitivity.Thiscanmakethecarfollowtheblackline
moresmoothly.

133/252
Lesson5UltrasonicInfraredObstacleAvoidanceRobotCar
Overview
Inthislesson,wewillcompletethetestof4experimentalcodes.
Inexperimentaltest1,weseparatelylearnhowtouseinfraredobstacle-avoidancesensorstodetectobstacles,andobserve
theresultsreturnedbythesensorstodeterminewhetherobstaclesaredetected.
Inthesecondexperimentaltest2,wewilllearntousetheultrasonicmoduletomeasuredistance.
Intheexperimentaltest3,wewilllearnhowtocontroltheservomotortorotatetoanyangle.
Intheexperimentaltest4,theinfraredobstacleavoidancesensor,theultrasonicmoduleandtheservomotorwere
assembledontherobotcaratthesametime,andthedataofthesesensorswereusedatthesametimetoassisttherobotcar
tocompletetheobstacleavoidancefunctionmoreaccurately.

134/252

135/252
Whatisinfraredobstacleavoidancesensor
Theinfraredobstacledetectorsensorhasapairofinfraredtransmittingandreceivingtubes.Thetransmitteremitsan
infraredraysofacertainfrequency.Whenthedetectiondirectionencountersanobstacle(reflectingsurface),theinfrared
raysarereflectedback,andreceivingtubewillreceiveit.Atthistime,theindicator(greenLED)lightsup.Afterprocessed
bythecircuit,thesignaloutputterminalwilloutputDigitalsignal.Youcanrotatethepotentiometerontheshieldtoadjust
thedetectiondistance.ItisbettertoadjustthepotentiometertomakethegreenLEDinastatebetweenonandoff.The
detectiondistanceisthebest,almost10cm.
Howtousetheinfraredobstacleavoidancesensor
wereadthesignallevelofobstacledetectorsensortojudgewhetherdetectobstaclesornot.
Whendetectsanobstacle,sensor’ssignalpinoutputsLOW(display0);otherwise,outputHIGH(display1).
Showtheresultontheserialmonitor,andcontroltheexternalLEDmoduleturnON/OFF.

136/252

137/252
Whatisanultrasonicsensor
Reviewtheultrasonicsensorfromthepreviouslesson.Itworkslikeabat'seye.Determinethedistanceofobstaclesinfront
afterreceivingandreceivinghigh-frequencysoundwaves.
Asthefollowingpictureshown,itisourultrasonicmodule.Ithastwosomethinglikeeyes.
Oneistransmittingend,theotherisreceivingend.

138/252
TheHC-SR04ultrasonicsensorusessonartodeterminedistancetoanobjectlikewhatbatsdo.Itoffersexcellent
non-contactrangedetectionwithhighaccuracyandstablereadingsinaneasy-to-usepackage.Itcomescompletewith
ultrasonictransmitterandreceivermodules.TheHC-SR04ortheultrasonicsensorisbeingusedinawiderangeof
electronicsprojectsforcreatingobstacledetectionanddistancemeasuringapplicationaswellasvariousotherapplications.
Herewehavebroughtthesimplemethodtomeasurethedistancewitharduinoandultrasonicsensor
andhowtouseultrasonicsensorwitharduino.

139/252
Specification
PowerSupply:+5VDC
QuiescentCurrent:<2mA
WorkingCurrent:15mA
EffectualAngle:<15°92
RangingDistance:2cm–400cm
Resolution:0.3cm
MeasuringAngle:30degree
TriggerInputPulsewidth:10uS

140/252
Whatisaservomotor
Description
Servomotorisapositioncontrolrotaryactuator.Itmainlyconsistsofahousing,circuitboard,
core-lessmotor,gearandpositionsensor.Itsworkingprincipleisthattheservoreceivesthe
signalsentbyMCUsorreceiversandproducesareferencesignalwithaperiodof20msand
widthof1.5ms,thencomparestheacquiredDCbiasvoltagetothevoltageofthe
potentiometerandobtainthevoltagedifferenceoutput.Whenthemotorspeedisconstant,the
potentiometerisdriventorotatethroughthecascadereductiongear,whichleadsthatthevoltagedifferenceis0,andthe
motorstopsrotating.Generally,theanglerangeofservorotationis0°--180°.

141/252
TherotationangleofservomotoriscontrolledbyregulatingthedutycycleofPWM(Pulse-WidthModulation)signal.The
standardcycleofPWMsignalis20ms(50Hz).Theoretically,thewidthisdistributedbetween1ms-2ms,butinfact,it's
between0.5ms-2.5ms.Thewidthcorrespondstherotationanglefrom0°to180°.Butnotethatformotorsofdifferent
brands,thesamesignalmayhavedifferentrotationangle.

142/252
Ingeneral,servohasthreelinesinbrown,redandorange.Thebrownwireisgrounded,theredoneisapositivepoleline
andtheorangeoneisasignalline.Thecorrespondingservoanglesareshownbelow:
Specification
PowerSupply:+5VDC
QuiescentCurrent:<2mA
WorkingCurrent:15mA
EffectualAngle:<15°92
RangingDistance:2cm–400cm
Resolution:0.3cm
MeasuringAngle:30degree
TriggerInputPulsewidth:10uS

143/252
Howtoconnectthecircuit

144/252
Let'sprogram
Test1--infraredobstacleavoidancesensor
Themainpurposeofthetestexperimentistoreadthereturnsignaloftheinfraredobstacleavoidancesensorandprintitto
theserialportmonitor.Whendetectsanobstacle,sensor’ssignalpinoutputsLOW(display0);otherwise,outputHIGH
(display1).
MixlyCode
Wireitupwellastheabovediagram.Okay,let’smoveontowritethetestcode.OpenMixlysoftware.Click“New”toadd
newproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Infrared_Obstacle_Avoidance_Sensor.mix"inthereferencematerialsweprovided.

145/252
Afteruploadingtheprogram,opentheserialmonitortoviewthesignalreturnedbytheinfraredobstacle
avoidancesensor.

146/252
Thenyoucanseethedataasblow:
Whenthereisanobstacleinthefront,IR_value=0,andtheindicatorlightonthesensorlightsup.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill
occupythecommunicationinterfaceoftheuploadedprogram.

147/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Infrared_Obstacle_Avoidance_Sensor.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance

148/252
Thenyoucanseethedataasblow:
Whenthereisanobstacleinthefront,IR_value=0,andtheindicatorlightonthesensorlightsup.
Note:Beforeuploadingthecode,youneedtoturnofftheserialmonitoroftheArduinoIDEandthemonitoroftheMixly
software,otherwisethecodeuploadwillfailbecausetheserialportisusuallyoccupied.

149/252
Test2--ServoControl
Inthisexperimentaltest,welearnhowtocontroltheservomotorandcontroltheservomotortorotateto
thespecifiedangle.
MixlyCode
Wireitupwellastheabovediagram.Okay,let’smoveontowritethetestcode.Openmixlysoftware.Click“New”toadd
newproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson"Test_2_Servo_Control.mix"inthe
referencefilesweprovidedCD.
ProgrammingThinking

150/252
Thiscodeblockisusedtocontrolthemotorrotationangle,therangeis0-180.Thisprogramblockcanonlycontroltheservo
motorconnectedtotheD10digitalIOinterface
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openArduinoIDEsoftwareandopenthereferencecodeforthislesson
"Test_2_Servo_Control.ino"inthereferencefilesweprovidedonCD.
Beforeyoucanrunthis,makesurethatyouhaveinstalledthe<Servo>libraryorre-installit,ifnecessary.Otherwise,
yourcodewon'twork.Fordetailsaboutloadingthelibraryfile,seeLessonabouthowtoaddlibraries.
CodeExplanation
Arduinocomeswith#include<Servo.h>(servofunctionandstatement
Thefollowingaresomecommonstatementsoftheservofunction:

151/252
1.attachinterface——Setservointerface,port9and10areavailable
2.writeangle——Thestatementtosetrotationangleofservo,theangle
rangeisfrom0°to180°
3.read——usedtoreadangleofservo,readthecommandvalueof
“write()”
4.attached——Judgeiftheparameterofservoissenttoitsinterface
Note:Theabovewrittenformatis“servovariablename,specificstatement
”,forinstance:myservo.attach(10)
Afteruploadingthecode,Theservomotorrotatesto15°andwaitsfor2secondsandthenrotatesto165°,andafter2
seconds,itrotatesto90°,andrepeatstheaboveprocess.

152/252
Test3--UltrasonicSensorModule
InExperimentalTest3,wewilllearnhowtocontroltheultrasonicsensor,anddisplaythedistancemeasured
bytheultrasonicsensorontheserialmonitor.
MixlyCode
Wireitupwellastheabovediagram.Okay,let’smoveontowritethetestcode.Openmixlysoftware.Click“New”toadd
newproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_3_Ultrasonic_Sensor_Module.mix"inthereferencefilesweprovidedCD.

153/252
Afteruploadingtheprogram,opentheserialmonitortoviewthedistancemeasuredbytheultrasonicsensor.

154/252
Thenyoucanseethedataasblow:
Note:thatyouneedtocloseboththeArduinoIDEserialmonitorandtheserialmonitoroftheMixlysoftwarebefore
uploadingthecode,otherwisethecodewillfailtouploadbecausethecommunicationserialportisoccupied.

155/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openArduinoIDEsoftwareandopenthereferencecodeforthislesson
"Test_3_Ultrasonic_Sensor_Module.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance

156/252
Thenyoucanseethedataasblow:
Note:Beforeuploadingthecode,youneedtoturnofftheserialmonitoroftheArduinoIDEandthe
monitoroftheMixlysoftware,otherwisethecodeuploadwillfailbecausetheserialportisusually
occupied.

157/252
Test4--Ultrasonic_Infrared_Obstacle_Avoidance_Robot_Car
Intheexperimentaltest4,theinfraredobstacleavoidancesensor,theultrasonicmoduleandtheservomotorwere
assembledontherobotcaratthesametime,andthedataofthesesensorswereusedatthesametimetoassisttherobotcar
tocompletetheobstacleavoidancefunctionmoreaccurately.
MixlyCode
Thinkaboutthecodelogic.Openmixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_4_Ultrasonic_Infrared_Obstacle_Avoidance_Robot_Car.mix"inthereferencefilesweprovidedCD.
ProgrammingThinking
Thefollowingistheprogramexecutionflowchartoftherobotcartocompletetheobstacleavoidancefunction

158/252

159/252

160/252

161/252

162/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_4_Ultrasonic_Infrared_Obstacle_Avoidance_Robot_Car.ino"inthereferencematerialsweprovided.
ProgrammingThinking
Thefollowingistheprogramexecutionflowchartoftherobotcartocompletetheobstacleavoidancefunction

163/252

164/252

165/252

166/252

167/252

168/252
Whatwillyousee
UploadthecodetoUNOR3controlboard,,andturnthePOWERswitchON.Note:Itisrecommendedthattheheightofthe
obstacleisgreaterthan15cm.whichmeansthattheheightoftheobstacleisgreaterthantheheightoftheultrasonicsensor.
Becauseofreceivingthedetectionsignalsofultrasonicandinfraredobstacleavoidancemodulesatthesametime,therobot
carcancompletetheobstacleavoidancefunctionmoreaccurately.Whenobstaclesareontheleftandrightsidesoftherobot
car,theycanbediscoveredbytheinfraredobstacleavoidancemoduleintimeandturntoavoid.Whentheobstacleis
directlyinfront,theultrasonicwillbeabletomeasurethedistancebetweentherobotcarandtheobstacle.

169/252
Lesson6UltrasonicFollowRobotCar
Overview
Inthelastcourse,Ilearnedhowtousetheultrasonicmoduleandinfraredobstacleavoidancemodule.Similarly,combining
thesetwomodulescancontroltherobotcartocompletethefollowingfunction.
Whentheguidingobjectisontheleftandrightsidesoftherobotcar,theinfraredobstacleavoidancemodulecandetectand
judgethedirectionoftheguidingobject,andcontroltherobotcartoturntotheguideobject.
Whentheguidedobjectisdirectlyinfrontoftherobotcar,theultrasonicsensorcandetectthedistancebetweentherobot
carandtheguideobject.Whenthedistanceisgreaterthan10mm,controltherobotcartoapproachtheguide;
Whenthedistanceislessthan5mm,controltherobotcartomovebackwardandkeepaproperdistance,5mm<D<10mm.

170/252
Whatisinfraredobstacleavoidancesensor
Theinfraredobstacledetectorsensorhasapairofinfraredtransmittingandreceivingtubes.Thetransmitteremitsan
infraredraysofacertainfrequency.Whenthedetectiondirectionencountersanobstacle(reflectingsurface),theinfrared
raysarereflectedback,andreceivingtubewillreceiveit.Atthistime,theindicator(greenLED)lightsup.Afterprocessed
bythecircuit,thesignaloutputterminalwilloutputDigitalsignal.Youcanrotatethepotentiometerontheshieldtoadjust
thedetectiondistance.ItisbettertoadjustthepotentiometertomakethegreenLEDinastatebetweenonandoff.The
detectiondistanceisthebest,almost10cm.
Howtousetheinfraredobstacleavoidancesensor
wereadthesignallevelofobstacledetectorsensortojudgewhetherdetectobstaclesornot.
Whendetectsanobstacle,sensor’ssignalpinoutputsLOW(display0);otherwise,outputHIGH(display1).
Showtheresultontheserialmonitor,andcontroltheexternalLEDmoduleturnON/OFF.

171/252

172/252
Whatisanultrasonicsensor
Reviewtheultrasonicsensorfromthepreviouslesson.Itworkslikeabat'seye.Determinethedistanceofobstaclesinfront
afterreceivingandreceivinghigh-frequencysoundwaves.
Asthefollowingpictureshown,itisourultrasonicmodule.Ithastwosomethinglikeeyes.
Oneistransmittingend,theotherisreceivingend.

173/252
TheHC-SR04ultrasonicsensorusessonartodeterminedistancetoanobjectlikewhatbatsdo.Itoffersexcellent
non-contactrangedetectionwithhighaccuracyandstablereadingsinaneasy-to-usepackage.Itcomescompletewith
ultrasonictransmitterandreceivermodules.TheHC-SR04ortheultrasonicsensorisbeingusedinawiderangeof
electronicsprojectsforcreatingobstacledetectionanddistancemeasuringapplicationaswellasvariousotherapplications.
Herewehavebroughtthesimplemethodtomeasurethedistancewitharduinoandultrasonicsensor
andhowtouseultrasonicsensorwitharduino.

174/252
Howtoconnectthecircuit

175/252
Let'sprogram
Test1--UltrasonicFollowRobotCar
Whentheguidingobjectisontheleftandrightsidesoftherobotcar,theinfraredobstacleavoidancemodulecandetectand
judgethedirectionoftheguidingobject,andcontroltherobotcartoturntotheguideobject.
Whentheguidedobjectisdirectlyinfrontoftherobotcar,theultrasonicsensorcandetectthedistancebetweentherobot
carandtheguideobject.Whenthedistanceisgreaterthan10mm,controltherobotcartoapproachtheguide;
Whenthedistanceislessthan5mm,controltherobotcartomovebackwardandkeepaproperdistance,5mm<d<10mm.
MixlyCode
Thinkaboutthecodelogic.Openmixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Ultrasonic_Follow_Robot_Car.mix"inthereferencematerialsweprovided.

176/252
ProgrammingThinking
Thefollowingistheprogramexecutionflowchartoftherobotcartocompletetheultrasonicfollowfunction

177/252

178/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Ultrasonic_Follow_Robot_Car.ino"inthereferencematerialsweprovided.
Whatwillyousee
UploadthecodetoUNOR3controlboard,,andturnthePOWERswitchON.Note:Itisrecommendedtousearectangular
objectboxtoguidetherobotcar.Length>10cm.Width>15cm.
Therobotcardetectsthedistanceoftheobjectinfrontthroughtheultrasonicsensor.Whenthefrontobjectmoves,therobot
carwillfollowthemovement,keepingthedistancebetweenthetankandtheobjectinfrontbetween5cm~8cm.

179/252
Lesson7InfraredRemoteControlRobotCar
Overview
Inthislesson,wewilllearntheinfraredremotecontrol,andusetheinfraredremotecontroltocontroltherobotcargo
forward,backward,turnleft,turnright,rotateleftrotateright.Note:Duetoairtransportation,theremotecontroldoesnot
containbatteries,youneedtoprepareabuttonbatteryCR2025beforeuse.

180/252
Whatisaninfraredremotecontrol
Thereisnodoubtthatinfraredremotecontroliscommonlyseeninourdailylife.It'shardtoimagineourworldwithout
it.Aninfraredremotecontrolcanbeusedtocontrolawiderangeofhomeappliancessuchastelevision,audio,video
recordersandsatellitesignalreceivers.Well,inthefollowinglet’sgetabetterunderstandingoftheinfraredremote
control.Infraredremotecontroliscomposedofinfraredtransmittingandinfraredreceivingsystems.Thatis,consistofan
infraredremotecontrol,aninfraredreceivermoduleandamicrocontrollerthatcandecode.Youcanrefertothefigurebelow.
Remotecontrolkeyvalue

181/252
The38Kinfraredcarriersignaltransmittedbyaninfraredremotecontrollerisencodedbyanencodingchipinsidethe
remotecontroller.Itiscomposedofapilotcode,usercode,datacode,anddatainversioncode.Thetimeintervalbetween
pulsesisusedtodistinguishwhetheritisasignal0or1.(whentheratioofhighleveltolowlevelisabout1:1,considered
assignal0.)
Andtheencodingisjustwellcomposedofsignal0and1.Theusercodeofthesamebuttononremotecontrolleris
unchanged.Usingdifferencedatadistinguishthekeypressedontheremotecontrol.Whenpressdownabuttononthe
remotecontrol,itwillsendoutaninfraredcarriersignal.Andwheninfraredreceiverreceivesthatsignal,itsprogramwill
decodethecarriersignal,andthroughdifferentdatacodes,thuscanjudgewhichkeyispressed.Themicrocontrolleris
decodedbyanreceivedsignal0or1todeterminewhichkeyispressedbytheremotecontrol.

182/252
Whatisaninfraredreceiver
Therobotshieldcomeswithinfraredreceivermodule.Itismainlycomposedofaninfraredreceivinghead.Thisdevice
integrateswithreception,amplificationanddemodulation.ItsinterIChasbeendemodulated,outputtingDigitalsignal.
SuitableforIRremotecontrolandinfrareddatatransmission.Thedatainterfaceoftheinfraredreceiverisconnectedtothe
D3digitalIOport.

183/252
Let'sprogram
Test1--InfraredRemoteControlRobotCar
Inexperimentaltest1,learntoreceiveinfraredremotecontrolsignals,anddistinguishthecorresponding
remotecontrolkeyvalue,andfinallyrealizeinfraredremotecontrolrobotcar.
MixlyCode
Thinkaboutthecodelogic.Well,figureoutthelogic,youcanhaveatrytowriteoutthecodelogicofinfraredobstacle
avoidance.Openmixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Infrared_Remote_Control_Robot_Car.mix"inthereferencematerialsweprovided.

184/252
ProgrammingThinking
Thisprogramblockistoinitializetheinfraredreceiver,andtheportnumberisfilledwith"3".
ThedatainterfaceoftheinfraredreceiverisconnectedtotheD3digitalIOport.
Selectthebuttonyouneedtoset.Whenthespecifiedbuttonispressed,theblockoutputstruelogic.

185/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Infrared_Remote_Control_Robot_Car.ino"inthereferencematerialsweprovided.
Whatwillyousee
UploadthecodetoUNOR3controlboard,andturnthePOWERswitchON.Usetheinfraredremotecontroltocontrolthe
tank'sdirectionofadvance.Note:Duetoairtransportation,theremotecontroldoesnotcontainbatteries,youneedto
prepareabuttonbatteryCR2025beforeuse.
KeyonIR
remotecontrol
RobotstatusGoforwardGobackwardTurnleftTurnrightRotatetoleftRotatetoright Stop

186/252
Lesson8LightSeekingRobotCar
Overview
Inthislesson,wemainlystudytwoexperimentaltests.Inthefirsttestexperiment,welearnthephotoelectricsensoranduse
ittoobtainthelightintensityintheenvironment;inthesecondtestexperiment,thephotoelectricsensorandmotorcontrol
needtobecombined,sothatwhenthecarsensesstronglight,Willmoveinthedirectionofthelight.

187/252
Whatisphotoelectricsensor
Thephotoelectricsensor(photoresistor)isaresistorsemiconductormadebythephotoelectriceffect.Itisverysensitiveto
ambientlight,soitsresistancevaluechangeswithdifferentlightintensities.Weuseitsfunctionstodesigncircuitsand
generatephotoresistorsensormodules.Thesignalendofthemoduleisconnectedtothemicrocontroller.Whenthelight
intensityincreases,theresistancedecreases,andthevoltageofthesignaloutputportofthemoduledecreases,thatis,the
voltagedetectedbytheanalogportofthemicrocontrollerwilldecrease.Otherwise,whenthelightintensitydecreases,the
resistanceincreases,andthevoltageofthesignaloutputportofthemoduleincreases,thatis,thevoltagedetectedbythe
analogportofthemicrocontrollerwillincrease.Therefore,wecanusethephotoresistorsensormoduletoreadthe
correspondinganalogvalueandsensethelightintensityintheenvironment.Itisusuallyusedinlightmeasurement,control
andconversion,andlightcontrolcircuits.

188/252
Howtoconnectthecircuit

189/252
Let'sprogram
Test1--LightSeekingSignal
Onthemodule,Whenthephotoresistorisilluminatedbystronglight,Itsresistancevaluedropsrapidly,
thecurrentpassedincreases,theresistanceofthephotoresistorrisesrapidlyinadarkenvironment,the
currentpassedthroughisreduced,Themaincontrolboarddetermineswhetherthereisalightsource.
MixlyCode
Thinkaboutthecodelogic.Well,figureoutthelogic,youcanhaveatrytowriteoutthecodelogicofinfraredobstacle
avoidance.Openmixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson"Test_1_Light_Seeking_Signal.mix"
inthereferencefilesweprovidedonCD.
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson"Test_1_Light_Seeking_Signal.ino"
inthereferencefilesweprovidedonCD.

190/252
Afteruploadingtheprogram,Useacovertoblockthelightnearthephotoresistor,andthenobservethatthe
outputvalueofthelight-seekingsignalontheserialmonitorisrelativelylarge,andthenremovethe
obstruction.Itisfoundthattheoutputvalueofthelight-seekingsignalontheserialmonitorbecomes
smaller.Youcanalsousetheflashlightofthemobilephonetoilluminatethephotoresistortoobservethe
changeoftheoutputvalueofthelight-seekingsignalontheserialmonitor.

191/252
Test2--LightSeekingRobotCar
thephotoelectricsensorandthemotorcontrolneedtobecombined,sothatwhenthecarsensesstronglight,
itwillmoveinthedirectionofthelight.
MixlyCode
Thinkaboutthecodelogic.Well,figureoutthelogic,youcanhaveatrytowriteoutthecodelogicofinfraredobstacle
avoidance.Openmixlysoftware.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_2_Light_Seeking_Robot_Car.mix"inthereferencefilesweprovidedonCD.

192/252
ProgrammingThinking
ThespecificsoftwaredesignideaisasshowninFigure

193/252

194/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_2_Light_Seeking_Robot_Car.ino"inthereferencefilesweprovidedonCD.

195/252
Whatwillyousee
UploadthecodetoUNOR3controlboard,andturnthePOWERswitchON.Testinadarkenvironmentandturnoffthe
lightsintheroom.Thelightoftheflashlightfacesthephotoelectricsensorontheright,andtherobotcarturnsright.The
lightoftheflashlightfacesthephotoelectricsensorontheleft,andtherobotcarturnsleft.

196/252
Lesson9BluetoothControlRobotCar
Overview
Inthislesson,wemainlystudytwoexperimentaltests.
InTest1,welearnthecommunicationbetweentheBluetoothmoduleandthemobilephone.
InTest2,usetheappremotecontroltocontrolthedirectionoftherobotcar.

197/252

198/252
WhatisBLE
ThemeaningofBLEislowenergyBluetooth,whichhaslowworkingpowerconsumptionandlongstandbytime.However,
BLE4.0isanewbranchandisnotbackwardcompatible.
SupportedAndroiddevices:AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhighersystem.
YouneedtocompletethesearchandconnectionofBLEdevicesthroughtheApp.
BLEJDY-16
TheJDY-16transparenttransmissionmoduleisbasedontheBluetooth-compatible4.2protocolstandard,theworking
frequencybandis2.4GHZrange,themodulationmethodisGFSK,themaximumtransmissionpoweris0db,themaximum
transmissiondistanceis60meters,anditadoptsimportedoriginalchipdesignandsupportsuserstomodifythedevice
throughATcommandsName,serviceUUID,transmitpower,pairingpasswordandotherinstructionsareconvenientand
flexibletouse.TheJDY-16Bluetooth-compatiblemodulecanrealizethedatatransmissionbetweenthemoduleandthe
mobilephoneorbetweenthemoduleandthemodule.ThecommunicationmodeofUARTorIICcanbeselectedthrough
IO,andtheBluetooth-compatiblecanbequicklyusedforproductapplicationthroughsimpleconfiguration.MakeBLE's

199/252
applicationinproductsfasterandmoreconvenient.
ProductParameters:
Model:JDY-16
Workingfrequency:2.4G
Transmittingpower:0db(maximum)
Communicationinterface:UARTorIIC
Workingvoltage:1.8V-3.6V

200/252
Workingtemperature:-40℃-80℃
Antenna:Built-inPCBantenna
Receivingsensitivity:-97dbm
Transmissiondistance:60meters
Modulesize:19.6mm*14.94*2.6
Bluetooth-compatibleversion:BLE4.2(compatiblewithBLE4.0,BLE4.1)
Transparenttransmissionrate:115200bps/s
Wake-upstatecurrent:4mA(withbroadcast)
Lightsleepstatecurrent:<300uA(withbroadcast)
Deepsleepcurrent:1.8uA(nobroadcast)
Commandparametersaving:parameterconfigurationdataissavedafterpower-off
STMweldingtemperature:<300℃

201/252
Howtoconnectthecircuit

202/252

203/252
HowtoconnectAPPwithbluetoothmodule
Firstly,copythe“LAFVIN_4WD_Smart_Robot_Car_BLE_V2_2.apk”filefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.

204/252
Opentheapp,youwillseethefollowinginterface,swipeleftandrighttoswitchpages.

205/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.

206/252
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist

207/252
toautomaticallyconnect.

208/252
Report:Successfulconnected.Thismeansthatthecorrectdevicehasbeenconnected
Report:DeviceError.ThismeansthattheconnectedBluetoothdevicedoesnotbelongtotherobotcar,searchforJDY-16
andreconnect.
IfAppdoesnotfindthe"JDY-16"device,restarttheBluetoothmodule(unplugtheBluetoothmodulefromtheArduino
UNOMotorDriverShied,disconnectthepoweroftheBluetoothmodule;thenreinstallittotheArduinoUNOMotor
DriverShied,connecttothepowersupply).theredLEDflashes,whichmeansitisinaconnectablestate.Thensearchfor

209/252
BluetoothdevicesagainintheAPP.
Let'sprogram
Test1--BluetoothModuleReceivesInformation
InExperimentalTest1,welearnedhowtoreceivetheinformationsentbythemobilephoneapptothe
Bluetoothmodule.
MixlyCode
Thinkaboutthecodelogic.Click“New”toaddnewproject,thenstartyourprogramming.
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Bluetooth_Module_Receives_Information.mix"inthereferencematerialsweprovided.

210/252
ProgrammingThinking
Setthebaudrateforserialcommunicationto9600.ThecommunicationspeedbetweentheserialportoftheArduinoUNO
maincontrolboardandtheserialportofBluetoothneedstobethesame.ThecommunicationbaudrateoftheBluetooth
moduleis9600bydefault.

211/252
Iftheserialporthasreceivednewinformation,itwillnotstopuntilthenewdataisreceived.
Combinetheendingcharactersintoastring.Needtodelaywaitingforthereceptiontocomplete.
Ifanewcharacterstringisreceived,printthereceivedcharacterstringtotheserialmonitor,andclearthelastdatawithout

212/252
preparingforthenextreception.
Aftercompletingtheprogramupload,opentheserialmonitortoviewtheinformationreceivedbytheBluetoothmodule.

213/252
AftertheBluetoothmoduleofthemobilephoneandtheBluetoothmoduleoftherobotcararesuccessfullyconnected
Whenyoupresstheupbutton,thecharacterreceivedbyBluetoothis“%G#”,
Whenyoupressthedownbutton,thecharacterreceivedbyBluetoothis“%T#”.
Similarly,youcanusethismethodtotestthecommandsofotherbuttonsintheAPP.

214/252
Setthebaudrateforserialcommunicationto9600.ThecommunicationspeedbetweentheserialportoftheArduinoUNO
maincontrolboardandtheserialportofBluetoothneedstobethesame.ThecommunicationbaudrateoftheBluetooth
moduleis9600bydefault.

215/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Bluetooth_Module_Receives_Information.ino"inthereferencematerialsweprovided.
ProgrammingThinking
StringBLE_value;
voidsetup(){
Serial.begin(9600);
BLE_value="";
}
Setthebaudrateforserialcommunicationto9600.ThecommunicationspeedbetweentheserialportoftheArduinoUNO
maincontrolboardandtheserialportofBluetoothneedstobethesame.ThecommunicationbaudrateoftheBluetooth
moduleis9600bydefault.

216/252
voidloop(){
//Iftheserialporthasreceivednewinformation,itwillnotstopuntilthenewdataisreceived.
while(Serial.available()>0){
//Combinetheendingcharactersintoastring
BLE_value=BLE_value+((char)(Serial.read()));
//Needtodelaywaitingforthereceptiontocomplete
delay(2);
}
Iftheserialporthasreceivednewinformation,itwillnotstopuntilthenewdataisreceived.Combinethe
endingcharactersintoastring.Needtodelaywaitingforthereceptiontocomplete.
if(0<String(BLE_value).length()){//Ifanewcharacterstringisreceived
//Printthereceivedstringtotheserialmonitor
Serial.println(BLE_value);

217/252
BLE_value="";//clearthelastdatawithoutpreparingforthenextreception.
}
}
Ifanewcharacterstringisreceived,printthereceivedcharacterstringtotheserialmonitor,andclearthelastdatawithout
preparingforthenextreception.

218/252
Aftercompletingtheprogramupload,opentheserialmonitortoviewtheinformationreceivedbytheBluetoothmodule.

219/252
AftertheBluetoothmoduleofthemobilephoneandtheBluetoothmoduleoftherobotcararesuccessfullyconnected
Whenyoupresstheupbutton,thecharacterreceivedbyBluetoothis“%A#”,
Whenyoupressthedownbutton,thecharacterreceivedbyBluetoothis“%I#”.
Similarly,youcanusethismethodtotestthecommandsofotherbuttonsintheAPP.

220/252
Note:thatyouneedtocloseboththeArduinoIDEserialmonitorandtheserialmonitoroftheMixlysoftwarebefore
uploadingthecode,otherwisethecodewillfailtouploadbecausethecommunicationserialportisoccupied.

221/252
Test2BluetoothControlRobotCar
Step1:Circuitwiring
Connectthewiringaccordingtothewiringdiagram,payingattentiontothepositiveandnegativepolesofthepowersupply.
Correctlydistinguishtheinstallationpositionofthesensormodule,suchasleft,center,rightlinetrackingmodule.A1:Left
frontmotorB1:Rightfrontmotor.

222/252

223/252
Step2:Uploadcode
MixlyCode
IfyouusethegraphicalprogrammingsoftwareMixlyasthedevelopmentenvironment.Openthissourceprogramin
Mixly_Code>Lesson_9>"Test_2_Bluetooth_Control_Robot_Car.mix".SelectthecorrectserialporttouploadtheMixly
code.
HowtoInstallMixlySoftware HowtoAddMixlyLibraries HowtoUploadtheReferenceProgram
ArduinoCode
IfyouusetheArduinoIDEasthedevelopmentenvironment.Openthissourceprogramin
Arduino_Code>Lesson_9>"Test_2_Bluetooth_Control_Robot_Car.ino".Selectthecorrectserialporttouploadthecode
underthe"Tools"menu.Ifyouaremissingsomesteps,ArduinoIDEmayreportsomeerrors.Youcanrefertothefollowing
solutions.
HowtoUnloadArduinoCode.

224/252
Step3:Installtheapp
Firstly,copythe“LAFVIN_4WD_Smart_Robot_Car_BLE_V2_2.apk”filefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.

225/252
OpentheAPP,youwillseethefollowingcontrolinterface.

226/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.

227/252
Step4:Bluetoothconnection
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.

228/252
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist
toautomaticallyconnect.

229/252
Report:Successfulconnected.Thismeansthatthecorrectdevicehasbeenconnected
Report:DeviceError.ThismeansthattheconnectedBluetoothdevicedoesnotbelongtotherobotcar,searchforJDY-16
andreconnect.
IfAppdoesnotfindthe"JDY-16"device,restarttheBluetoothmodule(unplugtheBluetoothmodulefromtheArduino
UNOMotorDriverShied,disconnectthepoweroftheBluetoothmodule;thenreinstallittotheArduinoUNOMotor
DriverShied,connecttothepowersupply).theredLEDflashes,whichmeansitisinaconnectablestate.Thensearchfor
BluetoothdevicesagainintheAPP.

230/252
Step5:Appcontrolinterface

231/252
ThemainfunctionoftheRemoteControlinterfaceistocontrolthedirectionandspeedoftherobotcar.Whenthebattery
voltageislowerthan7.4V,replaceitintime.

232/252
6in1Multi-purposeBluetoothRobotCar
Allfunctionsarecollectedintothesameprogram,includingLineTracking,UltrasonicInfraredAvoidObstacles,Infrared
Remote,LightSeeking,FollowMe,RemoteControl,GravitySensorRemoteControl,andanyfunctioncanbefreely
switchedthroughtheapp.

233/252
Step1:AssembletheRobotCar
Refertotheassemblyvideotocompletetheinstallationoftherobotcar.Tip:Thelengthofthescrewismarkedinthevideo,
youshouldusethesamelength.Beforeinstallation,youneedtoidentifyM3*6mmM3*8mmM3*10mmM3*12mm.Ifyou
usethewrongscrewlengthinthefirsthalf,therewillbemissingscrewsinthelowerpartoftheinstallation.

234/252
Step2:CircuitWiring
Connectthewiringaccordingtothewiringdiagram,payingattentiontothepositiveandnegativepolesofthepowersupply.
Correctlydistinguishtheinstallationpositionofthesensormodule,suchasleft,center,rightlinetrackingmodule.A1:Left
frontmotorB1:Rightfrontmotor.Ifyouconnectsomepartsbymistake,itwillaffectthenormalexecutionoftherobotcar.

235/252

236/252
Step3:UploadCode
MixlyCode
IfyouusethegraphicalprogrammingsoftwareMixlyasthedevelopmentenvironment.Openthissourceprogramin
Mixly_Code>"6_in_1_Multi_purpose_Bluetooth_Robot_Car_V2_2.mix".Selectthecorrectserialporttouploadthe
Mixlycode.
HowtoInstallMixlySoftware HowtoAddMixlyLibraries HowtoUploadtheReferenceProgram
ArduinoCode
IfyouusetheArduinoIDEasthedevelopmentenvironment.Openthissourceprogramin
Arduino_Code>"6_in_1_Multi_purpose_Bluetooth_Robot_Car_V2_2.ino".Selectthecorrectserialporttouploadthe
codeunderthe"Tools"menu.Ifyouaremissingsomesteps,ArduinoIDEmayreportsomeerrors.Youcanrefertothe
followingsolutions.
HowtoUploadArduinoCodeHowtoInstallArduinoIDE HowtoInstallArduinoDriver

237/252
Step4:InstalltheApp
Firstly,copythe“LAFVIN_2WD_Smart_Robot_Car_BLE_V2_2.apk”filefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.

238/252
OpentheAPP,youwillseethefollowingcontrolinterface.

239/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.

240/252
Step5:BluetoothConnection
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.

241/252
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist
toautomaticallyconnect.

242/252
Report:Successfulconnected.Thismeansthatthecorrectdevicehasbeenconnected
Report:DeviceError.ThismeansthattheconnectedBluetoothdevicedoesnotbelongtotherobotcar,searchforJDY-16
andreconnect.
IfAppdoesnotfindthe"JDY-16"device,restarttheBluetoothmodule(unplugtheBluetoothmodulefromtheArduino
UNOMotorDriverShied,disconnectthepoweroftheBluetoothmodule;thenreinstallittotheArduinoUNOMotor
DriverShied,connecttothepowersupply).theredLEDflashes,whichmeansitisinaconnectablestate.Thensearchfor
BluetoothdevicesagainintheAPP.

243/252
Step6:Appcontrolinterface
Swipethescreenfromlefttoright

244/252

245/252

246/252
Youcanfreelyswitchthevariousfunctionalmodesthroughthemobilephoneapp,suchasultrasonicobstacleavoidance,
infraredobstacleavoidance,infraredremotecontrol,gravitysensorremotecontrol.Whenthebatteryvoltageislowerthan
7.4V,replaceitintime.

247/252
Thereare6iconsonthehomepage,andeachiconrepresentsafunction.Therobotcarimmediatelyexecutesthefunction
afterclicking.
IfyouhavequestionsabouttheuseoftheRemoteControlfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson9BluetoothControlRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.

248/252
Note:Useblacktapetodrawthelineonthewhitefloor.Thewidthoftheblacklineis15cm.Adjustthesensitivitythrough
thepotentiometerontheline-followingsensor.
IfyouhavequestionsabouttheuseoftheLineTrackingfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson4LineTrackingSmartCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.

249/252
Note:Itisrecommendedthattheheightoftheobstacleisgreaterthan15cm.whichmeansthattheheightoftheobstacleis
greaterthantheheightoftheultrasonicsensor.
IfyouhavequestionsabouttheuseoftheAvoidObstaclesfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson5UltrasonicInfraredObstacleAvoidanceRobotCar.Thereasonforthisistoavoid
otherfactorsaffectingtheexecutionofthisfunction.

250/252
Note:Duetoairtransportation,theremotecontroldoesnotcontainbatteries,youneedtoprepareabuttonbatteryCR2025
beforeuse.
IfyouhavequestionsabouttheuseoftheIRRemotefunction,oryouwanttoaddyourideastothisfunction,youcantest
thisfunctionseparately.Lesson7InfraredRemoteControlRobotCar.Thereasonforthisistoavoidotherfactorsaffecting
theexecutionofthisfunction.

251/252
Note:Testinadarkenvironmentandturnoffthelightsintheroom.
IfyouhavequestionsabouttheuseoftheLightSeekingfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson8LightSeekingRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.

252/252
Note:Itisrecommendedtousearectangularobjectboxtoguidetherobotcar.Length>10cm.Width>15cm.
IfyouhavequestionsabouttheuseoftheFollowMefunction,oryouwanttoaddyourideastothisfunction,youcantest
thisfunctionseparately.Lesson6UltrasonicFollowRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.
Tags