Pathfinder 16-Way (Line16) × EV3 × clev3r
Interactive tutorialEV3
First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.
This page covers clev3r (EV3 BASIC) only: how to set it up for the Pathfinder 16-Way (Line16) on MINDSTORMS EV3, 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) (EV3 edition, RJ12 plug).
- Brick: LEGO MINDSTORMS EV3.
- Software: clev3r (a BASIC programming environment for the EV3, also called EV3 Basic). The version tested for this site is v1.7.1.0. Pick this if you already use clev3r.
Install the software
- Install clev3r (v1.7.1.0 recommended).
- To open an example: open the
.bpfile in clev3r → "Compile and download" → run it from the folder starting withMBC_in the EV3 file browser.
Make the software see the sensor
No extension needed. On the EV3 the sensor emulates an original LEGO sensor (most products are an "Infrared Sensor"), with exactly the same modes as the official EV3 software: Proximity / Beacon / Remote, with the same ranges.
- Read them with BASIC commands such as
IR_PROXIMITY/IR_BEACON/IR_REMOTE. See the readings below. - clev3r can also read modes that EV3-G and Classroom cannot, so examples marked "Pybricks / EV3 MicroPython / clev3r only" run here too.
- Some products come with MBC subroutines. They are already inside the example files.
Important
Do not switch modes in the middle of a program. Every time the EV3 switches a sensor mode it stalls (about 1 s). Pick one mode at the start and use it for the whole run.
Wiring
- Plug the sensor into EV3 port 1 with the cable (any of 1~4 works; use the same port in the program).
- Turn the EV3 on first, then plug in the sensor.
- Latch up, push the plug in gently.
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).
- Plug in the sensor and turn the hub on (the sensor lights come on).
- Hold the calibration button for about 0.5 s, then release it (do not keep holding it; holding it keeps restarting calibration).
- 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.
- Keep the sensor 3~12 mm above the surface while sweeping; higher reads poorly.
- 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.
Proximity mode: line position
| Value | Range | Meaning |
|---|---|---|
| Line position | -16 ~ +16 |
0 = black line in the centre, negative left, positive right; ±16 = line at the very edge |
Beacon mode: 16 reflected-light values
Read the "value list" (8 bytes). Each channel is quantised to 19 (1 = darkest, 9 = brightest) and two channels are combined into one two-digit number (1199), getting around the EV3 limit of 100.
| Byte | Content | Range | Decoding |
|---|---|---|---|
| 0 | Channels 0+1 | 11 ~ 99 | tens = channel 0, units = channel 1 |
| 1 | Channels 2+3 | 11 ~ 99 | tens = channel 2, units = channel 3 |
| 2 | Channels 4+5 | 11 ~ 99 | tens = channel 4, units = channel 5 |
| 3 | Channels 6+7 | 11 ~ 99 | tens = channel 6, units = channel 7 |
| 4 | Channels 8+9 | 11 ~ 99 | tens = channel 8, units = channel 9 |
| 5 | Channels 10+11 | 11 ~ 99 | tens = channel 10, units = channel 11 |
| 6 | Channels 12+13 | 11 ~ 99 | tens = channel 12, units = channel 13 |
| 7 | Channels 14+15 | 11 ~ 99 | tens = channel 14, units = channel 15 |
Example: a byte reads 83; the tens digit 8 is the even channel (e.g. channel 0), the units digit 3 is the odd channel (e.g. channel 1).
Remote mode: position + width + edges (recommended for competition)
Read the "value list" (4 bytes):
| Byte | Content | Range | Meaning |
|---|---|---|---|
| 0 | High-resolution position | -100 ~ +100 |
0 centre, negative left, positive right; the best PID error input |
| 1 | Line width | 0 ~ 16 |
Sensors triggered; detects crossings and T-junctions |
| 2 | Left edge light | 0 ~ 100 |
Reflection of channel 1 (far left), 0 pure black, 100 pure white |
| 3 | Right edge light | 0 ~ 100 |
Reflection of channel 16 (far right), 0 pure black, 100 pure white |
Tip
When bytes 2 and 3 are both below 20, the front of the robot is fully on the cross line of a junction; a sudden change on one side means a fork is coming. Useful to avoid losing the line.
MBC subroutines
The example file contains three subroutines; no extension pack to install. Put them inside an endless loop to always have the latest data:
LinePos16_dataUpdate: give theport, returnspos16(-16 ~ +16, left negative, right positive).LinePos100_dataUpdate: give theport, returnspos100(-100 ~ +100, needs a proper calibration),width(0 ~ 16), andch1/ch16(far-left / far-right light0 ~ 100).LineCh16_dataUpdate: give theport, returns the arraylight16;light16[0]~light16[15]are each sensor's quantised light1 ~ 9(1 darkest, 9 brightest).
Example program
- clev3r example (.bp): open with clev3r.

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
- Open the
.bpof example 1 on this page and press "Compile and download". - Run it from the folder starting with
MBC_in the EV3 file browser. - If the number on the EV3 screen changes with what is in front of the sensor, everything is connected.
FAQ
- Cannot find the program on the EV3? Look in the EV3 file browser for the folder starting with
MBC_. - The number never changes? Unplug the sensor and plug it back in (the EV3 must be on first).
- The program hiccups now and then? It switches sensor modes. Use one mode only.
Reading values
Code assumes port 1: Sensor.SetMode picks the mode, Sensor.ReadRawValue reads the n-th value.
line position linePos
| 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) |
' clev3r (BASIC)
Sensor.SetMode(1, 0)
linePos = Sensor.ReadRawValue(1, 0)mode 0 · int8 · IR-PROX(F16:739-741) (locked mode: firmware and hosts will not change it)
fine position linePosFine
| Range | Meaning |
|---|---|
-100~+100 |
sub-channel position: −100 to +100, 0 = centre, negative = left (same sign as line position) |
' clev3r (BASIC)
Sensor.SetMode(1, 2)
linePosFine = Sensor.ReadRawValue(1, 0)
Sensor.SetMode(1, 4)
linePosFine = Sensor.ReadRawValue(1, 0)mode 2 · int8 · IR-REMOTE byte0 = highRes−100 存成 int8(F16:745-751); mode 4 · int8 · #67 新:IR-S-ALT 內容同模式 2(原本不送) (locked mode: firmware and hosts will not change it)
line width lineWidth
| Range | Meaning |
|---|---|
0~16 路 |
number of channels on the line, 0~16; 0 = no line |
' clev3r (BASIC)
Sensor.SetMode(1, 2)
lineWidth = Sensor.ReadRawValue(1, 1)
Sensor.SetMode(1, 4)
lineWidth = Sensor.ReadRawValue(1, 1)mode 2 · int8; mode 4 · int8 · #67 新:同模式 2 (locked mode: firmware and hosts will not change it)
line bitmap bitmap
| Range | Meaning |
|---|---|
0~65535 bit |
bit0 = channel 1 (left) … bit15 = channel 16; 1 = that channel sees the line |
' clev3r (BASIC)
Sensor.SetMode(1, 3)
bitmap = Sensor.ReadRawValue(1, 0)mode 3 · int16 · #67 新:IR-REM-A 1×int16 = 16 bit 位元圖(原本不送)
channel 1~16 reflect light
| Range | Meaning |
|---|---|
0~100 |
calibrated reflect of channel 1 |
' clev3r (BASIC)
Sensor.SetMode(1, 1)
light1 = Sensor.ReadRawValue(1, 0) ' first; for the N-th use 0 + N - 1
Sensor.SetMode(1, 2)
light1 = Sensor.ReadRawValue(1, 2) ' first; for the N-th use 2 + N - 1
Sensor.SetMode(1, 4)
light1 = Sensor.ReadRawValue(1, 2) ' first; for the N-th use 2 + N - 1mode 1 · int8 · IR-SEEK 8×int8 兩路壓一 byte:byte i = convert9(第 2i+1 路)×10 + convert9(第 2i+2 路)(11~99;convert9:0~11→1、12~22→2 … 89~100→9,F16:716-723); mode 2 · int8 · index 2 = 第 1 路、index 3 = 第 16 路(0~100); mode 4 · int8 · #67 新:同模式 2 (locked mode: firmware and hosts will not change it)
Not readable here:line segments, last exit direction, threshold, calibrations done. Use Arduino / mBlock / micro:bit for these.
Commands
The EV3 port is read-only, so this software cannot send commands: calibrate with the button on the sensor and change settings over Arduino I2C, mBlock or micro:bit.
Examples
Example 1: See where the line is
What this example does: Put the sensor over the black line and the EV3 screen shows a number telling you where the line is. This is step one of every line-following program: learn to "read the number".
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- Pathfinder 16-way (EV3 edition, RJ12 plug)
- A white mat with a black line (about 2 cm wide)
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 01:看看線在哪裡
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:把感應器放在黑線上,EV3 螢幕會顯示一個數字告訴你線在哪裡。這是所有循線程式的第一步:先學會「讀數字」。
' 讀值:pos=線的位置(-16 ~ +16,0=線在正中間)
' ============================================================
folder "prjs" "MBC_line16_ex01"
' 循行者 16 路插 1 號孔,使用模式 0
Sensor.SetMode(1, 0)
LCD.Clear()
' 先把螢幕清乾淨
LCD.Clear()
' 下面的動作一直重複
While "True"
' 讀取線的位置,顯示在螢幕第 1 行
LCD.Text(1, 0, 0, 1, "POS " + Sensor.ReadRawValue(1, 0) + " ")
' 等 0.1 秒再讀下一次,數字才不會閃太快
Program.Delay(100)
EndWhileStep by step:
- Clear the screen first
- Repeat the steps below forever
- Read the line position and show it on screen row 1
- Wait 0.1 s before the next read so the number does not flicker
What you should see: With the black line in the middle of the sensor the screen shows 0; move the line left and the number goes negative, move it right and it goes positive, up to ±16 at the edges (left/right as seen standing behind the robot, facing forward).
FAQ:
- The line is gone but the number stays at the last value? That is normal: when the line leaves the sensor, the position stays where it was last seen. To detect "line lost", use the line width from example 4 (width = 0).
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
- The robot steers the wrong way and gets worse? Swap the "+" and "−" in the program (swap the left/right wheel corrections), or check that the left wheel is on B and the right wheel on C.
Example 2: Three-way line following: left, right, straight
What this example does: Use "if … then … else" to make the robot follow the black line: turn left when the line is to the left, turn right when it is to the right, go straight when it is in the middle.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- Pathfinder 16-way (EV3 edition, RJ12 plug)
- A white mat with a black line (about 2 cm wide)
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 02:三段式循線:偏左、偏右、直走
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:用「如果…就…否則…」讓車子沿著黑線走:線偏左就往左轉,線偏右就往右轉,在中間就直走。
' 讀值:pos=線的位置(-16 ~ +16,0=線在正中間)
' ============================================================
folder "prjs" "MBC_line16_ex02"
' 循行者 16 路插 1 號孔,使用模式 0
Sensor.SetMode(1, 0)
LCD.Clear()
' 一直重複檢查線的位置
While "True"
' 如果線的位置小於 -4(偏左)
If Sensor.ReadRawValue(1, 0) < (-4) Then
' 線偏左:左輪慢、右輪快,車子往左修
Motor.StartPower("B", 10)
Motor.StartPower("C", 40)
' 否則,如果線的位置大於 4(偏右)
ElseIf Sensor.ReadRawValue(1, 0) > 4 Then
' 線偏右:左輪快、右輪慢,車子往右修
Motor.StartPower("B", 40)
Motor.StartPower("C", 10)
Else
' 線在中間:兩輪一樣快,直直走
Motor.StartPower("B", 30)
Motor.StartPower("C", 30)
EndIf
EndWhileStep by step:
- Keep checking the line position
- If the line position is less than -4 (line is to the left)
- Line to the left: left wheel slow, right wheel fast, the robot steers left
- Otherwise:
- Otherwise, if the line position is greater than 4 (line is to the right)
- Line to the right: left wheel fast, right wheel slow, the robot steers right
- Otherwise:
- Line in the centre: both wheels the same speed, go straight
- Otherwise, if the line position is greater than 4 (line is to the right)
- If the line position is less than -4 (line is to the left)
What you should see: The robot wobbles left and right along the black line. On sharp bends it may run off; try lowering 40 and changing 10 to 0.
FAQ:
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
- The robot steers the wrong way and gets worse? Swap the "+" and "−" in the program (swap the left/right wheel corrections), or check that the left wheel is on B and the right wheel on C.
Example 3: Proportional line following: the further off, the harder it turns
What this example does: Three-way line following keeps wobbling. This example uses "line position × a number" as the steering power: a little off means a little turn, a lot off means a big turn, so the robot drives more smoothly.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- Pathfinder 16-way (EV3 edition, RJ12 plug)
- A white mat with a black line (about 2 cm wide)
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 03:比例循線:偏越多、轉越多
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:三段式循線會一直搖擺。這個範例把「線的位置 × 一個數字」當成轉彎的力量:偏一點就轉一點、偏很多就轉很多,車子會走得更順。
' 讀值:pos=線的位置(-16 ~ +16,0=線在正中間)
' ============================================================
folder "prjs" "MBC_line16_ex03"
' 循行者 16 路插 1 號孔,使用模式 0
Sensor.SetMode(1, 0)
LCD.Clear()
' 一直重複
While "True"
' 轉彎力量 turn = 線的位置 × 2
turn = Sensor.ReadRawValue(1, 0) * 2
' 左輪=30+turn、右輪=30-turn:線偏哪邊,車子就往哪邊修
Motor.StartPower("B", 30 + turn)
Motor.StartPower("C", 30 - turn)
EndWhileStep by step:
- Repeat forever
- Steering power turn = line position × 2
- Left wheel = 30 + turn, right wheel = 30 − turn: the robot steers towards the line
What you should see: The robot follows the black line more smoothly than in example 2. The number 2 is the "proportional gain": too big and it swings left and right, too small and it cannot make the bends. Tune it yourself.
FAQ:
- It keeps swinging even on a straight line? Lower 2 a little (for example 1).
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
- The robot steers the wrong way and gets worse? Swap the "+" and "−" in the program (swap the left/right wheel corrections), or check that the left wheel is on B and the right wheel on C.
Example 4: Stop at a crossing
What this example does: The sensor also tells you "how many channels see the black line" (line width). Normally that is 2~3; at a crossing it suddenly jumps. This example follows the line while watching the width, and stops with a beep when it is 10 or more.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- Pathfinder 16-way (EV3 edition, RJ12 plug)
- A black-line mat with crossings
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 04:碰到十字路口就停車
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:感應器還會告訴你「壓到黑線的格數」(線寬)。平常只有 2~3 格,到十字路口會一下子變很多。這個範例邊循線邊看線寬,大於等於 10 就停車並嗶一聲。
' 讀值:width=線的寬度(壓到黑線的格數)(0 ~ 16,0=看不到線);pos100=線的位置(細)(-100 ~ +100,0=線在正中間)
' ============================================================
folder "prjs" "MBC_line16_ex04"
' 循行者 16 路插 1 號孔,使用模式 2
Sensor.SetMode(1, 2)
LCD.Clear()
' 一直循線,直到線寬大於等於 10(到路口了)
While Sensor.ReadRawValue(1, 1) < 10
' 轉彎力量 turn = 線的位置(-100~100)× 0.3
turn = Sensor.ReadRawValue(1, 0) * 0.3
' 一樣用比例循線往前走,速度放慢到 25
Motor.StartPower("B", 25 + turn)
Motor.StartPower("C", 25 - turn)
EndWhile
' 停車
Motor.Stop("BC", "True")
' 嗶一聲告訴你到了
Speaker.Tone(50, 1000, 100)
Speaker.Wait()Step by step:
- Keep following the line until the line width is 10 or more (reached a crossing)
- Steering power turn = line position (-100~100) × 0.3
- Same proportional line following, slowed down to 25
- Stop
- Beep to tell you it arrived
What you should see: The robot follows the line and stops with a beep when it reaches a crossing.
FAQ:
- It stops before the crossing? Bends can also widen the line; raise 10 a little.
- It does not stop at the crossing? Show the line width the way example 1 does, read the real value at the crossing, then change 10 in the program.
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
- The robot steers the wrong way and gets worse? Swap the "+" and "−" in the program (swap the left/right wheel corrections), or check that the left wheel is on B and the right wheel on C.
Example 5: Count crossings: stop at the 3rd one
What this example does: Competitions often say "drive to the Nth crossing". This example counts crossings with a variable count and uses another variable onCross to remember "am I on a crossing right now", so one crossing is not counted many times.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- Pathfinder 16-way (EV3 edition, RJ12 plug)
- A black-line mat with 3 or more crossings
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 05:數路口:第 3 個路口停車
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:比賽常常要「走到第幾個路口」。這個範例用一個變數 count 數路口,用另一個變數 onCross 記住「現在是不是正壓在路口上」,避免同一個路口被數很多次。
' 讀值:pos100=線的位置(細)(-100 ~ +100,0=線在正中間);width=線的寬度(壓到黑線的格數)(0 ~ 16,0=看不到線)
' ============================================================
folder "prjs" "MBC_line16_ex05"
' 循行者 16 路插 1 號孔,使用模式 2
Sensor.SetMode(1, 2)
LCD.Clear()
' 路口數 count 從 0 開始
count = 0
' onCross=0 代表「現在不在路口上」
onCross = 0
' 一直循線,直到數滿 3 個路口
While count < 3
' 比例循線:turn = 線的位置 × 0.3
turn = Sensor.ReadRawValue(1, 0) * 0.3
' 左輪=25+turn、右輪=25-turn
Motor.StartPower("B", 25 + turn)
Motor.StartPower("C", 25 - turn)
' 如果線寬大於等於 10(壓在路口上)
If Sensor.ReadRawValue(1, 1) >= 10 Then
' 而且剛剛還不在路口上
If onCross = 0 Then
' 剛壓到新路口:count 加 1
count = count + 1
' 記住「正在路口上」,同一個路口不要再數
onCross = 1
' 嗶一聲
Speaker.Tone(50, 1000, 100)
Speaker.Wait()
EndIf
Else
' 離開路口了:onCross 改回 0,準備數下一個
onCross = 0
EndIf
' 螢幕顯示已經數到第幾個路口
LCD.Text(1, 0, 0, 1, "COUNT " + count + " ")
EndWhile
' 停車
Motor.Stop("BC", "True")Step by step:
- Crossing counter count starts at 0
- onCross = 0 means "not on a crossing right now"
- Keep following the line until 3 crossings have been counted
- Proportional line following: turn = line position × 0.3
- Left wheel = 25 + turn, right wheel = 25 − turn
- If the line width is 10 or more (on a crossing)
- and we were not on a crossing a moment ago
- Just reached a new crossing: add 1 to count
- Remember "on a crossing" so the same crossing is not counted again
- Beep
- Otherwise:
- Left the crossing: set onCross back to 0, ready for the next one
- and we were not on a crossing a moment ago
- Show how many crossings have been counted
- Stop
What you should see: Every crossing beeps once and adds 1 on the screen; the robot stops at the 3rd crossing. Change the 3 to stop at a different crossing.
FAQ:
- One crossing is counted twice? Happens when the black line at the crossing is damaged or shiny. Slow the speed 25 down or raise the width threshold.
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
- The robot steers the wrong way and gets worse? Swap the "+" and "−" in the program (swap the left/right wheel corrections), or check that the left wheel is on B and the right wheel on C.
Example 6: Line bitmap: draw an LED ruler on the screen
Pybricks v4 / EV3 MicroPython v2.0 / clev3r only (the EV3-G and Classroom blocks cannot read this mode)
What this example does: Mode 3 sends the "line bitmap": 16 bits, one per channel, 1 when that channel is on the line. This example draws it as a ruler (# = on the line, . = not), just like the LEDs on the sensor, so you can see at a glance which channels see the line and whether there is a fork.
What you need:
- Pathfinder 16-way (EV3 edition, firmware v4.0 or later)
- EV3 brick
- A white mat with a black line
How to connect: Pathfinder 16-way in port 1, mounted under the front of the robot about 1 cm above the ground, facing straight down.
Download the program (pick your software):
(The code is the example; no screenshot needed.)
clev3r code
' ============================================================
' 循行者 16 路循線感應器 EV3 新手範例 06:壓線位元圖:在螢幕上畫一把 LED 尺
' 軟體:clev3r
' 接法:循行者 16 路插 1 號孔;左輪馬達接 B、右輪馬達接 C
' 這個範例會做什麼:模式 3 送出「壓線位元圖」:16 個位元,每一路壓到線就是 1。這個範例把它畫成一把尺(# =壓到線、. =沒壓到),跟感應器上的 LED 一樣,一眼就看出線在哪幾路、有沒有分岔。
' 讀值:bitmap=壓線位元圖(0 ~ 65535:bit0=第 1 路(最左)… bit15=第 16 路,1=那一路壓到線)
' ============================================================
folder "prjs" "MBC_line16_ex06"
' 循行者 16 路插 1 號孔,使用模式 3
Sensor.SetMode(1, 3)
LCD.Clear()
' 清除螢幕
LCD.Clear()
' 一直重複
While "True"
' 第 1 行畫尺:16 格,最左是第 1 路,# =壓到線、. =沒壓到
bitsValue = Math.Remainder(Sensor.ReadRawValue(1, 0) + 65536, 65536)
bitsText = ""
For b = 0 To 15
If Math.Remainder(Math.Floor(bitsValue / Math.Power(2, b)), 2) = 1 Then
bitsText = Text.Append(bitsText, "#")
Else
bitsText = Text.Append(bitsText, ".")
EndIf
EndFor
LCD.Text(1, 0, 0, 1, "L " + bitsText + " ")
' 第 2 行顯示位元圖的數字(第 1 路=1、第 2 路=2、第 3 路=4…相加)
LCD.Text(1, 0, 16, 1, "BITS " + Math.Remainder(Sensor.ReadRawValue(1, 0) + 65536, 65536) + " ")
' 等 0.1 秒
Program.Delay(100)
EndWhileStep by step:
- Clear the screen
- Repeat forever
- Row 1 draws the ruler: 16 cells, channel 1 on the far left, # = on the line, . = not
- Row 2 shows the bitmap as a number (channel 1 = 1, channel 2 = 2, channel 3 = 4 … added up)
- Wait 0.1 s
What you should see: Put the sensor over the black line: 2~3 # marks follow the line along the ruler; at a crossing the whole row turns into #; with no line it is all dots. The number is the sum of 1, 2, 4, 8 … for the channels on the line, for example channels 1 and 2 = 3.
FAQ:
- The ruler is mirrored compared with the sensor LEDs? The ruler is seen from behind the robot (far left = channel 1); the LEDs may look mirrored when viewed from above.
- The number stays at 0 or never changes? This mode needs sensor firmware v4.0 (2026-10) or later; update older firmware first.
- Why is there no EV3-G / Classroom version? This example uses a new mode (firmware v4, 2026-10). The EV3-G and Classroom infrared blocks cannot read it; only Pybricks, EV3 MicroPython and clev3r can.
- The number never changes? Check that the sensor light is on and the cable is seated. Turn the EV3 on before plugging in the sensor, or unplug and plug it back in.
Still stuck? Leave a message on Contact us with the software you use and a screenshot of your program, and we will help.
More questions
- The EV3 shows an infrared sensor? Expected: the sensor emulates a LEGO sensor so the stock blocks can read it.
- A short freeze when switching modes? The EV3 needs about 1 s per mode change. Stick to one mode during a run.
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/ev3-clev3r.en.md、_build/guides/product/line16/ev3-clev3r.en.md - Examples:
sensors/line16/ev3-examples.md