This page describes how to program mBot with the mBlock app on your smart device.
Before you start, make sure that you've got:
mBot (If you haven't completed the building of mBot, build it by referring to Build mBot first.)
1. Download and install the mBlock app
Scan the QR code below with your smart device.
Alternatively, you can search for mBlock in an app store.
2. Connect mBot to the mBlock app
(1) Enable Bluetooth on your smart device.
(2) Power on mBot.
(3) Tap to open the mBlock app.
(4) Tap Coding, and tap + on the page that appears.
(5) In the Sprite Library, choose Devices > mBot and tap √.
(6) Tap the mBot setting icon and then tap Connect on the device setting page that appears.
(7) Place your smart device close to mBot for mBlock to automatically search for and connect to mBot.
After the connection is complete, a voice message is played, indicating that the connection is successful.
3. Write a program
(1) Tap Back to coding.
(2) Set the programming mode to Live.
Live: In this mode, you can view the program running effect in real-time, which facilitates the debugging of the program. In this mode, you must keep mBot connected to the mBlock app. If they are disconnected, the program can't be run.
Upload: In this mode, you need to upload the compiled program to mBot. After being successfully uploaded, the program can still run normally on mBot when it is disconnected from the mBlock app.
Note: Programs can not only be uploaded to mBot via the mBlock app, but mBlock PC client and web version.
(3) Drag blocks to the scripts area.
a. Define the time when the program is triggered by selecting an appropriate block from the Events category. For example, select the block when green flag clicked.
Tap Events, and drag to the scripts area.
b. Define the number of times the program is to be run. For example, keep the program running after it is triggered.
Tap Control and drag the block forever () to the scripts area.
c. Define the specific conditions for obstacle avoidance and the way mBot responds to an obstacle.
Define the condition
For example, mBot starts to avoid an obstacle when the obstacle is within 9 cm away from it, and mBot keeps moving forward when no obstacle is found or an obstacle is more than 9 cm away from it.
Tap Control and drag the block if () then () else () to the scripts area.
Set the condition with a distance.
Tap Operators and drag the block () > () to the scripts area and put it in the condition block.
Tap the value 50 to change it to 9.
Tap Sensing and then drag and place the block ultrasonic sensor () distance(cm) as below.
Define the response
When mBot is more than 9 cm away from the obstacle in front, mBot keeps moving forward.
Tap Action, drag and place the block () at power ()% as below, tap and choose move forward.
() to the scripts area and put it into the condition block."},"attribs":{"0":"*0|1+x*0+32"}},"apool":{"numToAttrib":{"0":["author","7100746261334294529"]},"nextNum":1}},"align":"","folded":false}},"EKaodmuaqoMsAsx4uYuc3yEynDd":{"id":"EKaodmuaqoMsAsx4uYuc3yEynDd","snapshot":{"type":"text","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","children":[],"text":{"apool":{"nextNum":1,"numToAttrib":{"0":["author","7100746261334294529"]}},"initialAttributedTexts":{"attribs":{"0":"*0+z"},"text":{"0":"Tap the value 50 to change it to 9."}}},"align":"","folded":false}},"OUWwdiqySoqKCGxwfNhcyPKanYd":{"id":"OUWwdiqySoqKCGxwfNhcyPKanYd","snapshot":{"type":"image","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","align":"center","image":{"token":"boxcnUbplYWXSU6z4txxSS5w39f","mimeType":"image/png","size":453381,"scale":1,"width":1328,"height":645,"name":"image.png","crop":[0,0,0,0],"rotation":0}}},"Us0odCqG4oe4UUxi6nlcI1oyneh":{"id":"Us0odCqG4oe4UUxi6nlcI1oyneh","snapshot":{"type":"text","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","children":[],"text":{"apool":{"nextNum":1,"numToAttrib":{"0":["author","7010587221652717572"]}},"initialAttributedTexts":{"attribs":{"0":"*0+2b"},"text":{"0":"Click Sensing, then drag and place the ultrasonic sensor () distance(cm) as below. "}}},"align":"","folded":false}},"FqqUdeeuCoQyQ8xeY2jcbD50ngc":{"id":"FqqUdeeuCoQyQ8xeY2jcbD50ngc","snapshot":{"type":"image","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","align":"center","image":{"token":"boxcn2PQLOYnK2GqmTQp6jtvY2b","mimeType":"image/png","size":561993,"scale":1,"width":1328,"height":645,"name":"image.png","crop":[0,0,0,0],"rotation":0}}},"WwO8dAmoso66uExoVsNcRmfOnld":{"id":"WwO8dAmoso66uExoVsNcRmfOnld","snapshot":{"type":"text","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","children":[],"text":{"initialAttributedTexts":{"text":{"0":"Define the responses\nWhen it is 9cm away from the obstacle in front, mBot keeps moving forward.\nClick Action, then drag and place the move forward at power (50) percent as below."},"attribs":{"0":"*0|1+l*1+22*0|1+1*1+2a"}},"apool":{"numToAttrib":{"0":["author","7100746261334294529"],"1":["author","7010587221652717572"]},"nextNum":2}},"align":"","folded":false}},"Xd8RdtaBYoMJbMx2wOjcJkr4nMc":{"id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","snapshot":{"type":"page","parent_id":"","comments":null,"locked":false,"hidden":false,"author":"7100746261334294529","children":["XQKid4eCmok2KwxqIMxcYt9CnZh","GMcKdISy6oMouYxUPN4cEVHcnXe","VOq6dEqmCoYK4ExiaSVcfD02nTc","SYS4d66oqooYsexSwL2cSVynnGc","WyYgdK8yioC0q2x8Hvhcg6zwnYe","NOuMd4IgioscaoxvtU0ckeQrnc8","EISod28CYosYC8xkXSBc0RhHnPd","JkCcd4QwYoqS2yxWq5rca3kSnCb","GUc8dmm8OoUMm4x4oIpctKtunBb","BsOOdqCckoWSGGxCUIbc1kZ5n68","FUq4do66SouKUGx4eCucnIiYnod","BwASdI0UaoI0gAxsFNUcrnocnKg","WaqCdowS4ooykexCg6Bc0Zhgned","OE0kd8I2Ao6Ee0xY39qcwK89nbe","LKcEdMGEMoocugxCeoNctfX6n3b","X8cMdKQqwogww8xsZP0cDDPGnbh","OicoduEKOoQOACxusU7cqYBunpd","VG28dYIowoc6qExA1OUcPYmBnfe","IuAOd0kwUoksiuxYJlBcF9MTnih","XumAdaSymo2ME4xcvZpcL1WDnYb","PAYIdSUccouU2SxarOXcOvMPnS2","TIeEd0e2Cou8YAx2Uz8cPS5YnZe","EYWUdwKsiomCskxyQjgcfRcCndd","WSi6dUuC2ooSEYxwdalcOkSBn2d","IokIde0eMo0UaSxIuxicw1G8ngb","Lcs6daeGkoe2UixEbpWchwlKn3c","MmOidEmY8oymAOxmyEIcNd4Tnpb","YyS8dACA2oYoY6xyc1hcrukznmd","Qc0mdW8WYoUWaSx7Yaoc5pBxnC5","CCaodseCoo0gcixQpAacpt3wntc","AigMd8A26oq8iSx6EM4ccFg5n11","Ta6Adwe4aoGQOQxmw8JcG6VwnWe","O62Qd6oqmoo2sSxUNQ8cLpMznSe","NWGOdiSg0oy20Wxm47Yc4xCbnyd","ZaoGdWicIougauxcfyTcIOQ9nFh","H0cydyGSIoWkGgxwtkvc9HAGn7g","U8S0dMeCQoM0u4x7HdPcKSzonCn","KWqwdCe4uo4aGexMnJDcHipvnud","MA0AdSeUmos82sxOKSAcXpHEnEf","HmuAdSGemoiYqixCU8JcD3cgnZe","X6m8dEm0goUUs8xE1Fucbm4enbc","AwmGdOwGIoSyqGxyOwicxwEonUe","Bw8yd0skYoMOyuxklxdcPGFonof","E6QmdkqyaosKE0xUhMnczOlSnLg","KQsad2yq6oEQgkxeEx4cQT5Dnlc","AGksdiEAMoiKyuxUpDlcIMERnfc","G6KAdk062oiOuSx0m3qcmr7Cnaf","TYW4d4UwioKqekxchVGcdYFpnUf","HE0odMgmyoMIAixELO0ctEHunib","H8E6d2C2WoIOaYxuWFzcR51Ynof","TM2ud2yqeoQk0Mxek4scBKSJnNh","E0e0dcOYmo44SkxKeB1cwFfWnSg","KyCqd02Kwoiu2Qxa8STcGtZZnZg","AwcId2aMgoa4oEx8Pjic6oxXn8g","WcmqdIka8o8E4exmuBwcmXornTc","DWycdOOMYowA4Uxc7VpcWHORn7f","EeCAdG0SGoU8cGxm0ticcgEHnWA","EKaodmuaqoMsAsx4uYuc3yEynDd","OUWwdiqySoqKCGxwfNhcyPKanYd","Us0odCqG4oe4UUxi6nlcI1oyneh","FqqUdeeuCoQyQ8xeY2jcbD50ngc","WwO8dAmoso66uExoVsNcRmfOnld","VesAdumE2oWUAkxw1BOc5SkgnHd","ZoMadkeSsoG88AxEtqtchxD7nBg","Q8mQd0g2goG8UGxNjbjcWQBwnLV","EyaUdqQ4MoC20Yx87C0cUQQ4ngd","GouYdGaskoyK06xe4PPcxzoMnug","VGW4doSEsoqYcWxADCRcW3rdnZe","F6qod6wYSoY0IkxUSkXcnNhXnU9","MCcUdmYIqogm26xecWsczWsAnwe","DOASdIe4KoeWkAxMF8vcGiFmnyf","KcoQdgCUwoOoMaxsRFrc1I47nVc","ZIiUdacSmoWy0YxkF3HcKhssnth","Iug8dcw68ocqOqxaI1pc17HunPh","OWSWd4W0YoSE8Yx6dZNcBm89nsc","U6YGdyim2oiQmYx6WnIcYBj9ngh","SyA0dwmW0osYKixw3Crc72TOnog","Jk4Md2UwqoKIw8xARdQc0ZhenZf","TIIYdI2C2oQweYxCUyRclwk5nWc","RUEad4eC6ocssAxhlbHcAIE5nvP"],"text":{"apool":{"nextNum":2,"numToAttrib":{"0":["author","7100746261334294529"],"1":["author","7010587221652717572"]}},"initialAttributedTexts":{"attribs":{"0":"*0+v*1+3"},"text":{"0":"Program mBot with the mBlock 5 App"}}},"align":"","folded":false}}},"payloadMap":{"EeCAdG0SGoU8cGxm0ticcgEHnWA":{"level":1},"EKaodmuaqoMsAsx4uYuc3yEynDd":{"level":1},"Us0odCqG4oe4UUxi6nlcI1oyneh":{"level":1},"WwO8dAmoso66uExoVsNcRmfOnld":{"level":1}},"extra":{"mention_page_title":{},"external_mention_url":{}},"isKeepQuoteContainer":false,"selection":[{"id":66,"type":"text","selection":{"start":0,"end":143},"recordId":"EeCAdG0SGoU8cGxm0ticcgEHnWA"},{"id":67,"type":"text","selection":{"start":0,"end":35},"recordId":"EKaodmuaqoMsAsx4uYuc3yEynDd"},{"id":68,"type":"block","recordId":"OUWwdiqySoqKCGxwfNhcyPKanYd"},{"id":69,"type":"text","selection":{"start":0,"end":83},"recordId":"Us0odCqG4oe4UUxi6nlcI1oyneh"},{"id":70,"type":"block","recordId":"FqqUdeeuCoQyQ8xeY2jcbD50ngc"},{"id":71,"type":"text","selection":{"start":0,"end":178},"recordId":"WwO8dAmoso66uExoVsNcRmfOnld"}],"pasteFlag":"bd5327fd-d7f8-4879-9fa7-87fe94c2550b"}" data-lark-record-format="docx/record" class="lark-record-clipboard"
Now, a simple obstacle avoidance program is completed.
4. Run the program
See if it is as expected that mBot starts to move forward and when an obstacle is detected within 9 cm away from it, it turns left and then keeps moving forward.
Note: Keep mBot within the Bluetooth connection range of your smart device.
Tips:
-
You can change the parameter values on the blocks (e.g., change the distance threshold and responses) or add more conditions to compile your own obstacle avoidance program.
-
You can also compile other programs (such as a line following program) in a similar way.
mBot and tap √."},"attribs":{"0":"*0+y*0*1+7*0+3*0*1+4*0+5*0*1+5*0+1"}},"apool":{"numToAttrib":{"0":["author","7100746261334294529"],"1":["bold","true"]},"nextNum":2}},"align":"","folded":false}},"MmOidEmY8oymAOxmyEIcNd4Tnpb":{"id":"MmOidEmY8oymAOxmyEIcNd4Tnpb","snapshot":{"type":"image","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","align":"center","image":{"token":"boxcnowJ4nM70567ZSweaOXam0f","mimeType":"image/png","size":430776,"scale":1,"width":1355,"height":635,"name":"image.png","crop":[0,0,0,0],"rotation":0}}},"YyS8dACA2oYoY6xyc1hcrukznmd":{"id":"YyS8dACA2oYoY6xyc1hcrukznmd","snapshot":{"type":"text","parent_id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","comments":[],"locked":false,"hidden":false,"author":"7100746261334294529","children":[],"text":{"initialAttributedTexts":{"text":{"0":"(6) Tap the mBot setting icon and then tap Connect on the device setting page that appears."},"attribs":{"0":"*0+17*0*1+7*0+x*2+3*0+5"}},"apool":{"numToAttrib":{"0":["author","7100746261334294529"],"1":["bold","true"],"2":["author","7010587221652717572"]},"nextNum":3}},"align":"","folded":false}},"Xd8RdtaBYoMJbMx2wOjcJkr4nMc":{"id":"Xd8RdtaBYoMJbMx2wOjcJkr4nMc","snapshot":{"type":"page","parent_id":"","comments":null,"locked":false,"hidden":false,"author":"7100746261334294529","children":["XQKid4eCmok2KwxqIMxcYt9CnZh","GMcKdISy6oMouYxUPN4cEVHcnXe","VOq6dEqmCoYK4ExiaSVcfD02nTc","SYS4d66oqooYsexSwL2cSVynnGc","WyYgdK8yioC0q2x8Hvhcg6zwnYe","NOuMd4IgioscaoxvtU0ckeQrnc8","EISod28CYosYC8xkXSBc0RhHnPd","JkCcd4QwYoqS2yxWq5rca3kSnCb","GUc8dmm8OoUMm4x4oIpctKtunBb","BsOOdqCckoWSGGxCUIbc1kZ5n68","FUq4do66SouKUGx4eCucnIiYnod","BwASdI0UaoI0gAxsFNUcrnocnKg","WaqCdowS4ooykexCg6Bc0Zhgned","OE0kd8I2Ao6Ee0xY39qcwK89nbe","LKcEdMGEMoocugxCeoNctfX6n3b","X8cMdKQqwogww8xsZP0cDDPGnbh","OicoduEKOoQOACxusU7cqYBunpd","VG28dYIowoc6qExA1OUcPYmBnfe","IuAOd0kwUoksiuxYJlBcF9MTnih","XumAdaSymo2ME4xcvZpcL1WDnYb","PAYIdSUccouU2SxarOXcOvMPnS2","TIeEd0e2Cou8YAx2Uz8cPS5YnZe","EYWUdwKsiomCskxyQjgcfRcCndd","WSi6dUuC2ooSEYxwdalcOkSBn2d","IokIde0eMo0UaSxIuxicw1G8ngb","Lcs6daeGkoe2UixEbpWchwlKn3c","MmOidEmY8oymAOxmyEIcNd4Tnpb","YyS8dACA2oYoY6xyc1hcrukznmd","Qc0mdW8WYoUWaSx7Yaoc5pBxnC5","CCaodseCoo0gcixQpAacpt3wntc","AigMd8A26oq8iSx6EM4ccFg5n11","Ta6Adwe4aoGQOQxmw8JcG6VwnWe","O62Qd6oqmoo2sSxUNQ8cLpMznSe","NWGOdiSg0oy20Wxm47Yc4xCbnyd","ZaoGdWicIougauxcfyTcIOQ9nFh","H0cydyGSIoWkGgxwtkvc9HAGn7g","U8S0dMeCQoM0u4x7HdPcKSzonCn","KWqwdCe4uo4aGexMnJDcHipvnud","MA0AdSeUmos82sxOKSAcXpHEnEf","HmuAdSGemoiYqixCU8JcD3cgnZe","X6m8dEm0goUUs8xE1Fucbm4enbc","AwmGdOwGIoSyqGxyOwicxwEonUe","Bw8yd0skYoMOyuxklxdcPGFonof","E6QmdkqyaosKE0xUhMnczOlSnLg","KQsad2yq6oEQgkxeEx4cQT5Dnlc","AGksdiEAMoiKyuxUpDlcIMERnfc","G6KAdk062oiOuSx0m3qcmr7Cnaf","TYW4d4UwioKqekxchVGcdYFpnUf","HE0odMgmyoMIAixELO0ctEHunib","H8E6d2C2WoIOaYxuWFzcR51Ynof","TM2ud2yqeoQk0Mxek4scBKSJnNh","E0e0dcOYmo44SkxKeB1cwFfWnSg","KyCqd02Kwoiu2Qxa8STcGtZZnZg","AwcId2aMgoa4oEx8Pjic6oxXn8g","WcmqdIka8o8E4exmuBwcmXornTc","DWycdOOMYowA4Uxc7VpcWHORn7f","EeCAdG0SGoU8cGxm0ticcgEHnWA","EKaodmuaqoMsAsx4uYuc3yEynDd","OUWwdiqySoqKCGxwfNhcyPKanYd","Us0odCqG4oe4UUxi6nlcI1oyneh","FqqUdeeuCoQyQ8xeY2jcbD50ngc","WwO8dAmoso66uExoVsNcRmfOnld","VesAdumE2oWUAkxw1BOc5SkgnHd","ZoMadkeSsoG88AxEtqtchxD7nBg","Q8mQd0g2goG8UGxNjbjcWQBwnLV","EyaUdqQ4MoC20Yx87C0cUQQ4ngd","GouYdGaskoyK06xe4PPcxzoMnug","VGW4doSEsoqYcWxADCRcW3rdnZe","F6qod6wYSoY0IkxUSkXcnNhXnU9","MCcUdmYIqogm26xecWsczWsAnwe","DOASdIe4KoeWkAxMF8vcGiFmnyf","KcoQdgCUwoOoMaxsRFrc1I47nVc","ZIiUdacSmoWy0YxkF3HcKhssnth","Iug8dcw68ocqOqxaI1pc17HunPh","OWSWd4W0YoSE8Yx6dZNcBm89nsc","U6YGdyim2oiQmYx6WnIcYBj9ngh","SyA0dwmW0osYKixw3Crc72TOnog","Jk4Md2UwqoKIw8xARdQc0ZhenZf","TIIYdI2C2oQweYxCUyRclwk5nWc","RUEad4eC6ocssAxhlbHcAIE5nvP"],"text":{"apool":{"nextNum":2,"numToAttrib":{"0":["author","7100746261334294529"],"1":["author","7010587221652717572"]}},"initialAttributedTexts":{"attribs":{"0":"*0+v*1+3"},"text":{"0":"Program mBot with the mBlock 5 App"}}},"align":"","folded":false}}},"payloadMap":{"Lcs6daeGkoe2UixEbpWchwlKn3c":{"level":1},"YyS8dACA2oYoY6xyc1hcrukznmd":{"level":1}},"extra":{"mention_page_title":{},"external_mention_url":{}},"isKeepQuoteContainer":false,"selection":[{"id":35,"type":"text","selection":{"start":0,"end":59},"recordId":"Lcs6daeGkoe2UixEbpWchwlKn3c"},{"id":36,"type":"block","recordId":"MmOidEmY8oymAOxmyEIcNd4Tnpb"},{"id":37,"type":"text","selection":{"start":0,"end":91},"recordId":"YyS8dACA2oYoY6xyc1hcrukznmd"}],"pasteFlag":"bd5327fd-d7f8-4879-9fa7-87fe94c2550b"}" data-lark-record-format="docx/record" class="lark-record-clipboard"
Comments
Hi, I need save the project build in the app to share with other persons or devices, how do it?
Thanks.
Please sign in to leave a comment.