SlidePub
Home
Categories
Login
Register
Home
General
LAFVIN 4WD Smart Robot Car Kit V2.2-compressed.pdf
LAFVIN 4WD Smart Robot Car Kit V2.2-compressed.pdf
xn761
59 views
184 slides
Aug 21, 2024
Slide
1
of 256
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
About This Presentation
for lafvin4wd smart robot kit
Size:
7.05 MB
Language:
en
Added:
Aug 21, 2024
Slides:
184 pages
Slide Content
Slide 1
4WDSmartRobotCarKitV2.2
Slide 3
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
Slide 4
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.
Slide 5
1/252
Slide 6
2/252
LAFVINSmartRobotCarKitV2Introduction
SmartRobotCarKitV2.0ismainlymanufacturedusingtheArduinoUNOR3maincontrolandtheMotordriveexpansion
board,tworeductionmotors,Acrylicframechassisandsomesensors.
LAFVINSmartRobotCarKitV2havethefollowingadvantages:
1)Arduinomotordriveshieldintegratesthedriverchip,eliminatingthetraditionalcomplexwiringandinstallation
space.Theshieldusesstandardinterfacewiring,simpleandeasytounderstand,fastinstallationwiring.
Slide 7
3/252
2)ThenewlycreatedAPPcontrolsoftware,the6majorfunctionsoftherobotcarkitarecomprehensivelycontrolledbythe
APP,andthefunctionmodecanbeswitchedfreely.6in1Multi-purposeBluetoothRobotCar
Slide 8
4/252
3)ThenewlydesignedBluetoothmoduleisconnectedtothecircuit,andtheuploadprogramdoesnotrequiremanual
disconnectionoftheBluetoothmodule.Helpbeginnerlearnerstosuccessfullyavoidthetrapofuploadingprogramfailure.
Slide 9
5/252
4)SimultaneouslysupportsmixlygraphicalprogrammingandarduinoIDEcodeprogramming,whichisconvenientfor
beginnerstolearn.
Slide 10
6/252
5)Provide3Ddynamicinstallationtutorialtoquicklybuildyourrobotcar.Thepowersupplyusestwo18650lithium
batterieswithlong-lastingbatterylife.
Slide 11
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.
Slide 12
8/252
STEP2
ïŒ
Downloadthedevelopmentsoftwarethatiscompatiblewiththeoperatingsystemofyourcomputer.
TakeWindowsasanexamplehere.
Slide 13
9/252
ClickWindowsInstaller.
ClickJUSTDOWNLOAD.
Alsoversion1.8.0isavailableinthematerialweprovided,andtheversionsofour
materialsarethelatestversionswhenthiscoursewasmade.
Slide 14
10/252
InstallingArduino(Windows)
InstallArduinowiththeexe.Installationpackage.
ClickIAgreetoseethefollowinginterface
Slide 15
11/252
ClickNext
Slide 16
12/252
YoucanpressBrowseâŠtochooseaninstallationpathordirectlytypeinthedirectoryyouwant.
ClickInstalltoinitiateinstallation
Slide 17
13/252
Waitfortheinstallingprocess,ifappeartheinterfaceofWindowSecurity,justcontinuetoclick
Installtofinishtheinstallation.
Next,thefollowingiconappearsonthedesktop
Slide 18
14/252
Double-clicktoenterthedesireddevelopmentenvironment
Slide 19
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.
Slide 20
16/252
Slide 21
17/252
Thenright-clickonthedeviceandselectthetopmenuoption(UpdateDriverSoftware...)shownasthefigurebelow.
Slide 22
18/252
ThenitwillbepromptedtoeitherâSearchAutomaticallyforupdateddriversoftwareâorâBrowsemycomputerfordriver
softwareâ.Shownasbelow.Inthispage,selectâBrowsemycomputerfordriversoftwareâ.
Right-clickonthedeviceandselectthetopmenuoption(UpdateDriverSoftware...).
Slide 23
19/252
YouwillthenbepromptedtoeitherâSearchAutomaticallyforupdateddriversoftwareâorâBrowsemycomputerfordriver
softwareâ.Selecttheoptiontobrowseandnavigatetothe:C\ProgramFiles(x86)\Arduino\drivers.(Note:Hereisthepath
youchoosetoinstallarduinoIDE.Thepathchosenintheinstallationtutorialintheprevioussectionisthat,sothepathI
choseisC\ProgramFiles(x86)\Arduino\drivers)
Slide 24
20/252
ClickâNextâandyoumaygetasecuritywarning,ifso,allowthesoftwaretobeinstalled.
Oncethesoftwarehasbeeninstalled,youwillgetaconfirmationmessage.Installationcompleted,clickâCloseâ.
Slide 25
21/252
Uptonow,thedriverisinstalledwell.ThenyoucanrightclickâComputerââ>âPropertiesââ>âDevicemanagerâ,you
shouldseethedeviceasthefigureshownbelow.
Slide 26
22/252
HowtoAddLibraries
InstallingAdditionalArduinoLibraries
OnceyouarecomfortablewiththeArduinosoftwareandusingthebuilt-infunctions,youmaywanttoextendtheabilityof
yourArduinowithadditionallibraries.
WhatareLibraries?
Librariesareacollectionofcodethatmakesiteasyforyoutoconnecttoasensor,display,module,etc.Forexample,the
built-inLiquidCrystallibrarymakesiteasytotalktocharacterLCDdisplays.Therearehundredsofadditionallibraries
availableontheInternetfordownload.Thebuilt-inlibrariesandsomeoftheseadditionallibrariesarelistedinthereference.
Tousetheadditionallibraries,youwillneedtoinstallthem.
HowtoInstallaLibrary
Slide 27
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''.
Slide 28
24/252
Youwillbepromptedtoselectthelibraryyouwouldliketoadd.Navigatetothe.zipfile'slocationandopenit.
(Note:Thisisjusttodemonstratehowtoaddaziplibraryfile,whetheryouneedtoaddalibraryfiledependsonyouractual
programneeds)
Slide 29
25/252
ReturntotheSketch>ImportLibrarymenu.Youshouldnowseethelibraryatthebottomofthedrop-downmenu.Itis
readytobeusedinyoursketch.ThezipfilewillhavebeenexpandedinthelibrariesfolderinyourArduinosketches
directory.
NB:theLibrarywillbeavailabletouseinsketches,butexamplesforthelibrarywillnotbeexposedintheFile>Examples
untilaftertheIDEhasrestarted.
Thosetwoarethemostcommonapproaches.MACandLinuxsystemscanbehandledlikewise.Themanualinstallationto
beintroducedbelowasanalternativemaybeseldomusedanduserswithnoneedsmayskipit.
Slide 30
26/252
BlinkTest(Testyourfirstprogram)
youwilllearnhowtoprogramyourUNOcontrollerboardtoblinktheArduinoâsbuilt-inLED,andhowtodownload
programsbybasicsteps.
TheUNOboardhasrowsofconnectorsalongbothsidesthatareusedtoconnecttoseveralelectronicdevicesandplug-in
'shields'thatextendsitscapability.
ItalsohasasingleLEDthatyoucancontrolfromyoursketches.ThisLEDisbuiltontotheUNOboardandisoften
referredtoasthe'L'LEDasthisishowitislabeledontheboard.
Slide 31
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
Slide 32
28/252
Whenthesketchwindowopens,enlargeitsothatyoucanseetheentiresketchinthewindow.
Slide 33
29/252
TheexamplesketchesincludedwiththeArduinoIDEare'read-only'.Thatis,youcanuploadthemtoanUNOR3board,but
ifyouchangethem,youcannotsavethemasthesamefile.
Sincewearegoingtochangethissketch,thefirstthingyouneedtodoissaveyourowncopy.
FromtheFilemenuontheArduinoIDE,select'SaveAs..'andthensavethesketchwiththename'MyBlink'.
Slide 34
30/252
Youhavesavedyourcopyof'Blink'inyoursketchbook.Thismeansthatifyoueverwanttofinditagain,youcanjust
openitusingtheFile>Sketchbookmenuoption.
Slide 35
31/252
AttachyourArduinoboardtoyourcomputerwiththeUSBcableandcheckthatthe
'BoardType'and'SerialPort'aresetcorrectly.
Slide 36
32/252
Slide 37
33/252
Slide 38
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.
Slide 39
35/252
]
Next,thestatuswillchangeto'Uploading'.Atthispoint,theLEDsontheArduinoshouldstarttoflickerasthesketchis
transferred.
Slide 40
36/252
Finally,thestatuswillchangeto'Doneuploading'.
Afteruploadingthecode,youwillseethatthe"L"LEDontheArduinoUNOmotherboardwilllightupfor1second,and
thenturnofffor1second,andtheprocesswillcontinuetoloop.
Slide 41
37/252
Slide 42
38/252
Ifyouaremissingsomesteps,ArduinoIDEmayreportsomeerrors.Youcanrefertothefollowingsolutions.
(1)Itmeansthatyourboardisnotconnectedatall,orthedrivershavenotbeeninstalled(ifnecessary)orthatthewrong
serialportisselected.HowtoInstallArduinoDriver
Slide 43
39/252
(2)Itmeansthatthecommunicationserialportforuploadingcodeisoccupied.IfyouconnecttheBluetoothmodulewhen
uploadingthecode,youneedtodisconnecttheBluetoothmodulefromtheArduinoUNOexpansionboard,andthen
reinstalltheBluetoothmoduleafteruploading.
AnotherpossibilityisthattheUSBinterfaceoftheArduinoUNOisinsufficientlypowered,andyouneedtoturnonthe
externalpowerswitchoftheexpansionboard.
Slide 44
40/252
(3)Ifyouneedtouselibraryfilesinsomeprojectprograms,youmayencounterthiserror.
Itmeansthatsomelibraryfilesareusedinthecode,butyoudidnotaddthecorrespondinglibraryfilestothearduinoIDE
beforeuploadingthecode.HowtoAddLibraries
Slide 45
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.
Slide 46
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
Slide 47
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.
Slide 48
44/252
MixlyBlocksFunctions:
SystemFunctions
LookatthemaininterfaceofMixly,itincludesfiveparts,thatis,Blocksselection,codeedit,textcode(hidden),
systemfunctionandmessagepromptarea.Shownbelow.
Slide 49
45/252
Somecommonfunctions:
Throughthisinterface,youcancompletethecodecompileãuploadãsaveandmanage.Itsupportfourremove
methods:dragitleftoutcodewindow,ordragtoRecycleBin,deletekey,orright-clicktodeleteblock.Itsupports
fourlanguages:EnglishãEspañol(Spanish)ãäžæç®äœ(ChineseSimplified)ãäžæç¹äœ(ChineseTraditional).
Slide 50
46/252
HowtoInstallMixlySoftware
Firstdecompressthemixlyprogrammingsoftwarefile
Afterunzippingyouwillgetthefollowingfiles(Note:DonotincludespecialcharacterssuchasChinese,spaces,
brackets,etc.intheunzippeddirectory.Thenameoftheuncompressedpathcannothaveadoublespacebar.Ifthenamed
nameneedsaseparator,youcanuseanunderscoretoreplacethedoublespacebar,forexample,youshouldnamethefolder
Mixly_SofewaveinsteadofMixlySofewave)
Slide 51
47/252
Slide 52
48/252
Double-clickthemixlyapplicationfiletoopenthesoftware.AndselectthemaincontrolboardasArduino/GenuinoUno
Slide 53
49/252
HowtoAddMixlyLibraries
Themixlylibraryfileisanintegratedgraphicalcodecustomizedforacertaincontrolboard.Forexample,wehavewrittena
mixlylibraryfileforsmarthomelearningkit.Youcandirectlyloaditintomixlysoftwareanduseitdirectly,whichbrings
conveniencetoyourprogrammingprocess.Thegenerallibraryfilecontainsthefollowingfiles,thelast.xmlfileisthe
readablelibraryfileofthemixlysoftware
(Note:Aftercompletingtheinstallationofthemixlysoftware,thelibraryfile<LAFVINSmartRobotCarKit>already
containstheautomaticadditiontotheprogrammingsoftware,youcanuseitdirectlywithoutaddingandaddingrepeatedly.)
Slide 54
50/252
Ifyouneedtoaccidentallydeletethelibraryfile,oryouwanttoaddotherfunctionallibraryfiles,youcanrefertothe
followingstepstoaddlibraryfiles.
Afteropeningthemixlysoftware,select"import"andclicklocalimport.thenselectthepathwherethe"SmartRobot
CarKit"folderislocated,selectthefile--âSmartRobotCarKit.xmlâ,andclick"open"
Slide 55
51/252
Slide 56
52/252
ThefigurebelowshowsthattheâSmart_Robot_Tankâlibraryfilehasbeensuccessfullyimportedintothemixlysoftware.
Slide 57
53/252
Nextwewriteaprogramonthesoftwareanduploadittosmartrobotcar.
Dragtheprogramblocknamed"Moveforward"totheprogrammingarea,andmodifythePWMvariableto200.
Slide 58
54/252
HowtoUploadtheReferenceProgram
Click"Open"onthemixlysoftwareandselectthereferenceprogram.TakethereferenceprogramfromLesson3asan
example,OpenthissourceprograminMixly_Code>Lesson_3>âTest_1_Motor_Speed_and_Direction_Control.mixâ.
Slide 59
55/252
Slide 60
56/252
Slide 61
57/252
ConnecttheArduinoUNOdevelopmentboardtothecomputerwithaUSBdatacable,andturnonthepowerswitch.Select
thedevelopmentboardtypeas"Arduino/GenuinoUno"onthesoftwareandyouwillseeanewconnectionserialport
"COM17"appears.
Tip:TheserialnumberofyourarduinounoonyourPCisother.Everycomputerisdifferent,checkthecorrectserial
numberinthedevicemanagerofyourcomputer.IfnoavailableCOMinterfaceisfound,youneedtoinstallthearduino
driver.HowtoInstallArduinoDriver
Slide 62
58/252
Slide 63
59/252
Slide 64
60/252
ClickUploadandwaitfortheuploadtocomplete.Aftertheprogramuploadiscompleted,smartcargoesforwardandback
for2s,turnsleftandrightfor2s,andstopsfor2salternately.
Slide 65
61/252
Intheprocessofuploadingthecode,ifyoureportanerror,theremaybethefollowingreasons:
(1)TheUSBdatacableinterfaceisnotfirmlyconnected,orthedrivershavenotbeeninstalled(ifnecessary)orthatthe
wrongserialportisselected.HowtoInstallArduinoDriver
(2)Itmeansthatthecommunicationserialportforuploadingcodeisoccupied.IfyouconnecttheBluetoothmodulewhen
uploadingthecode,youneedtodisconnecttheBluetoothmodulefromtheArduinoUNOexpansionboard,andthen
reinstalltheBluetoothmoduleafteruploading.
(3)AnotherpossibilityisthattheUSBinterfaceoftheArduinoUNOisinsufficientlypowered,andyouneedtoturnonthe
externalpowerswitchoftheexpansionboard.
Slide 66
62/252
Theuseofeachstatementblockisdescribedbelow
In/OutBlock:
Slide 67
63/252
NO. BLOCKICON DEFINITION
1 ReturnsHIGHorLOWvoltage
2
WritedigitalvaluetoaspecificPort.Digital
Output:settheHIGHorLOWoutputforIOpins
3
ReturnsadigitalvalueofaspecificPort.Digital
IOReadPin,generallyusedtoreadtheHIGHor
LOWleveldetectedbyDigitalsensor
Slide 68
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.
Slide 69
65/252
8 SettheIOpinsasOutputorInputstate
9
ReadthecontinuoustimeofHIGHorLOWpulse
fromIOpins(generallyusedforultrasonic
ranging)
Slide 70
66/252
ControlBlock:
Slide 71
67/252
NO
.
BLOCKICON DEFINITION
1 Initialization(runonlyonce)
2
Endtheprogram,meanstheprogramwillstop
runningwhenusethisblock.
3
Delayfunction,clicktoselectmsorus(pausethe
programfortheamountoftime(inmilliseconds)
Slide 72
68/252
specifiedasparameter.Thereare1000millisecondsin
asecond.)
4
if_dofunction(firstevaluateavaluebetrueorfalse,if
avalueistrue,thendosomestatement.Youcanclick
thebluegearicontoselecttheelseifblockorelse
block.)
Slide 73
69/252
5
switchfunction.Youcanclickthebluegeariconto
selectthecaseblockordefaultblock.(usedto
evaluateseveralprogramsthenexecutethe
correspondingfunctionmatchedwithprogram.)
6 Equaltoforstatement.
Slide 74
70/252
7 Awhileloopstatement.
8 breakfunction,usedtoexitfromthecontainingloop.
Slide 75
71/252
9
millis()function,returnsthesystemrunningtimesince
theprogramstarted.(Theunitcanbems
(milliseconds)orÎŒsïŒmicrosecond)).
10
Timerinterruptfunction,thatis,setatriggerinterrupt
fortheamountoftime(inmilliseconds)specifiedas
parameter.
Slide 76
72/252
11 Timerinterruptstartblock
12 Timerinterruptstopblock
Slide 77
73/252
MathBlock:
Slide 78
74/252
NO. BLOCKICON DEFINITION
1 Anumber
2
ClicktoselecttheArithmeticOperators:ïŒ
(addition);ïŒ(subtraction);x(Multiplication);÷
(division);%(remainder);^(bitwisexor)
3
Clicktoselectthe&(bitwiseend);l(bitwiseor);<<
(bitshiftleft);>>(bitshiftright)
Slide 79
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:
Slide 80
76/252
Returnthesquareofanumber.sqrt:Returnthe
squarerootofanumber.
6
Ifselectthemax,returnsthelargernumber;
ifselectthemin,returnsthesmallernumber.
Slide 81
77/252
TextBlock:
Slide 82
78/252
NO. BLOCKICON DEFINITION
1 characterstring:aletter,word,orlineoftext.
2 Acharacter
3
Createsapieceoftextbyjoiningtogethertwopieceof
text.(HereHellojoinMixlyequalsHelloMixly)
4 Convertsastringintoanintegeroranfloat.
Slide 83
79/252
5
ReturnsthecharcorrespondingtoanASCIIcode
(Decimalnumber97correspondingtoa)
6 ReturnstheASCIIcodecorrespondingtoachar.
7 Convertsanumberintoastring.
8 Calculatesthelengthofastring
9 Outputthecharofastring(thecharat0ofhelloish)
Slide 84
80/252
10
ThefirststringequalsorstartsWithorendsWiththe
secondstring,returns1,otherwisereturns0.(ifequals,
bothstringsareabc,returns1.)
11
Returnsadecimalvalueofthefirststringsubtractsthe
secondstring.
Slide 85
81/252
ListBlock:
Slide 86
82/252
NO. BLOCKICON DEFINITION
1
Createalistwithanynumberofitems
2
Creatsalistfromatext.(intmylist[]={0,0,0};)
3
Returnsthelengthofalist
4
Returnsthevalueofatthespecifiedpositioninalist.
5
Setsthevalueofatthespecifiedpositioninalist.
Setthefirstiteminmylisttoanotheritem.
Slide 87
83/252
LogicBlock:
Slide 88
84/252
NO
.
BLOCKICON DEFINITION
1
logiccomparision=:Returntrueifbothinputsequaleach
other.â :Returntrueifbothinputsarenotequaltoeach
other.<:Returntrueifthefirstinputissmallerthanthe
secondinput.â€:Returntrueifthefirstinputissmaller
thanorequaltothesecondinput.>:Returntrueifthe
firstinputisgreaterthanthesecondinput.â¥:Returntrue
ifthefirstinputisgreaterthanorequaltothesecond
input.
Slide 89
85/252
2
and:Returntrueifbothinputsaretrue;or:Returntrueif
atleastoneoftheinputsistrue
3
Returnstrueiftheinputisfalse.Returnsfalseiftheinput
istrue.
4 Returnseithertrueorfalse.
5 Returnsnull
6
Ifthefirstnumberistrue,thesecondnumberisreturned,
otherwisethethirdnumber.
Slide 90
86/252
SerialPortBlock:
Slide 91
87/252
NO. BLOCKICON DEFINITION
1 Settheserialbuadrateto9600
2 Writethespecifiednumber,textorothervalue.
3
Printthespecifiednumber,textorothervalue
onmonitor.
4
Printthespecifiednumber,textorothervalue
onnewlineofmonitor.
Slide 92
88/252
5
Printthespecifiednumberinhexademical
formatonnewlineofmonitor.
6
Iftheserialportisavailable,itreturnstrue,
otherwisereturnsfalse.(generallyusedin
Bluetoothcommunication)
7 Returnsastringinserialport
8
Astringreadfromserialporttoastringvariable,
pauseuntilreadthespecifiedcharacter.
Slide 93
89/252
9
Readtheserialdatabybyte(generallyusedto
readthevaluesentfromBluetooth)(deletethe
datahasbeenread)
10 Waitfortheoutputdatacompleted
11
Setthesoftwareserialport(callthisfunctionif
needtouseseveralserialports)
12
Eventfunctiontriggerbyserialportdata,thatis,
serialportisreadytocallthisfunction.(equalto
aninterruptfunction)
Slide 94
90/252
MonitorBlock:
Slide 95
91/252
NO. BLOCKICON DEFINITION
1 SettheIICLCD1602address
2
InputthevalueonLCDline1andline2fromleftto
right.
3 SettherowandcolumnofLCDtoprintthechar
4 CleartheLCDscreen
Slide 96
92/252
VariablesBlock
Slide 97
93/252
NO. BLOCKICON DEFINITION
1 Defineanintegervariable
whosenameisitem
2 Mandatorytypeconversionof
constantsorvariables
Slide 98
94/252
FunctionsBlock:
Slide 99
95/252
NO. BLOCKICON DEFINITION
1
Createsafunctionwithnooutput.Clicktheblueicontosetthe
procedureparameter.(noreturnvalue)
2
Createsafunctionwithanoutput.Clicktheblueicontosetthe
procedureparameter.(withreturnvalueandcansetthedata
types)
3 Ifavalueistrue,thenreturnasecondvalue.
Slide 100
96/252
Smart_Robot_TankBlock:
Slide 101
97/252
Slide 102
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.
Slide 103
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
Slide 104
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
Slide 105
101/252
8 Controltherotationangleoftheservo
motor,theanglerangeofrotationis0~180
degrees
9 Thisprogramblockisinitializedanddefines
theIOdatainterfaceconnectedtothe
infraredreceiver
Whenthekeycommandoftheremote
controlisreceivedandthevaluesetbythe
programblockisthesame,theprogram
blockoutputslogicture.
10 Usetheultrasonicmoduletomeasurethe
distance,theprogramblockreturnsthe
measureddistancevalue,theunitiscm
Slide 106
102/252
11
Thefunctionofthisprogramblockisto
receivethedetectionresultoftheinfrared
obstacleavoidancesensorandsavethe
receivedresulttothevariable
left_infrared_avoidance_sensoror
right_infrared_avoidance_sensor
12
Thisprogramblockisusedtoreceivethe
informationsentbytheBluetoothmodule,
andstorethereceivedinformationinthe
variablebluetooth_val
Slide 107
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.
Slide 108
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)
Slide 109
105/252
Slide 110
106/252
A1A2B1B2ofthemotorArduinoshieldistheinterfaceofthemotor.
ThemotorsconnectedtotheA1interfaceandtheA2interfacehavethesamespeedandthesamedirection.
ThemotorsconnectedtotheB1andB2portshavethesamespeedandthesamedirection.
TheD2digitalI/OportcontrolsthedirectionofthemotoroftheportA,andtheD5digitalI/OportoutputsthePWMsignal
tocontrolthespeedofthemotoroftheportA.
TheD4digitalI/OportcontrolsthedirectionofthemotoroftheinterfaceB,andtheD6digitalI/OportoutputsthePWM
signaltocontrolthespeedofthemotoroftheinterfaceB.
Slide 111
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
Slide 112
108/252
Howtoconnectthecircuit
Let'sprogram
Test1--MotorSpeedandDirectionControl
Slide 113
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
Slide 114
110/252
Thisblockcontrolsthedirectionoftherobotcartoforwardorbackward,255representsthemaximumspeed,andtherange
thatcanbemodifiedis0-255.Whenthespeedissetto0,itmeansstop.
The"RotateLeft"programblockcontrolstherobotcartomakeacircletotheleft.Speed90PWMmeansthatthecar
movesataspeedof90.Theminimumspeed0PWMmeansstop,andthemaximumspeedratiois255PWM.
Slide 115
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.
Slide 116
112/252
Lesson4LineTrackingSmartCar
Overview
Inthislesson,wewillcompletethetestoftwoexperimentalcodes.Inexperimentaltest1,welearnedhowtousethe
infraredline-followingsensor,andobservedtheresultsreturnedbythesensortodistinguishblackandwhiteobjects.Inthe
experimentaltest2,welearnedtocombinetheinfraredline-followingsensorwiththemotortocontroltherobotcarto
completetheline-followingfunction.
Slide 117
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
Slide 118
114/252
thethresholdbetweenONandOFF,thesensitivityisthebest.
Slide 119
115/252
Howtoconnectthecircuit
Slide 120
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.
Slide 121
117/252
Afteruploadingtheprogram,opentheserialmonitortoviewthesignalreturnedbytheinfraredobstacle
avoidancesensor.
Slide 122
118/252
Thenyoucanseethedataasblow:
Whendetectswhitepaper,sensorâssignalpinoutputsLOW(display0),andstatusLEDison;Whendetectsblack,sensorâs
signalpinoutputsHIGH(display1),andstatusLEDisoff.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill
Slide 123
119/252
occupythecommunicationinterfaceoftheuploadedprogram.
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Line_Tracking_Sensor.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance
Thenyoucanseethedataasblow:
Slide 124
120/252
Whendetectswhitepaper,sensorâssignalpinoutputsLOW(display0),andstatusLEDison;Whendetectsblack,sensorâs
signalpinoutputsHIGH(display1),andstatusLEDisoff.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill
occupythecommunicationinterfaceoftheuploadedprogram.
Slide 125
121/252
Test2--LineTrackingSmartCar
Intheexperimentaltest2,welearnedtocombinetheinfraredline-followingsensorwiththemotortocontroltherobotcar
tocompletetheline-followingfunction.
Slide 126
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.
Slide 127
123/252
Slide 128
124/252
WhenintheAstate,onlythemiddleline-followingsensordetectstheblackline,andtherobotcarmovesstraightataspeed
of120.
WhenintheBstate,theleftline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotheleftataspeedof80%.
WhenintheDstate,therightline-followingsensorandthecenterline-followingsensordetecttheblackline,andtherobot
carrotatestotherightataspeedof80%.
Slide 129
125/252
WhenintheCstate,theleftline-followingsensordetectstheblackline,andtherobotcarrotatestotheleftataspeedof
120%.
Slide 130
126/252
WhenintheEstate,therightline-followingsensordetectstheblackline,andtherobotcarrotatestotherightataspeedof
120%.
Whenthethreeline-followingsensorsdetecttheblacklineatthesametime,therobotcarstops.
Slide 131
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);
Slide 132
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%.
Slide 133
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);
Slide 134
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);
Slide 135
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);
}
Slide 136
132/252
Whatwillyousee
UploadthetestcodetoUNOR3controlboard,turnthePOWER
switchON.Thenthesmartcarwillmovealongtheblackline.
Note:Thefloorsofdifferentmaterialsinthehomehavedifferentdegreesoflightreflection.Youcanadjustthe
potentiometerontheline-followingsensortochangetheresponsesensitivity.Thiscanmakethecarfollowtheblackline
moresmoothly.
Slide 137
133/252
Lesson5UltrasonicInfraredObstacleAvoidanceRobotCar
Overview
Inthislesson,wewillcompletethetestof4experimentalcodes.
Inexperimentaltest1,weseparatelylearnhowtouseinfraredobstacle-avoidancesensorstodetectobstacles,andobserve
theresultsreturnedbythesensorstodeterminewhetherobstaclesaredetected.
Inthesecondexperimentaltest2,wewilllearntousetheultrasonicmoduletomeasuredistance.
Intheexperimentaltest3,wewilllearnhowtocontroltheservomotortorotatetoanyangle.
Intheexperimentaltest4,theinfraredobstacleavoidancesensor,theultrasonicmoduleandtheservomotorwere
assembledontherobotcaratthesametime,andthedataofthesesensorswereusedatthesametimetoassisttherobotcar
tocompletetheobstacleavoidancefunctionmoreaccurately.
Slide 138
134/252
Slide 139
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.
Slide 140
136/252
Slide 141
137/252
Whatisanultrasonicsensor
Reviewtheultrasonicsensorfromthepreviouslesson.Itworkslikeabat'seye.Determinethedistanceofobstaclesinfront
afterreceivingandreceivinghigh-frequencysoundwaves.
Asthefollowingpictureshown,itisourultrasonicmodule.Ithastwosomethinglikeeyes.
Oneistransmittingend,theotherisreceivingend.
Slide 142
138/252
TheHC-SR04ultrasonicsensorusessonartodeterminedistancetoanobjectlikewhatbatsdo.Itoffersexcellent
non-contactrangedetectionwithhighaccuracyandstablereadingsinaneasy-to-usepackage.Itcomescompletewith
ultrasonictransmitterandreceivermodules.TheHC-SR04ortheultrasonicsensorisbeingusedinawiderangeof
electronicsprojectsforcreatingobstacledetectionanddistancemeasuringapplicationaswellasvariousotherapplications.
Herewehavebroughtthesimplemethodtomeasurethedistancewitharduinoandultrasonicsensor
andhowtouseultrasonicsensorwitharduino.
Slide 143
139/252
Specification
PowerSupply:+5VDC
QuiescentCurrent:<2mA
WorkingCurrent:15mA
EffectualAngle:<15°92
RangingDistance:2cmâ400cm
Resolution:0.3cm
MeasuringAngle:30degree
TriggerInputPulsewidth:10uS
Slide 144
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°.
Slide 145
141/252
TherotationangleofservomotoriscontrolledbyregulatingthedutycycleofPWM(Pulse-WidthModulation)signal.The
standardcycleofPWMsignalis20ms(50Hz).Theoretically,thewidthisdistributedbetween1ms-2ms,butinfact,it's
between0.5ms-2.5ms.Thewidthcorrespondstherotationanglefrom0°to180°.Butnotethatformotorsofdifferent
brands,thesamesignalmayhavedifferentrotationangle.
Slide 146
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
Slide 147
143/252
Howtoconnectthecircuit
Slide 148
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.
Slide 149
145/252
Afteruploadingtheprogram,opentheserialmonitortoviewthesignalreturnedbytheinfraredobstacle
avoidancesensor.
Slide 150
146/252
Thenyoucanseethedataasblow:
Whenthereisanobstacleinthefront,IR_value=0,andtheindicatorlightonthesensorlightsup.
Importantnote:Beforeyouuploadtheprogram,youneedtoclosetheserialmonitor,otherwisetheserialmonitorwill
occupythecommunicationinterfaceoftheuploadedprogram.
Slide 151
147/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_1_Infrared_Obstacle_Avoidance_Sensor.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance
Slide 152
148/252
Thenyoucanseethedataasblow:
Whenthereisanobstacleinthefront,IR_value=0,andtheindicatorlightonthesensorlightsup.
Note:Beforeuploadingthecode,youneedtoturnofftheserialmonitoroftheArduinoIDEandthemonitoroftheMixly
software,otherwisethecodeuploadwillfailbecausetheserialportisusuallyoccupied.
Slide 153
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
Slide 154
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:
Slide 155
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.
Slide 156
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.
Slide 157
153/252
Afteruploadingtheprogram,opentheserialmonitortoviewthedistancemeasuredbytheultrasonicsensor.
Slide 158
154/252
Thenyoucanseethedataasblow:
Note:thatyouneedtocloseboththeArduinoIDEserialmonitorandtheserialmonitoroftheMixlysoftwarebefore
uploadingthecode,otherwisethecodewillfailtouploadbecausethecommunicationserialportisoccupied.
Slide 159
155/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openArduinoIDEsoftwareandopenthereferencecodeforthislesson
"Test_3_Ultrasonic_Sensor_Module.ino"inthereferencematerialsweprovided.
Afteruploadingthecode,clickthebuttonintheupperrightcornertoopentheserialmonitortoviewthemeasureddistance
Slide 160
156/252
Thenyoucanseethedataasblow:
Note:Beforeuploadingthecode,youneedtoturnofftheserialmonitoroftheArduinoIDEandthe
monitoroftheMixlysoftware,otherwisethecodeuploadwillfailbecausetheserialportisusually
occupied.
Slide 161
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
Slide 162
158/252
Slide 163
159/252
Slide 164
160/252
Slide 165
161/252
Slide 166
162/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_4_Ultrasonic_Infrared_Obstacle_Avoidance_Robot_Car.ino"inthereferencematerialsweprovided.
ProgrammingThinking
Thefollowingistheprogramexecutionflowchartoftherobotcartocompletetheobstacleavoidancefunction
Slide 167
163/252
Slide 168
164/252
Slide 169
165/252
Slide 170
166/252
Slide 171
167/252
Slide 172
168/252
Whatwillyousee
UploadthecodetoUNOR3controlboard,,andturnthePOWERswitchON.Note:Itisrecommendedthattheheightofthe
obstacleisgreaterthan15cm.whichmeansthattheheightoftheobstacleisgreaterthantheheightoftheultrasonicsensor.
Becauseofreceivingthedetectionsignalsofultrasonicandinfraredobstacleavoidancemodulesatthesametime,therobot
carcancompletetheobstacleavoidancefunctionmoreaccurately.Whenobstaclesareontheleftandrightsidesoftherobot
car,theycanbediscoveredbytheinfraredobstacleavoidancemoduleintimeandturntoavoid.Whentheobstacleis
directlyinfront,theultrasonicwillbeabletomeasurethedistancebetweentherobotcarandtheobstacle.
Slide 173
169/252
Lesson6UltrasonicFollowRobotCar
Overview
Inthelastcourse,Ilearnedhowtousetheultrasonicmoduleandinfraredobstacleavoidancemodule.Similarly,combining
thesetwomodulescancontroltherobotcartocompletethefollowingfunction.
Whentheguidingobjectisontheleftandrightsidesoftherobotcar,theinfraredobstacleavoidancemodulecandetectand
judgethedirectionoftheguidingobject,andcontroltherobotcartoturntotheguideobject.
Whentheguidedobjectisdirectlyinfrontoftherobotcar,theultrasonicsensorcandetectthedistancebetweentherobot
carandtheguideobject.Whenthedistanceisgreaterthan10mm,controltherobotcartoapproachtheguide;
Whenthedistanceislessthan5mm,controltherobotcartomovebackwardandkeepaproperdistance,5mm<D<10mm.
Slide 174
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.
Slide 175
171/252
Slide 176
172/252
Whatisanultrasonicsensor
Reviewtheultrasonicsensorfromthepreviouslesson.Itworkslikeabat'seye.Determinethedistanceofobstaclesinfront
afterreceivingandreceivinghigh-frequencysoundwaves.
Asthefollowingpictureshown,itisourultrasonicmodule.Ithastwosomethinglikeeyes.
Oneistransmittingend,theotherisreceivingend.
Slide 177
173/252
TheHC-SR04ultrasonicsensorusessonartodeterminedistancetoanobjectlikewhatbatsdo.Itoffersexcellent
non-contactrangedetectionwithhighaccuracyandstablereadingsinaneasy-to-usepackage.Itcomescompletewith
ultrasonictransmitterandreceivermodules.TheHC-SR04ortheultrasonicsensorisbeingusedinawiderangeof
electronicsprojectsforcreatingobstacledetectionanddistancemeasuringapplicationaswellasvariousotherapplications.
Herewehavebroughtthesimplemethodtomeasurethedistancewitharduinoandultrasonicsensor
andhowtouseultrasonicsensorwitharduino.
Slide 178
174/252
Howtoconnectthecircuit
Slide 179
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.
Slide 180
176/252
ProgrammingThinking
Thefollowingistheprogramexecutionflowchartoftherobotcartocompletetheultrasonicfollowfunction
Slide 181
177/252
Slide 182
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.
Slide 183
179/252
Lesson7InfraredRemoteControlRobotCar
Overview
Inthislesson,wewilllearntheinfraredremotecontrol,andusetheinfraredremotecontroltocontroltherobotcargo
forward,backward,turnleft,turnright,rotateleftrotateright.Note:Duetoairtransportation,theremotecontroldoesnot
containbatteries,youneedtoprepareabuttonbatteryCR2025beforeuse.
Slide 184
180/252
Whatisaninfraredremotecontrol
Thereisnodoubtthatinfraredremotecontroliscommonlyseeninourdailylife.It'shardtoimagineourworldwithout
it.Aninfraredremotecontrolcanbeusedtocontrolawiderangeofhomeappliancessuchastelevision,audio,video
recordersandsatellitesignalreceivers.Well,inthefollowingletâsgetabetterunderstandingoftheinfraredremote
control.Infraredremotecontroliscomposedofinfraredtransmittingandinfraredreceivingsystems.Thatis,consistofan
infraredremotecontrol,aninfraredreceivermoduleandamicrocontrollerthatcandecode.Youcanrefertothefigurebelow.
Remotecontrolkeyvalue
Slide 185
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.
Slide 186
182/252
Whatisaninfraredreceiver
Therobotshieldcomeswithinfraredreceivermodule.Itismainlycomposedofaninfraredreceivinghead.Thisdevice
integrateswithreception,amplificationanddemodulation.ItsinterIChasbeendemodulated,outputtingDigitalsignal.
SuitableforIRremotecontrolandinfrareddatatransmission.Thedatainterfaceoftheinfraredreceiverisconnectedtothe
D3digitalIOport.
Slide 187
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.
Slide 188
184/252
ProgrammingThinking
Thisprogramblockistoinitializetheinfraredreceiver,andtheportnumberisfilledwith"3".
ThedatainterfaceoftheinfraredreceiverisconnectedtotheD3digitalIOport.
Selectthebuttonyouneedtoset.Whenthespecifiedbuttonispressed,theblockoutputstruelogic.
Slide 189
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
Slide 190
186/252
Lesson8LightSeekingRobotCar
Overview
Inthislesson,wemainlystudytwoexperimentaltests.Inthefirsttestexperiment,welearnthephotoelectricsensoranduse
ittoobtainthelightintensityintheenvironment;inthesecondtestexperiment,thephotoelectricsensorandmotorcontrol
needtobecombined,sothatwhenthecarsensesstronglight,Willmoveinthedirectionofthelight.
Slide 191
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.
Slide 192
188/252
Howtoconnectthecircuit
Slide 193
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.
Slide 194
190/252
Afteruploadingtheprogram,Useacovertoblockthelightnearthephotoresistor,andthenobservethatthe
outputvalueofthelight-seekingsignalontheserialmonitorisrelativelylarge,andthenremovethe
obstruction.Itisfoundthattheoutputvalueofthelight-seekingsignalontheserialmonitorbecomes
smaller.Youcanalsousetheflashlightofthemobilephonetoilluminatethephotoresistortoobservethe
changeoftheoutputvalueofthelight-seekingsignalontheserialmonitor.
Slide 195
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.
Slide 196
192/252
ProgrammingThinking
ThespecificsoftwaredesignideaisasshowninFigure
Slide 197
193/252
Slide 198
194/252
ArduinoCode
ifyouwanttorefertotheprogramweprovide.openthereferencecodeforthislesson
"Test_2_Light_Seeking_Robot_Car.ino"inthereferencefilesweprovidedonCD.
Slide 199
195/252
Whatwillyousee
UploadthecodetoUNOR3controlboard,andturnthePOWERswitchON.Testinadarkenvironmentandturnoffthe
lightsintheroom.Thelightoftheflashlightfacesthephotoelectricsensorontheright,andtherobotcarturnsright.The
lightoftheflashlightfacesthephotoelectricsensorontheleft,andtherobotcarturnsleft.
Slide 200
196/252
Lesson9BluetoothControlRobotCar
Overview
Inthislesson,wemainlystudytwoexperimentaltests.
InTest1,welearnthecommunicationbetweentheBluetoothmoduleandthemobilephone.
InTest2,usetheappremotecontroltocontrolthedirectionoftherobotcar.
Slide 201
197/252
Slide 202
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
Slide 203
199/252
applicationinproductsfasterandmoreconvenient.
ProductParameters:
Model:JDY-16
Workingfrequency:2.4G
Transmittingpower:0db(maximum)
Communicationinterface:UARTorIIC
Workingvoltage:1.8V-3.6V
Slide 204
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â
Slide 205
201/252
Howtoconnectthecircuit
Slide 206
202/252
Slide 207
203/252
HowtoconnectAPPwithbluetoothmodule
Firstly,copytheâLAFVIN_4WD_Smart_Robot_Car_BLE_V2_2.apkâfilefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.
Slide 208
204/252
Opentheapp,youwillseethefollowinginterface,swipeleftandrighttoswitchpages.
Slide 209
205/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.
Slide 210
206/252
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist
Slide 211
207/252
toautomaticallyconnect.
Slide 212
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
Slide 213
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.
Slide 214
210/252
ProgrammingThinking
Setthebaudrateforserialcommunicationto9600.ThecommunicationspeedbetweentheserialportoftheArduinoUNO
maincontrolboardandtheserialportofBluetoothneedstobethesame.ThecommunicationbaudrateoftheBluetooth
moduleis9600bydefault.
Slide 215
211/252
Iftheserialporthasreceivednewinformation,itwillnotstopuntilthenewdataisreceived.
Combinetheendingcharactersintoastring.Needtodelaywaitingforthereceptiontocomplete.
Ifanewcharacterstringisreceived,printthereceivedcharacterstringtotheserialmonitor,andclearthelastdatawithout
Slide 216
212/252
preparingforthenextreception.
Aftercompletingtheprogramupload,opentheserialmonitortoviewtheinformationreceivedbytheBluetoothmodule.
Slide 217
213/252
AftertheBluetoothmoduleofthemobilephoneandtheBluetoothmoduleoftherobotcararesuccessfullyconnectedïŒ
Whenyoupresstheupbutton,thecharacterreceivedbyBluetoothisâ%G#â,
Whenyoupressthedownbutton,thecharacterreceivedbyBluetoothisâ%T#â.
Similarly,youcanusethismethodtotestthecommandsofotherbuttonsintheAPP.
Slide 218
214/252
Setthebaudrateforserialcommunicationto9600.ThecommunicationspeedbetweentheserialportoftheArduinoUNO
maincontrolboardandtheserialportofBluetoothneedstobethesame.ThecommunicationbaudrateoftheBluetooth
moduleis9600bydefault.
Slide 219
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.
Slide 220
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);
Slide 221
217/252
BLE_value="";//clearthelastdatawithoutpreparingforthenextreception.
}
}
Ifanewcharacterstringisreceived,printthereceivedcharacterstringtotheserialmonitor,andclearthelastdatawithout
preparingforthenextreception.
Slide 222
218/252
Aftercompletingtheprogramupload,opentheserialmonitortoviewtheinformationreceivedbytheBluetoothmodule.
Slide 223
219/252
AftertheBluetoothmoduleofthemobilephoneandtheBluetoothmoduleoftherobotcararesuccessfullyconnectedïŒ
Whenyoupresstheupbutton,thecharacterreceivedbyBluetoothisâ%A#â,
Whenyoupressthedownbutton,thecharacterreceivedbyBluetoothisâ%I#â.
Similarly,youcanusethismethodtotestthecommandsofotherbuttonsintheAPP.
Slide 224
220/252
Note:thatyouneedtocloseboththeArduinoIDEserialmonitorandtheserialmonitoroftheMixlysoftwarebefore
uploadingthecode,otherwisethecodewillfailtouploadbecausethecommunicationserialportisoccupied.
Slide 225
221/252
Test2BluetoothControlRobotCar
Step1:Circuitwiring
Connectthewiringaccordingtothewiringdiagram,payingattentiontothepositiveandnegativepolesofthepowersupply.
Correctlydistinguishtheinstallationpositionofthesensormodule,suchasleft,center,rightlinetrackingmodule.A1:Left
frontmotorB1:Rightfrontmotor.
Slide 226
222/252
Slide 227
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.
Slide 228
224/252
Step3:Installtheapp
Firstly,copytheâLAFVIN_4WD_Smart_Robot_Car_BLE_V2_2.apkâfilefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.
Slide 229
225/252
OpentheAPP,youwillseethefollowingcontrolinterface.
Slide 230
226/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.
Slide 231
227/252
Step4:Bluetoothconnection
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.
Slide 232
228/252
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist
toautomaticallyconnect.
Slide 233
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.
Slide 234
230/252
Step5:Appcontrolinterface
Slide 235
231/252
ThemainfunctionoftheRemoteControlinterfaceistocontrolthedirectionandspeedoftherobotcar.Whenthebattery
voltageislowerthan7.4V,replaceitintime.
Slide 236
232/252
6in1Multi-purposeBluetoothRobotCar
Allfunctionsarecollectedintothesameprogram,includingLineTracking,UltrasonicInfraredAvoidObstacles,Infrared
Remote,LightSeeking,FollowMe,RemoteControl,GravitySensorRemoteControl,andanyfunctioncanbefreely
switchedthroughtheapp.
Slide 237
233/252
Step1:AssembletheRobotCar
Refertotheassemblyvideotocompletetheinstallationoftherobotcar.Tip:Thelengthofthescrewismarkedinthevideo,
youshouldusethesamelength.Beforeinstallation,youneedtoidentifyM3*6mmM3*8mmM3*10mmM3*12mm.Ifyou
usethewrongscrewlengthinthefirsthalf,therewillbemissingscrewsinthelowerpartoftheinstallation.
Slide 238
234/252
Step2:CircuitWiring
Connectthewiringaccordingtothewiringdiagram,payingattentiontothepositiveandnegativepolesofthepowersupply.
Correctlydistinguishtheinstallationpositionofthesensormodule,suchasleft,center,rightlinetrackingmodule.A1:Left
frontmotorB1:Rightfrontmotor.Ifyouconnectsomepartsbymistake,itwillaffectthenormalexecutionoftherobotcar.
Slide 239
235/252
Slide 240
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
Slide 241
237/252
Step4:InstalltheApp
Firstly,copytheâLAFVIN_2WD_Smart_Robot_Car_BLE_V2_2.apkâfilefromtheAPPfoldertoyourmobilephoneand
installitintoanapplicationsoftware.AndroidphonesequippedwithBluetooth4.0andupgradedtoAndroid4.3Orhigher
system.
Slide 242
238/252
OpentheAPP,youwillseethefollowingcontrolinterface.
Slide 243
239/252
Important:Allowsaccesstolocationpermissionsandpermissiontoconnecttonearbydevices,otherwiseitmaynotbe
possibletosearchfornearbyBluetoothdevices.
Slide 244
240/252
Step5:BluetoothConnection
InstalltheBluetoothmoduletotheArduinoUNOMotorDriverShied,turnonthepowerswitch,andtheindicatorlightof
theBluetoothmodulestartstoflash,whichmeansitisinaconnectablestate.ClicktheBluetoothicon toenterthe
Bluetoothpairingfunctionpage.
Slide 245
241/252
andthenclickdevicescan,AftersuccessfullysearchingforthedeviceJDY-16,clickthedeviceaddressinthedevicelist
toautomaticallyconnect.
Slide 246
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.
Slide 247
243/252
Step6:Appcontrolinterface
Swipethescreenfromlefttoright
Slide 248
244/252
Slide 249
245/252
Slide 250
246/252
Youcanfreelyswitchthevariousfunctionalmodesthroughthemobilephoneapp,suchasultrasonicobstacleavoidance,
infraredobstacleavoidance,infraredremotecontrol,gravitysensorremotecontrol.Whenthebatteryvoltageislowerthan
7.4V,replaceitintime.
Slide 251
247/252
Thereare6iconsonthehomepage,andeachiconrepresentsafunction.Therobotcarimmediatelyexecutesthefunction
afterclicking.
IfyouhavequestionsabouttheuseoftheRemoteControlfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson9BluetoothControlRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.
Slide 252
248/252
Note:Useblacktapetodrawthelineonthewhitefloor.Thewidthoftheblacklineis15cm.Adjustthesensitivitythrough
thepotentiometerontheline-followingsensor.
IfyouhavequestionsabouttheuseoftheLineTrackingfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson4LineTrackingSmartCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.
Slide 253
249/252
Note:Itisrecommendedthattheheightoftheobstacleisgreaterthan15cm.whichmeansthattheheightoftheobstacleis
greaterthantheheightoftheultrasonicsensor.
IfyouhavequestionsabouttheuseoftheAvoidObstaclesfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson5UltrasonicInfraredObstacleAvoidanceRobotCar.Thereasonforthisistoavoid
otherfactorsaffectingtheexecutionofthisfunction.
Slide 254
250/252
Note:Duetoairtransportation,theremotecontroldoesnotcontainbatteries,youneedtoprepareabuttonbatteryCR2025
beforeuse.
IfyouhavequestionsabouttheuseoftheIRRemotefunction,oryouwanttoaddyourideastothisfunction,youcantest
thisfunctionseparately.Lesson7InfraredRemoteControlRobotCar.Thereasonforthisistoavoidotherfactorsaffecting
theexecutionofthisfunction.
Slide 255
251/252
Note:Testinadarkenvironmentandturnoffthelightsintheroom.
IfyouhavequestionsabouttheuseoftheLightSeekingfunction,oryouwanttoaddyourideastothisfunction,youcan
testthisfunctionseparately.Lesson8LightSeekingRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.
Slide 256
252/252
Note:Itisrecommendedtousearectangularobjectboxtoguidetherobotcar.Length>10cm.Width>15cm.
IfyouhavequestionsabouttheuseoftheFollowMefunction,oryouwanttoaddyourideastothisfunction,youcantest
thisfunctionseparately.Lesson6UltrasonicFollowRobotCar.Thereasonforthisistoavoidotherfactorsaffectingthe
executionofthisfunction.
Tags
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
59
Slides
184
Age
483 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
41 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
45 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
40 views
14
Fertility awareness methods for women in the society
Isaiah47
38 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
37 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
39 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-184)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better