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

Interactive tutorialSPIKE

First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.

This page covers Official LEGO App (SPIKE 3, Robot Inventor) only: how to set it up for the Pathfinder 8-Way (Line8) on SPIKE Prime / Robot Inventor, how to read every value, the commands it supports and examples. Use the switcher above to change product, host or software.

Setup

What you need

  • Sensor: Pathfinder 8-Way (Line8) (SPIKE edition). Each platform is a different factory edition; an EV3 edition is not recognised on a SPIKE hub.
  • Hub: SPIKE Prime (Education, yellow hub) or Robot Inventor (home edition, teal hub).
  • Cable: the standard cable in the box, or an original LEGO cable.
  • Software: Education uses the LEGO Education SPIKE App (the examples on this site use SPIKE 3); the home edition uses the LEGO MINDSTORMS Robot Inventor App.
  • Hub firmware: the original LEGO firmware. No need to switch to Pybricks.

Install the software

  1. Education: install the SPIKE App from the LEGO Education download page.
  2. Home edition: install the LEGO MINDSTORMS Robot Inventor App.
  3. If the hub has been flashed with Pybricks, switch it back to the original LEGO firmware with the SPIKE App first, or the official App cannot connect.

Note

The Education and home editions read values differently: in the home-edition App some blocks are limited to 0 ~ 126, and "Color" only goes up to 10. Use the readings for the edition you have.

Make the software see the sensor

No extension and no driver needed. Plug the sensor into the hub and the official App treats it as an original LEGO sensor (for most products a SPIKE Color Sensor); just use that sensor's blocks.

  • An official block returns one number at a time, so the product data is encoded into the "Color", "Reflected light" and "Raw red / green / blue" slots. See the readings below for what each slot means.
  • To open an example: download the .llsp3 (home edition: .lms) → open the App → top-left "File" → "Open" → pick the file.

Wiring

  1. Plug the sensor into hub port C with the cable (any of A~F works; choose the same port in your program).
  2. The plug only goes in one way: latch up, push it in gently, do not force it.
  3. When the hub is on, the light on the sensor comes on.

Calibrate first (only once)

The Pathfinder has to "learn" the black and white of your mat before its numbers are right. Calibration is stored in the sensor and survives power-off (until you change mats).

  1. Plug in the sensor and turn the hub on (the sensor lights come on).
  2. Hold the calibration button for about 0.5 s, then release it (do not keep holding it; holding it keeps restarting calibration).
  3. When the green calibration LED (next to the button) lights up, sweep the sensor back and forth between the black line and the white floor within 5 seconds. All 8 sensing points must pass over the darkest black line and the brightest white area.
  4. Keep the sensor 3~12 mm above the surface while sweeping; higher reads poorly.
  5. The green LED goes off = calibration done, saved in the sensor automatically.

How do I know it worked? On the white floor the "line width" is 0; on a normal black line it is 2~3.

Data channel mapping

In the official App the Pathfinder 8-Way appears as a SPIKE Color Sensor, with the 8-channel data packed into the colour sensor channels. The Education and home editions map differently; use the table for yours.

Education (LEGO Education SPIKE App, SPIKE 3)

Official block Data Range and decoding
Color Line width 0 ~ 8: number of sensors on the line. A normal black line is usually 2 ~ 3; a crossing or a large colour patch makes it much larger, useful for detecting junctions
Reflected Light Standard position 0 ~ 16: 8 centre, 0 far left, 16 far right. Subtract 8 for the line position (negative = line on the left, positive = right); good for PID
Red High-resolution smooth position 0 ~ 200: 100 centre. Subtract 100 for the high-precision position (negative = left); needs a proper calibration
Green First 4 sensor values 0 ~ 65535: 4 bits per sensor, each 0 ~ 15
Blue Last 4 sensor values 0 ~ 65535: 4 bits per sensor, each 0 ~ 15

Home edition (LEGO MINDSTORMS Robot Inventor App)

In the home-edition App some single-channel blocks are limited to 0 ~ 126, so the position and reflected-light data are moved to the RGB and reflected-light channels to get around that limit:

