Ranger 8-Way (TOF8) × EV3 × EV3-G
Interactive tutorialEV3
First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.
This page covers EV3-G official software (EV3 Lab) only: how to set it up for the Ranger 8-Way (TOF8) 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: Ranger 8-Way (TOF8) (EV3 edition, RJ12 plug). A SPIKE edition is not recognised on an EV3.
- Brick: LEGO MINDSTORMS EV3.
- Cable: the standard cable in the box, or an original LEGO EV3 cable.
- Software: the official LEGO MINDSTORMS EV3 software (LabVIEW-style interface, usually called EV3-G). The most common choice in school computer labs and WRO teams.
Install the software
- Install the official EV3 software (EV3 Lab) from the LEGO Education download page.
- To open an example: download the
.ev3file → "File → Open Project" → connect the EV3 → "Download and Run" at the bottom right.
Make the software see the sensor
No extension and no driver needed. On the EV3 the sensor emulates an original LEGO sensor (most products show up as an "Infrared Sensor"); use the built-in sensor blocks and pick the right mode.
- The infrared sensor has three modes, Proximity, Beacon and Remote; the product puts different data in different modes. See the readings below.
- Some products come with MBC My Blocks. They are already inside the example projects; open an example and they are there.
Important
Do not switch modes in the middle of a program. Every time the EV3 switches a sensor mode (for example from Proximity to Remote) it stalls for about 1 s, which can make a fast robot lose control. 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; choose the same port in the blocks).
- Turn the EV3 on first, then plug in the sensor.
- Latch up, push the plug in gently; do not force it.
Wait 2~4 seconds after power-on
The Ranger 8-Way needs no calibration; plug it in and go. After power-on, wait 2~4 seconds for the 8 lasers to get ready; meanwhile everything reads 120 (cm). Start your program with a short wait before reading distances.
| Channel | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Facing | left | left-front 60° | left-front 30° | front | front | right-front 30° | right-front 60° | right |
The table assumes the sensor faces forward with the components up. Put your hand on the robot's left: example 1 should show a negative direction. If it shows a positive one, the sensor is mounted the other way, and "turn left" / "turn right" in the examples must be swapped too.
First test
- Download the
.ev3of example 1 on this page, open it and press "Download and Run". - If the number on the EV3 screen changes with what is in front of the sensor, everything is connected.
FAQ
- The number never changes? Unplug the sensor and plug it back in (the EV3 must be on first).
- The EV3 shows an "Infrared Sensor"? That is normal: read the values with the infrared sensor blocks.
- Some examples have no EV3-G version? Examples marked "Pybricks / EV3 MicroPython / clev3r only" use a mode the EV3-G blocks cannot read.
- The program hiccups now and then? It switches sensor modes; each switch costs about 1 s. Use one mode only.
Reading values
The EV3 sees a stock LEGO sensor, so read it with the stock sensor block.
nearest distance (cm) nearCm
| Range | Meaning |
|---|---|
0~120 cm (EV3 mode 2 gives a scaled value: cm×100/120 (0~100)) |
smallest of the 8 distances, 0~120 cm (a failed sensor counts as 120); 120 = nothing around |
| Value | Block | Decode | Mode |
|---|---|---|---|
| nearest distance (cm) | Infrared Sensor → Remote, channel 2 | the value | mode 2 |
nearest direction nearDir
| Range | Meaning |
|---|---|
-8~+8 |
direction of the nearest object: −7 (left) to +7 (right), 0 = straight ahead, negative = left; ±8 = nothing around (keeps the last side) |
| Value | Block | Decode | Mode |
|---|---|---|---|
| nearest direction | Infrared Sensor → Remote, channel 1 | the value | mode 2 |
farthest distance (cm) farCm
| Range | Meaning |
|---|---|
0~120 cm (EV3 mode 2 gives a scaled value: cm×100/120 (0~100)) |
largest of the 8 distances, 0~120 cm (a failed sensor always reads 120 and looks 'farthest') |
| Value | Block | Decode | Mode |
|---|---|---|---|
| farthest distance (cm) | Infrared Sensor → Remote, channel 4 | the value | mode 2 |
farthest direction farDir
| Range | Meaning |
|---|---|
-7~+7 |
direction of the most open side: −7 to +7, 0 = straight ahead, negative = left; 0 when all 8 read 120 |
| Value | Block | Decode | Mode |
|---|---|---|---|
| farthest direction | Infrared Sensor → Remote, channel 3 | the value | mode 2 |
front distance (cm) frontCm
| Range | Meaning |
|---|---|
0~120 cm (EV3 mode 0 gives a scaled value: cm×100/120 (0~100)) |
average of sensors 4 and 5 (both facing forward), 0~120 cm; EV3 mode 3 and SPIKE mode 6 carry the same thing in mm; 0x22 'C' is min(4, 5), not the average (see 10) |
| Value | Block | Decode | Mode |
|---|---|---|---|
| front distance (cm) | Infrared Sensor → Proximity | the value | mode 0 |
sensor 1~8 distance (cm) distCm
| Range | Meaning |
|---|---|
0~120 cm (EV3 mode 1, mode 4 give a scaled value: cm×100/120 (0~100)) |
distance of each sensor 1 |
| Value | Block | Decode | Mode |
|---|---|---|---|
| #1 | Infrared Sensor → Beacon heading, channel 1 | the value | mode 1 |
| #2 | Infrared Sensor → Beacon proximity, channel 1 | the value | mode 1 |
| #3 | Infrared Sensor → Beacon heading, channel 2 | the value | mode 1 |
| #4 | Infrared Sensor → Beacon proximity, channel 2 | the value | mode 1 |
| #5 | Infrared Sensor → Beacon heading, channel 3 | the value | mode 1 |
| #6 | Infrared Sensor → Beacon proximity, channel 3 | the value | mode 1 |
| #7 | Infrared Sensor → Beacon heading, channel 4 | the value | mode 1 |
| #8 | Infrared Sensor → Beacon proximity, channel 4 | the value | mode 1 |
Not readable here:nearest distance (mm), init bitmap, fault bitmap, front distance (mm), sensor 1~8 distance (mm). Use Pybricks / clev3r for these.
Examples
Example 1: Measure the distance straight ahead
What this example does: Mode 0 of the eight-direction laser gives the average distance straight ahead (the middle two lasers): the simplest value to use.
What you need:
- TOF8 eight-direction laser (EV3 edition)
- EV3 brick
How to connect: TOF8 eight-direction laser in port 1.
Download the program (pick your software):
Step by step:
- Clear the screen
- Repeat forever
- Row 1 shows the straight-ahead distance (0~100)
- Row 2 converts to centimetres: × 1.2
- Wait 0.1 s
What you should see: Move your hand in front and the number follows; with nothing ahead it reads 100.
FAQ:
- The number does not match a ruler? On EV3, 1 unit = 1.2 cm (for example 25 = 30 cm); 100 means nothing within 120 cm ahead.
- The number stays at 0 or never changes? Turn the EV3 on before plugging in the sensor, or unplug and plug it back in; make sure there is no protective film over the laser.
Example 2: Stop 30 cm before the wall
What this example does: The robot drives forward and stops when something is within 30 cm (value 25) straight ahead.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- TOF8 eight-direction laser (EV3 edition)
- A few boxes as obstacles
How to connect: TOF8 eight-direction laser in port 1, mounted at the front with lasers 4 and 5 facing straight ahead, about 5 cm above the ground.
Download the program (pick your software):
Step by step:
- Both wheels drive forward
- Wait until the straight-ahead distance is less than 25
- Stop
- Beep
What you should see: The robot stops about 30 cm from the obstacle and beeps.
FAQ:
- The number does not match a ruler? On EV3, 1 unit = 1.2 cm (for example 25 = 30 cm); 100 means nothing within 120 cm ahead.
Example 3: See all 8 directions at once
What this example does: Mode 1 sends the distance of each of the 8 lasers. This example shows all 8 numbers on the screen; wave your hand around and you will know which laser points where.
What you need:
- TOF8 eight-direction laser (EV3 edition)
- EV3 brick
How to connect: TOF8 eight-direction laser in port 1.
Download the program (pick your software):
Step by step:
- Clear the screen
- Repeat forever
- Row 1 shows the distance of laser 1
- Row 2 shows the distance of laser 2
- Row 3 shows the distance of laser 3
- Row 4 shows the distance of laser 4
- Row 5 shows the distance of laser 5
- Row 6 shows the distance of laser 6
- Row 7 shows the distance of laser 7
- Row 8 shows the distance of laser 8
- Wait 0.1 s
What you should see: 8 rows of numbers, one per laser; bring your hand near a laser and that row gets smaller.
FAQ:
- The number does not match a ruler? On EV3, 1 unit = 1.2 cm (for example 25 = 30 cm); 100 means nothing within 120 cm ahead.
- Is laser 1 on the left or the right? Try it with your hand and write it down; you will need it when programming.
Example 4: Sumo chaser: turn towards the nearest object and charge
What this example does: Mode 2 tells you directly "where the nearest object is and how far", so you do not have to compare 8 numbers yourself. The robot turns towards the nearest object and charges; when it sees nothing it spins to search.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- TOF8 eight-direction laser (EV3 edition)
- A can as the opponent
How to connect: TOF8 eight-direction laser in port 1, mounted at the front with lasers 4 and 5 facing straight ahead, about 5 cm above the ground.
Download the program (pick your software):
Step by step:
- Repeat forever
- If the nearest object is within 60 (about 72 cm)
- If the direction is less than -1 (to the left)
- Object on the left: spin left on the spot
- Otherwise:
- Otherwise, if the direction is greater than 1 (to the right)
- Object on the right: spin right on the spot
- Otherwise:
- Object straight ahead: charge at full power
- Otherwise, if the direction is greater than 1 (to the right)
- Otherwise:
- Nothing nearby: spin on the spot to look for the opponent
- If the direction is less than -1 (to the left)
- If the nearest object is within 60 (about 72 cm)
What you should see: Put the can anywhere around the robot: it turns towards the can and pushes it.
FAQ:
- The direction reads 8 or -8? ±8 means nothing within 120 cm in that direction, not "far left" or "far right".
- It overshoots and swings back and forth? Lower the turning power 20, or change -1 and 1 to -2 and 2.
Example 5: Drive towards the most open direction
What this example does: Mode 2 also tells you "the most open direction". With proportional control the robot keeps heading for open space and finds its way out of a box maze.
What you need:
- EV3 brick + Education base robot (left wheel on B, right wheel on C)
- TOF8 eight-direction laser (EV3 edition)
- A few boxes as obstacles
How to connect: TOF8 eight-direction laser in port 1, mounted at the front with lasers 4 and 5 facing straight ahead, about 5 cm above the ground.
Download the program (pick your software):
Step by step:
- Repeat forever
- Steering power turn = most open direction × 5 (negative = left, positive = right)
- Left wheel = 25 + turn, right wheel = 25 − turn
What you should see: The robot avoids the boxes and drives towards open space.
FAQ:
- The direction reads 8 or -8? ±8 means nothing within 120 cm in that direction, not "far left" or "far right".
- It keeps driving into walls? The sign of the direction may be opposite to your robot: swap "+turn" and "−turn" in the program.
Note
These examples have no version for this software: Example 6: Where is the nearest object, and how many millimetres away
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/tof8.json(single source of truth) - Setup:
_build/guides/software/ev3-ev3g.en.md、_build/guides/product/tof8/ev3-ev3g.en.md - Examples:
sensors/tof8/ev3-examples.md




