Program mBot Ranger with the mBlock App

This page describes how to program mBot Ranger with the mBlock app on your smart device.
Before you start, make sure that you've got:


A tablet or smartphone


mBot Ranger (If you haven't completed the building of mBot Ranger, build it by referring to Build a Land Raider 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 Ranger to the mBlock app

(1) Enable Bluetooth on your smart device.


(2) Power on mBot Ranger.

Press the red button to turn on Auriga.


(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 Ranger and tap √.


(6) Tap the mBot Ranger setting icon and then tap Connect on the Device setting page that appears.


(7) Place your smart device close to mBot Ranger.

mBlock automatically searches for and connects to mBot Ranger.


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 Ranger connected to mBlock. If they are disconnected, the program cannot be run.
Upload: In this mode, you need to upload the compiled program to mBot Ranger. After being successfully uploaded, the program can still run normally on mBot Ranger when it is disconnected from mBlock.
Upload mode is not available for mBot Ranger in the mBlock app. Use your computer to upload programs.

(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 Ranger responds to an obstacle.
Define the condition
For example, mBot Ranger starts to avoid an obstacle when the obstacle is within 9 cm away from it, and mBot Ranger 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 as below.


Define the response
When mBot Ranger is more than 9 cm away from the obstacle in front, mBot Ranger keeps moving forward.
Tap Action, drag and place the block () at power ()% as below, tap forward, and choose forward.



When mBot Ranger is within 9 cm away from the obstacle in front, mBot Ranger turns left.
Tap Action, drag and place the block () at power ()% as below, tap forward, and change it to 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 Ranger 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 Ranger 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?
4 out of 5 found this helpful



Please sign in to leave a comment.