Using the Distance Sensor in VEXcode VR

The Distance Sensor on the VR Robot reports the distance between the VR Robot and the nearest object. The sensor calculates distance by using the time it takes for laser light to bounce off of an object and return to the sensor.


Distance Sensor on the VR Robot

Diagram showcasing the features of VEXcode VR robot, highlighting its virtual programming capabilities, block-based coding interface, and support for educational objectives in STEM, including problem-solving and computational thinking.

The Distance Sensor is a sensor that reports the distance between the VR Robot and the nearest solid object.

Screenshot of VEXcode VR interface showcasing robot features, including programming blocks and virtual robot controls, designed for teaching coding concepts and robotics principles in an educational environment.

The Distance Sensor uses the same principles as sonar devices to measure sound. It sends out a tiny pulse of laser light with its emitter at one side of the sensor, and then times how long it takes for the light to reflect back to the receiver at the other side of the sensor. The sensor calculates the distance based on how long the pulse took to make the round trip. Then, the Distance Sensor reports to the VR Robot how far the nearest object is.

Diagram showcasing the features of the VEXcode VR robot, highlighting its components and capabilities in an educational setting for coding and robotics learning.

The width of the Distance Sensors range of vision changes as it looks further away from the front of the VR Robot:

  • The sensor can detect objects within a 10 degree field of view when looking for objects less than 1000 millimeters (~ 39 inches) away.
  • The sensor can detect objects within a 5 degree field of view when looking for objects between 1000 millimeters (~ 39 inches) and 2000 millimeters (~ 78 inches) away.
  • The sensor can detect objects within a 2 degree field of view when looking for objects greater than 2000 millimeters (~ 78 inches) away.

Common Uses of the Distance Sensor

Diagram illustrating the features of the VEXcode VR robot, highlighting its capabilities and components, designed to aid in learning coding concepts through a virtual programming environment.

The Distance Sensor can detect if there is an object in front of the VR Robot. This can be used to avoid an obstacle.


Using the Distance Sensor with VEXcode VR Blocks

Diagram illustrating the features of VEXcode VR robots, showcasing components such as sensors, motors, and design elements, aimed at enhancing coding and robotics education for students and educators.

The blocks used with the Distance Sensor can be found in the Sensing category.

<Distance found object> Block

Illustration of VEXcode VR robot features, showcasing the virtual robot's design and functionalities within the online programming environment for coding education in STEM.

The Distance Sensor detects if there is an object in front of it using the <Distance found object> block. The Distance Sensor can detect an object or surface within 3000 mm (~118 inches) of the sensor.

Diagram showcasing the features of the VEXcode VR robot, highlighting its components and capabilities within the context of an online programming environment for learning coding concepts.

The <Distance found object> block is a Boolean block that returns a condition as either true or false and fits inside any blocks with hexagonal (six-sided) spaces for other blocks.

For more information on boolean blocks, view this article.

Diagram illustrating the key features of the VEXcode VR robot, highlighting components such as sensors, motors, and programming interface, designed to enhance learning in coding and robotics for students and educators.

The value of the <Distance found object> block is a Boolean block that reports true when the Distance Sensor is close to an object, and reports false when it is not close enough to an object.

True or false will be reported and appear in the Monitor Console. 

To learn more about the Monitor Console, view this article.

(Distance from) Block

Diagram illustrating the features of the VEXcode VR robot, highlighting its capabilities and components for educational purposes in coding and robotics.

Using the (Distance from) block, the Distance Sensor can report the distance of the nearest object in millimeters (mm) or inches.

Image showcasing the features of VEXcode VR robots, highlighting their capabilities and design, in the context of an online programming environment for learning coding concepts through virtual robotics.

The (Distance from)  block reports number values and fits inside any blocks with oval spaces.

For more information on reporter blocks, view this article

Diagram showcasing the robot features in VEXcode VR, highlighting components such as sensors, wheels, and programming interface, designed to enhance learning in coding and robotics for students and educators.

The value of the (Distance from) block in the units of millimeters (mm) or inches can be displayed on the Monitor Console in VEXcode VR. 

To learn more about the Monitor Console, view this article.


Using the Distance Sensor in VEXcode VR Python

Illustration of VEXcode VR robot features, showcasing the virtual robot's design and capabilities within the online programming environment, aimed at enhancing coding skills and STEM education.

To begin programming the Distance Sensor with Python, you will need to first open a text project VEXcode VR. For more information, see this article.

Diagram showing the key features of VEXcode VR robot, including sensors, motors, and programming interface, illustrating how users can interact with the virtual robot in a coding environment for educational purposes.

Next, locate the Sensing category in the Toolbox and find found_object and get_distance commands. These are functions that report a Boolean value or numerical value about the sensor.

Diagram illustrating the key features of VEXcode VR robots, highlighting components such as sensors, motors, and programming interfaces, designed to enhance learning in coding and robotics for students and educators.

To add the command to your project, you can drag the command in from the Toolbox, or type out the command in the workspace using the Autocomplete function.

To learn more about Autocomplete in VEXcode VR with Python, see this article.

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: