MBC Pathfinder 8-Way (Line8) × LEGO SPIKE App

Read the Pathfinder in the LEGO SPIKE App in three steps

In the LEGO SPIKE App, the Pathfinder shows up as a Color Sensor. So you do not import a library. You read it with the Color Sensor blocks, then decode the numbers into line position and line width. 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 web version of the LEGO app (spike.legoeducation.com), so they look the same as in the app.

1

Start: when program starts + forever

You read a sensor again and again. First put the yellow "when program starts" block. Attach "forever" under it, and put "wait 0.1 seconds" inside, so it reads every 0.1 s.

  1. Open the LEGO SPIKE App, make a new project and choose "Word Blocks".
  2. From "Events", drag out "when program starts". From "Control", drag "forever" and attach it underneath.
  3. Drag a "wait 1 seconds" block into forever and change the number to 0.1.
2

Meet the three reading blocks, pick the right port

The LEGO app reads the Pathfinder with three Color Sensor blocks. Each block starts with a port drop-down. Pick the port the Pathfinder is plugged into. You must decode the number to get the line position:

Which port is the Pathfinder in?
LEGO blockWhat it gives youDecode
reflected light (in Sensors)line position (rough) + 8the number it returns minus 8 → -8 to 8
color (in Sensors)line width (how many channels are on the line)use it as it is → 0 to 8, 0 = no line
raw red (in the "More Sensors" extension)line position (fine) + 100the number it returns minus 100 → -100 to 100

To use raw red, first press the extension button at the bottom left of the app and add "More Sensors".

3

Store it in a variable and use it

In "Variables", make a new variable (for example "line position"). Use "set … to …" to store the decoded value in it. This gives the value a name. After that, use the variable to show or check the value. Click a function, and the blocks and result change to its example.

Sensor simulator (looking from behind the robot): drag the black line and watch the result on the right

The simulator is only a picture. The maths is simpler than the real thing, so a real sensor may be off by a channel or two. Light value 0 = black, 100 = white. A red ring = that channel sees the line.

Block examples for every function

Every function the LEGO app can read has a set of blocks you can copy (port C). Press "Try it" to jump to step 3.

What the LEGO app cannot read: the LEGO app only reads the sensor's "combined data". So it cannot read the Pathfinder's line segments, light value of each channel, which channels are on the line, sensor ID, firmware version or sensor is connected. To use these, switch to the MBC SPIKE Blocks website or Pybricks (the hub needs Pybricks firmware).

Good to know

  1. In the LEGO app, use the "Color Sensor" blocks. To the LEGO app, the Pathfinder is just a Color Sensor. You do not need to install anything.
  2. Always decode. Reflected light minus 8 and raw red minus 100 give the line position. If you forget, the number is always positive.
  3. Use line width to check for a line. Line width = 0 means no line. When the line leaves completely, the line position stays at the side where it left (-8 / 8).
  4. Crossing: line width 6 or more (the whole row sees the line).
  5. Direction: stand behind the robot and look forward. Line on the left = negative, line on the right = positive. Channel 1 is on the far left.