Official block Data Range and decoding
Color Line width 0 ~ 8 (the home edition caps colour at 10); often used to detect crossings
Reflected Light Standard position 0 ~ 16: subtract 8 for the line position, not affected by the 126 limit
Red High-resolution smooth position 0 ~ 200: subtract 100 for the high-precision position; nothing lost on the home edition
Green First 4 sensor values 0 ~ 255: 2 bits per sensor, each 0 ~ 3
Blue Last 4 sensor values 0 ~ 255: 2 bits per sensor, each 0 ~ 3

Example programs

Pathfinder 8-Way PID line following in the SPIKE App

Pathfinder 8-Way PID line following in the Robot Inventor App

PD line-following demos (speed 50)

The same PD logic as the Pybricks version, as blocks and Python for both the Education and the Robot Inventor app: 4 programs, all run on a hub (tested: Education SPIKE App 3 blocks and Python, 2026-10-29 to 30; Robot Inventor App 10.5.4 blocks and Python, 2026-10-29 to 30).

  • Education (SPIKE App 3): blocks .llsp3 · Python (helper built in)

  • Robot Inventor App: blocks .lms · Python (helper built in)

  • Download all (with the Pybricks versions)

  • Wiring: sensor on port C, left motor on E, right motor on F. The motors face opposite ways, so the left motor needs negative power to drive forward: left = −(speed + PD), right = speed − PD.

  • Reading: fine position = "raw red" − 100 (both apps). Width: blocks (Education and Robot Inventor alike) use the "color" block; only Robot Inventor Python uses reflected light get_reflected_light().

  • Speed 50 (power %), KP 0.4 and KD 1.5 are starting values; stop at a crossing: width > 5.

  • Works with older firmware too: the official apps read mode 0, which the mode 7 change does not touch.

  • When you paste Python into the SPIKE App 3 editor, it shortens the spaces before end-of-line # comments. That is just the editor's formatting; the program is unchanged.

Robot Inventor App Python

Warning

LEGO ended support for the Robot Inventor App on 2026-10-01. This section is only for people who still have a Robot Inventor hub; for new projects use SPIKE App 3 or Pybricks.

  • Reading (measured on hardware): fine position = get_rgb_intensity()[0] − 100, width = get_reflected_light(). get_color() only names a few positions, so it is not a position; coarse position and per-channel readings are not available in this app.
  • Helper: MBC_line8_ri_App_helper.py (class Line8RI: pos100(), width()); paste the whole file at the top of your program.
  • Example: ex01_line_follow.py (helper already included): line following + stop at a crossing, wiring C / E / F, run on a 51515 hub (App 10.5.4).

Want to learn more advanced line following?

These coaches have plenty of competition and teaching experience: Coach LegoLauXiao (demo video), Coach legolaumo (demo video).

First test

  1. Connect the hub to the App over USB or Bluetooth.
  2. Open example 1 on this page and press Run.
  3. Move your hand or the mat in front of the sensor: if the number changes, everything is connected.

FAQ

  • Nothing happens when I plug it in? Check in order: both ends of the cable firmly in → another hub port → another cable → another hub.
  • Different Apps give different numbers? The Education (yellow hub) and home (teal hub) editions use different formats. Check which edition you have and use its readings.
  • Do I need an adapter or a driver? No. The connector and protocol are the same as a LEGO hub port; it is recognised automatically.
  • Example 6 won't open in the official App? Examples marked "Pybricks only" use a new mode in firmware from 2026-10 on, which the official App blocks cannot read.

Reading values

The official app shows the sensor as a Color Sensor. Read it with the color, reflected light and raw red / green / blue blocks under More Sensors, then decode as shown.

line position linePos

line position
Range Meaning
-8~+8 which channel the line is under: −8 (far left) to +8 (far right), 0 = centre; seen from behind the robot, negative = left
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime line position 「reflected light」 the number it returns, minus 8
Robot Inventor line position 「reflected light」 the number it returns, minus 8

fine position linePosFine

fine position
Range Meaning
-100~+100 sub-channel position: −100 to +100, 0 = centre, negative = left (same sign as line position)
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime fine position 「raw red」 the number it returns, minus 100

line width lineWidth

line width
Range Meaning
0~8 路 number of channels on the line, 0~8; 0 = no line
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime line width 「color」 the number it returns
Robot Inventor line width 「color」 the number it returns

channel 1~8 reflect light

