MBC Ranger 8-Way (TOF8) × MBC SPIKE Blocks website

Read the Ranger 8-Way on the MBC Blocks website in three steps

On the MBC SPIKE Blocks website you do not need to import a library for the Ranger 8-Way: first, under "run once at start", tell the website which port the sensor is on; then add the main loop; finally put a reading block inside the main loop. Follow the steps on the left and the blocks on the right grow with you. These block pictures were built and exported straight from the website, so they look just like your screen.

The website's blocks are in Chinese. Every block below comes with its English meaning, so you can match it with what you see on screen. The website is free and needs no login; the hub needs Pybricks firmware (the website's "SPIKE 主機" (SPIKE hub) menu can install it for you). On the website the Ranger 8-Way is called "八方位雷射" (8-direction laser).

1

Setup: which port the Ranger is on

The first thing in the program is a "○ 埠 接 MBC 八方位雷射" (port ○ has the MBC 8-direction laser) block under the yellow "開機時執行一次" (run once at start). Now the website knows that this port has the Ranger 8-Way.

Which port is the sensor plugged into?
  1. Open the MBC SPIKE Blocks website and click "+" to start a new program.
  2. In the block categories on the left, click "MBC 感應器" (MBC sensors) → "八方位雷射" (8-direction laser). The first block is "○ 埠 接 MBC 八方位雷射" (port ○ has the MBC 8-direction laser).
  3. Attach it under "開機時執行一次" (run once at start) and pick C in the drop-down.
2

Add the main loop

The sensor has to be read again and again, so you need the yellow "主迴圈(一直重複)" (main loop, repeats forever). Put a "等待 100 毫秒" (wait 100 ms) block inside it first, so it reads every 0.1 s and not too fast.

  1. From "控制" (Control), drag out "主迴圈(一直重複)" (main loop) and drop it in an empty space under the setup blocks (it does not need to snap on).
  2. Drag a "等待 100 毫秒" (wait 100 ms) block into the main loop.

The website puts the program into multitasking (async) by itself. You do not choose it and you do not write await.

3

Use a reading block

"MBC 感應器 → 八方位雷射" (MBC sensors → 8-direction laser) also has 16 reading blocks. Each one has a port drop-down in the middle; pick the same port as in step 1 (C). Click a function and the blocks and output change to its example.

Simulated sensor (seen from above, robot facing up): drag the obstacle and watch the output on the right

The simulation is only a sketch: direction and distance come from a simple position-based estimate, so a real sensor may differ by a step or two. Red sector = that sensor sees something; grey sector = it reads 120 (nothing that way). Sensors 4 and 5 both face straight ahead.

An example for every reading block

16 reading blocks, each with an example you can copy (port C). The block names are in Chinese with the English meaning after them. Click "Try it" to jump to step 3; the blocks and output on the right change to that example.

Good to know

  1. One setup block is enough, and there is no library to download. Each port can be set up only once. The port in a reading block must match the setup block; if you pick the wrong port, the website warns you before downloading. When the website downloads your program, it sends the 8-direction laser reading code to the hub as well.
  2. Same functions as the Pybricks library: everything in MBC_laser8.py has a block here (ch = "第 N 路距離" (distance of sensor N), is_ok = "第 N 路正常" (sensor N OK), distances = "8 路距離(清單)" (all 8 distances, list)), and the values are the same. Read "感應器身分" (sensor ID) and "感應器韌體版本" (sensor firmware version) once, under "run once at start". The millimetre group (nearest distance in mm, distance straight ahead in mm, nearest direction from the millimetre group), the sensor ID and the firmware version need sensor firmware from 2026-10 or later.
  3. Unplugging does not stop the program: if it cannot read the sensor, it returns the last value and prints one warning line MBC: Port C 讀不到感應器… / no sensor… in the terminal. Plug it back in and it carries on by itself. Use "感應器有接好" (sensor connected) to check the connection. Careful: if the cable comes out while avoiding obstacles, the robot keeps driving on the last distance.
  4. A reading of 120 can mean 4 things: nothing that way, more than 120 cm away, just switched on (wait 2–4 s) or that sensor is faulty. Use "第 N 路正常" (sensor N OK) to spot a faulty one. A faulty sensor always reads 120, so it looks like the "most open direction".
  5. Direction: stand behind the robot and look forward: left is negative, right is positive. Sensor 1 points straight left, sensors 4 and 5 point straight ahead, sensor 8 points straight right. The nearest direction is −7 ~ +7, and ±8 = nothing around (it keeps the side where it last saw something), so check "is anything there?" with "nearest distance ≥ 120".