EV3 clev3r (BASIC)
+
Warning
Please Note: You are currently viewing the tutorial for the 【EV3 clev3r (BASIC)】 environment. If you are using SPIKE or other EV3 software, please click the button above to return to the hub menu and reselect.
Applicable to clev3r v1.7.1.0 (BASIC language development environment for EV3). In this environment, the Pathfinder 8-Way Sensor will be perfectly identified by the LEGO system as an official Infrared Sensor.
Important
Crucial Hardware Communication Delay Warning for EV3 Due to the hardware communication mechanism limitations of the official LEGO EV3 hub, when a program switches between different block modes (e.g., from Proximity to Remote) for reading, the hub will generate a physical communication waiting delay of approximately 0.5 seconds, which can cause the robot to lose control in high-speed competitions. Strong Recommendation: Depending on your task requirements (e.g., only using Remote for PID line following), select ONE block mode at the very beginning of the program and DO NOT switch reading modes midway through the task!
Differences from the Official EV3 Software (EV3-G) clev3r uses BASIC syntax, but the sensor reading modes are exactly the same as the official EV3 software: Proximity / Beacon / Remote modes. The returned value ranges are also completely identical. You can read them using BASIC commands like
IR_PROXIMITY/IR_BEACON/IR_REMOTE.
Read Line Position — Proximity Mode
Use BASIC commands to read Proximity mode values.
| Returned Value | Range | Description |
|---|---|---|
| Line Position | -8 ~ +8 |
👉 0 = black line is dead center, negative is left, positive is right; ±8 means the line is at the very edge of the sensor.
|
Read 8-Channel Photoelectric Reflection Values — Beacon Mode
Use BASIC commands to read the Beacon mode value list (8 bytes).
| Byte | Content | Range | How to read |
|---|---|---|---|
| 0 | Channel 1 reflectance | 0 ~ 100 | raw[0] |
| 1 | Channel 2 reflectance | 0 ~ 100 | raw[1] |
| 2 | Channel 3 reflectance | 0 ~ 100 | raw[2] |
| 3 | Channel 4 reflectance | 0 ~ 100 | raw[3] |
| 4 | Channel 5 reflectance | 0 ~ 100 | raw[4] |
| 5 | Channel 6 reflectance | 0 ~ 100 | raw[5] |
| 6 | Channel 7 reflectance | 0 ~ 100 | raw[6] |
| 7 | Channel 8 reflectance | 0 ~ 100 | raw[7] |
Each value is a calibrated reflectance:
0= darkest (black line),100= brightest (white). Channel 1 is the leftmost sensor (viewed from behind the robot).
Read Position + Width + Boundary Defense — Remote Mode (Recommended for Tactical Competition!)
Use BASIC commands to read the Remote mode value list (4 bytes).
| Byte | Content Data | Value Range | Tactical Interpretation |
|---|---|---|---|
| Byte 0 | High-Res Position Shift | -100 ~ +100 |
👉 0 represents dead center, negative is left, positive is right. The top choice for ultra-smooth PID error input!
|
| Byte 1 | Feature Line Width | 0 ~ 8 | 👉 Number of triggered sensors. Can be used to detect intersections or T-junctions. |
| Byte 2 | Left Boundary Physical Light Value | 0 ~ 100 |
👉 dataIrCalib[0] (channel 1) The reflected light of the leftmost sensor. 0=pure black, 100=pure white. Can be used to detect track boundaries or forks.
|
| Byte 3 | Right Boundary Physical Light Value | 0 ~ 100 |
👉 dataIrCalib[7] (channel 8) The reflected light of the rightmost sensor. 0=pure black, 100=pure white. Can be used to detect track boundaries or forks.
|
Tactical Fool-Proofing Tip: Byte 2 and Byte 3 in Remote mode allow you to directly obtain the extreme edge light values on both sides of the sensor in clev3r (BASIC). If both values are simultaneously less than 20, it means the front of the car has completely entered the horizontal line of an intersection; if one side's value suddenly changes, it means a fork is approaching. This is the ultimate weapon to prevent losing the line!
Download Example Programs
The image above demonstrates the classic PID line-following program structure in clev3r (EV3) for the 8-Way Line Follower.
EV3 Exclusive Subroutines Explanation
To make programming in EV3 clev3r (BASIC) more concise and intuitive, the MBC 8-Way Line Follower provides three powerful "Subroutines". During development, you don't need to install cumbersome extension packs; just call the corresponding function in the main program, and the system will automatically parse the hardware packets in the background and store the latest sensor data in exclusive variables for the motor control logic to use directly.
Here is an introduction to the functions and usage timings of the three core subroutines:
1. Basic Line Following Subroutine: LinePos8_dataUpdate
- Purpose: Quickly read the most basic 8-segment line position, suitable for beginner tutorials and basic left/right steering judgments.
- Parameters and Returns: Input sensor port (
port), returns variablepos8. - Value Parsing: The range is between
-8and+8. - Physical Intuition: Negative value when the black line is on the left, 0 when it is dead center, positive value when it is on the right.
2. Competitive High-Precision Subroutine: LinePos100_dataUpdate
- Purpose: Obtain high-resolution sub-pixel interpolated positions, the best choice for PID line following. Designed specifically for high-end PID/PD line-following control algorithms (applicable to various racing events), providing extremely smooth correction power. The prerequisite is that the sensor calibration must be fully completed; the more accurate the calibration, the more precise the values.
- Parameters and Returns: Input sensor port (
port), synchronously returns several key variables:pos100: High-precision position, range-100to+100(also maintains the standard of left negative, right positive).width: Real-time line width detection, the value represents the number of currently triggered sensors (range0to8). Can be used to accurately judge intersections, T-junctions, or the finish stop line.ch1/ch8: Synchronously read the physical light values of the leftmost (ch1) and rightmost (ch8) sensors (range0to100), making it convenient for users to adjust advanced strategies such as anti-derailment or intersections.
3. Full Array Decoding Subroutine: LineCh8_dataUpdate
- Purpose: Thoroughly decode the 8 sensors into independent states. Applicable for writing custom special intersection judgment algorithms, triggering monitoring of sensors at specific positions, or drawing the sensor status directly on the screen of the EV3 hub.
- Parameters and Returns: Input sensor port (
port), the subroutine will instantly parse and return the arraylight8. You can obtain the real-time quantized light value of each sensor through the index (light8[0]tolight8[7]) (value range1to9, 1=darkest, 9=brightest).
Tip
Development Tip The underlying technology of these three functions cleverly utilizes the multi-channel switching (Channel 1~4) of the built-in EV3 infrared sensor (set to Port 4) to transmit a large amount of data. During actual development, as long as you put these exclusive subroutines into an infinite Loop, you can ensure the line-following robot grasps the most real-time track information at all times!
Tip
Want to learn more advanced line-following control methods? You can take classes from these awesome coaches! They have rich experience in competitions and teaching, guaranteeing you'll learn a lot! 💯

