Pathfinder 16-Way (Line16) × 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 16-Way (Line16) 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 16-Way (Line16) (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 16 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 3~5.

Data channel mapping

In the official App the Pathfinder 16-Way appears as a SPIKE Color Sensor, with the 16-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 ~ 16: number of sensors on the line. A normal black line is usually 3 ~ 5; a crossing or a large colour patch makes it much larger, useful for detecting junctions
Reflected Light Standard position 0 ~ 32: 16 centre, 0 far left, 32 far right. Subtract 16 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 8 sensor values 0 ~ 65535: 2 bits per sensor, each 0 ~ 3
Blue Last 8 sensor values 0 ~ 65535: 2 bits per sensor, each 0 ~ 3

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 ~ 10: the home edition caps colour at 10, so the width is limited to 0 ~ 10; often used to detect crossings
Reflected Light Standard position 0 ~ 32: subtract 16 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 8 sensor values 0 ~ 255: 1 bit per sensor, each 0 ~ 1
Blue Last 8 sensor values 0 ~ 255: 1 bit per sensor, each 0 ~ 1

Example programs

Pathfinder 16-Way PID line following in the SPIKE App

Pathfinder 16-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. Tested on a hub (2026-10-29 to 30): Education SPIKE App 3 Python (reads width 16 at a crossing and stops), Robot Inventor App 10.5.4 blocks and Python.

Warning

The Education blocks .llsp3 is waiting for a re-test: on 2026-10-29 it only partly passed: it did not stop at the crossing, the dashboard readings lagged one step, and "color" showed NaN once the width went above 10. To stop at crossings, use the Education Python for now.

  • Education (SPIKE App 3): blocks .llsp3 (re-test pending) · 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: Education width > 10; Robot Inventor blocks > 9 (its "color" tops out at 10); Robot Inventor Python > 10.

  • 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_line16_ri_App_helper.py (class Line16RI: 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
-16~+16 which channel the line is under: −16 (far left) to +16 (far right), 0 = centre; seen from behind the robot, negative = left (normally ±15; ±16 only for 200 ms after the line leaves the outermost channel)
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime line position 「reflected light」 the number it returns, minus 16
Robot Inventor line position 「reflected light」 the number it returns, minus 16

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
Robot Inventor fine position 「raw red」 the number mod 256, minus 100 (Robot Inventor look-up encoding, see setup above)

Firmware note: byte2 = 細位置+100(0~200)、byte3 = 0;App 原始紅讀成 int16; 細位置+100 經玩具版查表編碼成 byte2~3

line width lineWidth

line width
Range Meaning
0~16 路 number of channels on the line, 0~16; 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

Firmware note: min(線寬, 10)

channel 1~16 reflect light

channel 1~16 reflect
Range Meaning
0~100 calibrated reflect of channel 116, 0100 (channel 1 = left); ids 10~1F
Hub Value Block (More Sensors → Color Sensor) Decode
SPIKE Prime channel 1~16 reflect 「raw green」 the number it returns
Robot Inventor channel 1~16 reflect 「raw green」 the number mod 256 (Robot Inventor look-up encoding, see setup above)

Firmware note: 每路 2 bit((v×10)>>8:0~25→0、26~51→1、52~76→2、77~100→3);byte4 = 第 5~8 路(第 5 路在 bit7-6)、byte5 = 第 1~4 路、byte6 = 第 13~16 路、byte7 = 第 9~12 路 → App 原始綠 = 第 1~8 路(bit15-14 = 第 1 路)、原始藍 = 第 9~16 路;byte 8~15 = 0; 每路 1 bit(光值 ≥ 門檻(值 07,預設 40)= 1 亮,跟二值化判白同一個判斷;2026-11-03 以前的韌體是光值 > 50):第 1~8 路合成 1 byte(第 1 路在 bit7)經玩具版查表編碼成 byte4~5;第 9~16 路 → byte6~7

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 (-16 to 16). 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 16-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 16"; the MBC Blocks website and Pybricks have "line position (-16~16)" 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 around 0 (-2 to 2 all count as center).
  • Move the black line to the left: the number goes negative, closer to -16 the farther left you go.
  • Move it to the right: it goes positive, closer to 16 the farther right you go.

Common problems

  • The number is stuck at 0 and never changes? → Run example 2 first: if the light is still green on white paper, every point thinks it sees black, meaning the sensor is not calibrated yet; go back to "calibrate" above.
  • Left and right are swapped? → First make sure the sensor is not mounted upside down (the side with the components must face down, toward the floor). If it is mounted correctly and still reversed, swap the sign of the "turn left" and "turn right" numbers in the later examples.
  • The official App shows 16 instead of 0? → You forgot to "subtract 16".

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…: any of the 16 sensor points 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 junction on (16-Way only)

What this example does: the 16-Way's sensor points are spread wide and packed densely, so at a junction it can tell "where the big black patch is". The hub display tells you:

  • A normal line → ⬆
  • A branch on the left (T-junction going left) → ⬅
  • A branch on the right (T-junction going right) → ➡
  • A crossroads → +
  • No line found → ✕

What you need: same as example 1, plus three kinds of junction drawn with black tape or a marker: a "T going left", a "T going right", and a "crossroads".

How to connect: Pathfinder on port C.

Download the program

Official LEGO App
ex03_junction_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 width < 6 → just a narrow strip, a normal line → show ⬆.
  4. Else (line width 6 or more = the black got much wider, so you are at a junction), look at the "line position", which is the center of that black patch:
    • line position < -3: the black is off to the left → branch on the left → ⬅
    • line position > 3: the black is off to the right → branch on the right → ➡
    • Neither: the black is dead center, equally wide on both sides → crossroads → +

What you should see: slowly push the sensor across the three junctions. Passing a T going left flashes ⬅ for a moment, a T going right flashes ➡, a crossroads flashes +, and the rest of the time it shows ⬆.

Common problems

  • Always ⬆, junctions are never recognized? → Push it more slowly; or the branch line is too thin, so change "6" to 5.
  • Normal curves get treated as junctions? → The line is too wide; change "6" to 7.
  • Why is there no "+" symbol in the official App? → The official App uses a hand-drawn 5×5 picture (one horizontal and one vertical bar through the middle); the MBC Blocks website and Pybricks show the "+" character directly.
  • 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 < -2 (line on the left) → turn left while driving.
  5. Else if line position > 2 (line on the right) → turn right.
  6. Else (-2 to 2) → 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.
  • Why is the center -2 to 2? → The 16-Way has finer steps, so the number moves as soon as the line is slightly off; leaving a little margin keeps the car from twitching back and forth all the time.

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 (nearly the whole row of sensor points is on black), it stops and beeps. It does not stop at T-junctions; it keeps driving straight through.

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 ≥ 11 (the official App writes it as "line width > 10", 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, drives through T-junctions without stopping, 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.
  • Didn't stop at the crossroads? → The car is too fast and shot straight through it; lower the speed, or change "11" to 10.
  • Stopped at a T-junction before reaching the crossroads? → The line is too wide; change "11" to 12 or 13 (the maximum is 16).
  • The official App version never stops at the crossroads? → In our 2026-10 hub tests, the Education SPIKE App 3 dashboard showed NaN for the "color" block once the width went above 10, and we are still re-testing the 16-way crossroads stop in blocks (on the same hub, the official App's Python reads width 16 and stops). In the home edition (Robot Inventor) "color" tops out at 10, so always use "> 9" there. Swap example 1's "reflected light minus 16" for "color", put the sensor on the crossroads and watch the number on the display; if it only goes up to 10, change example 5's "> 10" to "> 9".
  • 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/line16.json (single source of truth)
  • Setup:_build/guides/software/spike-official.en.md、_build/guides/product/line16/spike-official.en.md
  • Examples:sensors/line16/spike-examples.md
Email for a quoteBuying Guide