Program mBot with the mBlock App

This page describes how to program mBot with the mBlock app on your smart device.

  1. Download and install the mBlock app

  2. Connect mBot to the mBlock app

  3. Write a program

  4. Run the program

Before you start, make sure that you've got:


A tablet or smartphone


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 e0a23df9-3426-4286-a4b0-06507c0d67c8.png 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.


When mBot is within 9 cm away from the obstacle in front, mBot turns left.
Tap Action, drag and place the block () at power ()% as below, tap move forward, and choose turn left.


Now, a simple obstacle avoidance program is completed.


4. Run the program

Tap the green flag in the lower right corner to 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.



  • 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.

Was this article helpful?
11 out of 14 found this helpful


1 comment
  • Translator


    Hi, I need save the project build in the app to share with other persons or devices, how do it?




Please sign in to leave a comment.