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:

1280X1280_-_2023-03-13T143813.664.PNG

A tablet or smartphone

1280X1280_-_2023-03-13T150158.978.PNG

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.

1280X1280_-_2023-03-13T144024.340.PNG

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.

1280X1280_-_2023-03-13T150600.006.PNG

(2) Power on mBot Ranger.

Press the red button to turn on Auriga.

1280X1280_-_2023-03-13T150606.310.PNG

(3) Tap to open the mBlock app.

1280X1280_-_2023-03-13T144128.394.PNG

(4) Tap Coding, and tap + on the page that appears.

275969e5-26cc-414f-a346-be34694aea3f.png

(5) In the Sprite Library, choose Devices > mBot Ranger and tap √.

c48e4097-beeb-4fe4-856e-6e49982c2205.png

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

6d740b0b-be54-40b4-8ad7-845bdab8e5b6.pngd5f3c200-bf0f-44dd-b41a-54a79e7aa60f.png

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

mBlock automatically searches for and connects to mBot Ranger.

b2a575cb-60a3-4ce5-b5bc-7fd47168a936.png

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.

555e0e31-207b-4885-b4d9-9e9ab56b6802.png

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.
Note:
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.
66092db5-cd47-4f6c-b94d-c91f742c2f29.png
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.

53c5aab3-aec5-41ef-bf47-8d43ebf39f44.png

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.

954a4178-2443-44d9-b2aa-6b307a74bee8.png

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.

03994d2a-ca5d-4e34-b09a-15e0bc7a157b.png

Tap Sensing and then drag and place the block ultrasonic sensor () distance as below.

1cd7b6a2-c4b4-4d4c-9cd4-83255c92ebdb.png

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.

6c04ba84-d645-42de-8d26-892b9189b72c.png

543590ad-1e1c-4e3b-ad13-82a22028e3c1.png

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.
ff4ae799-0414-4dbb-b5e1-3532936084ca.png92ace593-3cfb-4136-bee7-655a9625f602.png
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.
7d5e1851-1289-4f7b-896f-631ad9230e5f.png
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.
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.

 

 

Was this article helpful?
8 out of 10 found this helpful

Comments

0 comments

Please sign in to leave a comment.