channel 1~8 reflect
Range Meaning
0~100 calibrated reflect of channel 18, 0100 (channel 1 = left); ids 10~17
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime channel 1~8 reflect 「raw green」 each number packs 4 channels of 4 bits

Firmware note: 4-bit (v×10)>>6

Not readable here:line segments, line bitmap, last exit direction, threshold, calibrations done. Use MBC Blocks website / Pybricks for these.

Commands

This software cannot send commands (neither the official SPIKE App 3 nor Pybricks' built-in ColorSensor blocks can). To send commands use Pybricks + the MBC library; you can also calibrate with the button on the sensor.

Examples

Example 1: See the black line

What this example does: the hub display keeps showing the line position (-8 to 8). Slowly move the black line from left to right and the number goes from negative to positive.

What you need

  • 1 SPIKE hub
  • 1 Pathfinder 8-Way (calibrated)
  • A sheet of white paper with a black line drawn on it (or a competition mat)

How to connect: Pathfinder on port C.

Download the program

Official LEGO App
ex01_show_position.llsp3
🟨 Blocks in the official LEGO App

Example 1 official App blocks

Step by step through the program

  1. Repeat forever: the blocks inside keep running until you press stop.
  2. Read the line position: in the official App it is "reflected light minus 8"; the MBC Blocks website and Pybricks have "line position (-8~8)" directly.
  3. Show it on the display: the official App uses the "write" block, the MBC Blocks website uses "show number on display", and Pybricks uses hub.display.number().
  4. Wait 0.2 seconds: lets the number sit still long enough for your eyes to read it.

What you should see

  • Line right under the sensor: the display shows 0 (-1 and 1 count as center too).
  • Move the black line to the left: the number goes negative, closer to -8 the farther left you go.
  • Move it to the right: it goes positive, closer to 8 the farther right you go.

Common problems

  • The number is stuck at 0 and never changes? → First check whether "line width" is 8 (every point thinks it sees black): that means the sensor is not calibrated yet; go back to "calibrate" above.
  • Left and right are swapped? → The sensor is mounted upside down (the side with the components must face down, toward the floor).
  • The official App shows 8 instead of 0? → You forgot to "subtract 8".

Example 2: Black line alarm

What this example does: when it sees the black line, the hub's center light turns green; when it can't find the line, the light turns red and the hub keeps beeping.

What you need: same as example 1.

How to connect: Pathfinder on port C.

Download the program

Official LEGO App
ex02_line_alarm.llsp3
🟨 Blocks in the official LEGO App

Example 2 official App blocks

Step by step through the program

  1. Read the line width: in the official App use the "color" block; what it returns is the line width.
  2. If line width > 0 then…: at least one sensor point is on the black line → green light.
  3. Else…: line width is 0, meaning not a single point is on the line → red light and a beep.
  4. Wait 0.1 seconds, then check again.

What you should see

  • Sensor on the black line: green light.
  • Move it onto the white floor: red light + nonstop beeping.

Common problems

  • Always green, even on white paper? → Not calibrated yet (every point is being read as black).
  • How do I pick the light color in the official App? → Click the color dot on the "set Power Button light to" block to change it.

Example 3: Which side is the line on

What this example does: the hub display uses an arrow to tell you where the line is: line on the left → ⬅, line on the right → ➡, in the center → ⬆, no line found → ✕.

What you need: same as example 1.

How to connect: Pathfinder on port C.

Download the program

Official LEGO App
ex03_which_side.llsp3
🟨 Blocks in the official LEGO App

Example 3 official App blocks

Step by step through the program

  1. First read the line position and line width and store them in two "variables" (a variable = a box with a name that can hold one number).
  2. If line width = 0 → show ✕ (no line found; the line position is not reliable right now, so this check comes first).
  3. Else, if line position < -1 → show the left arrow.
  4. Else, if line position > 1 → show the right arrow.
  5. Otherwise (-1, 0, 1) → show the up arrow, meaning the line is in the center.

What you should see: slowly move the line from left to right and the arrow changes ⬅ → ⬆ → ➡; lift the sensor off the line and it becomes ✕.

Common problems

  • Why is the center -1 to 1 instead of just 0? → The line has some width, so being slightly off still counts as center; otherwise the arrow would flicker back and forth all the time.
  • How do I change the picture in the official App? → Click the little grid image on the "turn on" block and light up whichever pixels you want.

Example 4: The simplest line following

What this example does: the robot follows the black line on its own. Line on the left → turn left; line on the right → turn right; line in the center → go straight.

What you need

  • Everything from example 1, plus
  • A two-wheel robot car (two motors as wheels)
  • A closed loop of black line (about 2 cm wide, no sharp turns)

How to connect

  • Pathfinder on port C, mounted at the front of the car, about 0.5 to 1 cm above the floor
  • Left wheel motor on E, right wheel motor on F

Download the program

Official LEGO App
ex04_simple_follow.llsp3
🟨 Blocks in the official LEGO App

Example 4 official App blocks

Step by step through the program

  1. Tell the hub where the wheels are: in the official App it is "set movement motors to E+F"; on the MBC Blocks website and in Pybricks it is "drive base: left wheel E, right wheel F".
  2. Set the speed: 30% in the official App; 100 mm per second in the other two. Start slow, and speed up once it works.
  3. Repeat forever: read the line position.
  4. If line position < -1 (line on the left) → turn left while driving.
  5. Else if line position > 1 (line on the right) → turn right.
  6. Else → go straight.

What you should see: the car follows the line, wobbling left and right as it goes (that is normal; example 5 improves it).

Common problems

  • It shoots off right away and gets farther and farther from the line? → The turn directions are reversed: swap the sign of the two turn numbers (official App: swap -40 and 40; the other two: swap -60 and 60).
  • The car drives backward? → The motors are mounted the opposite way from LEGO's standard car. Official App: mount the motors the same way as LEGO's "Driving Base" model; MBC Blocks website: in the "drive base" block, flip the "forward" direction of both the left and right wheels; Pybricks: change the left wheel to Direction.CLOCKWISE and the right wheel to Motor(Port.F, Direction.COUNTERCLOCKWISE).
  • It overshoots and runs off on sharp turns? → Lower the speed.

Example 5: Smooth line following + stop at the crossroads

What this example does: follows the line using "turn as much as you are off the line", which is smoother than example 4; when it reaches a crossroads (the whole row of sensor points is on black), it stops and beeps.

What you need: same as example 4, and the black line needs one crossroads.

How to connect: Pathfinder on port C; left wheel motor on E, right wheel motor on F.

Download the program

Official LEGO App
ex05_smooth_follow_stop.llsp3
🟨 Blocks in the official LEGO App

Example 5 official App blocks

Step by step through the program

  1. Read the fine line position (-100 to 100): in the official App it is "raw red minus 100".
  2. Read the line width.
  3. If line width ≥ 6 (the official App writes it as "line width > 5", same meaning) → crossroads: stop → beep → end the program.
  4. Else → turn amount = line position × a number (0.5 in the official App, 1.5 in the other two). The farther off the line, the harder it turns; slightly off means only a slight turn, so it doesn't wobble left and right.

What you should see: the car glides smoothly along the line and stops with a beep at the crossroads.

Common problems

  • Still wobbling left and right? → Make "the multiplier" a bit smaller (for example 0.5 → 0.3).
  • Can't keep up on turns and runs off the line? → Make "the multiplier" a bit bigger, or lower the speed.
  • Stops before reaching the crossroads? → The line is too wide or the sensor is too close to the floor; change "6" to 7.
  • Can't find the "raw red" block in the official App? → Opening the file should automatically add the "More Sensors" block category; if it is missing, click the "+" at the bottom-left of the block palette and add "More Sensors".

More questions

  • The hub does not detect the sensor? Unplug and replug, wait 2 s, try another port. The official app shows it as a colour sensor — that is expected.
  • Can I use the official app and Pybricks on the same hub? One firmware at a time: Pybricks and the MBC Blocks website need Pybricks firmware, the official app needs LEGO firmware; you can switch back any time with the SPIKE app.

Still stuck? Contact us with your software and a screenshot of the program.

Downloads

Sources

  • Host and software list:_build/guides.json
  • Values and commands:_build/protocol/line8.json (single source of truth)
  • Setup:_build/guides/software/spike-official.en.md、_build/guides/product/line8/spike-official.en.md
  • Examples:sensors/line8/spike-examples.md
Email for a quoteBuying Guide