Using the Distance Sensor with VEX V5

The Distance Sensor is one of the powerful V5 sensors which are designed for complete integration with the V5 robotics platform. This sensor uses a pulse of classroom-safe laser light to measure the distance from the front of the sensor to an object.

VEX Distance Sensor image, showcasing the sensor's design and features, used for measuring distances in robotics applications.


Description

The Distance Sensor can also be used to detect an object and determine the relative size of the object. The approximate size of an object is reported as small, medium, or large.

The sensor can be used to calculate a robot’s approach speed. Approach speed measures the speed of the robot/sensor as it moves toward the object.

Diagram of the Distance Sensor with labeled callouts indicating key components and features, illustrating its functionality within the V5 robotics system.

The housing of this sensor has two mounting tabs with slotted holes to provide flexibility when mounting the sensor to a robot.

Diagram of the Distance Sensor with labeled callouts highlighting key features and components, illustrating its functionality in robotics applications.

On the face of the sensor there is a small window where the laser beam is sent out and then received in order to measure distance.

Distance Sensor mounted in a C-Channel, showcasing its design and integration for robotics applications.

The width of the Distance Sensor allows it to be nested into a piece of C Channel.

Note: a 1/4 inch Standoff (275 - 1013) or an 8 millimeter (mm) Plastic Spacer (276-2019) needs to be used for this attachment in order to provide clearance for the V5 Smart Port.

V5 Robot Brain with Distance Sensor, showcasing the sensor's design and features for robotics applications.

In order for the Distance Sensor to be functional with the V5 Robot Brain, the sensor’s V5 Smart Port and a V5 Robot Brain’s Smart Port need to be connected with a V5 Smart Cable. The Distance Sensor will work with any of the 21 Smart Ports on the V5 Robot Brain. When connecting a V5 Smart Cable to the ports, be sure the cable’s connector is fully inserted into the port and the connector’s locking tab is fully engaged.


How the Distance Sensor Works

The Distance Sensor sends out a pulse of classroom-safe laser light and measures the amount of time it takes for the pulse to be reflected. This allows for a calculation of distance.

The sensor’s Class 1 Laser is similar to the lasers used on modern cell phones for head detection. The laser allows the sensor to have a very narrow field of view, so detection is always directly in front of the sensor.

The Distance Sensor’s measurement range is 20 millimeters (mm) to 2,000 millimeters (mm) (0.79 inch to 78.74 inches). Below 200 millimeters (mm) the accuracy is approximately +/‐15 millimeters (mm); above 200 millimeters (mm) the accuracy is approximately 5%.

The Distance Sensor needs to be paired with a programming language such as the VEXcode V5 or VEXcode Pro V5 to create a user program for the V5 Robot Brain to utilize the sensor’s readings to control the robot’s behavior.

The V5 Brain in concert with a user program can be used to convert the Distance Sensor readings into:

  • Distance to an object measured in millimeters or inches.
  • Object velocity in meters per second.
  • Object size is small, medium, or large.
  • Object found.

VEXcode V5 icon representing V5 sensors in the V5 Category Description section.


Setup of the Distance Sensor

Distance Sensor detecting a red object, illustrating its functionality in sensing distance and color in robotics applications.

Placement: The placement of the Distance Sensor is very important to its accurate readings. Be sure no structure on the robot is in front of the small laser window on the face of the sensor. There needs to be a clear path in front of the sensor between any object being measured and the sensor.

  • Reading Distance Sensor Values: It is helpful to use the Device Info screen on the V5 Robot Brain to see the values the Distance Sensor is returning. This can be done with the sensor connected to the Brain by:

    Diagram illustrating the process of removing a V5 sensor, showing the sensor and its connection points, relevant to V5 Category Description and V5 Sensors section.

    Remove the V5 Brain Magnetic Screen Protector, turn on the Brain, and touch the Devices icon.

    Illustration of V5 sensors with labeled components, showcasing their features and functionalities for educational purposes in robotics.

    Touch the Distance Sensor icon on the Device Info screen.

    Screenshot showing the placement of a V5 sensor object in a robotics programming interface, illustrating the setup process for V5 sensors.

    Place an object in front of the Distance Sensor or face the sensor towards a wall and observe its measurements. The displayed range and units, mm or inches, can be changed by a touch of the screen.

    Note: Ensure the V5 Robot Brain has the latest version of firmware.


Adding the distance sensor as a device in VEXcode V5

Whenever a sensor is used with a programming language it needs to be configured within that language. With VEXcode V5 and VEXcode Pro V5, this is accomplished by using the ‘Add a device’ feature. To provide an example of this, the following steps will add the Distance Sensor as a device within VEXcode V5.

Icon representing the selection of devices for V5 sensors in the V5 Category Description.

Select the Devices icon.

Screenshot showing the 'Select Add A Device' interface for V5 Sensors, featuring options to add various devices to the VEX V5 robotics system.

Select ‘Add a device.’

Diagram showing the process of selecting distance settings for V5 sensors in the VEX Robotics system, illustrating options and configurations available for distance measurement.

Select ‘DISTANCE.’

Screenshot of the VEX V5 Smart Port selection interface, displaying options for connecting various sensors, illustrating the setup process for V5 sensors in robotics projects.

Select the Smart Port that the Distance Sensor is plugged into on the V5 Robot Brain.

Diagram illustrating the connection points and setup for V5 sensors, highlighting the various ports and their functions within the V5 robotics system.

Once the port is chosen, select ‘DONE.’

Note: There is an option to change the name of the Distance Sensor in the text window from Distance1 to a different name.

Diagram illustrating the distance measurement capabilities of V5 sensors, showcasing various sensor placements and their corresponding ranges for optimal performance in robotics applications.

Once the distance sensor has been added to your user program a new set of sensor commands will become available.


Common Uses of the Distance Sensor

Screenshot of V5 Sensors category description, showcasing various V5 sensor types and their functionalities in a visual format, highlighting key features and examples for users.VEX V5 logo, representing the V5 Sensors category in the VEX Robotics Knowledge Base.

The Distance Sensor can produce several measurements which can be used to change the behavior of the robot.

These features can be used with either:

  • The ‘Device info’ option on the V5 Robot Brain.
  • Using the example project ‘Distance Sensing’ found in the ‘Open Examples’ option in the File menu of VEXcode V5.
  • Writing a custom user program with one of the VEXcode programs.


These features include:

    • Distance to an object measured in millimeters or inches. This provides a measurement between the front of the distance sensor and an object or a barrier/wall. A fun classroom challenge would be to use the distance sensor to measure the distance between your robot and the wall. Then measure the distance with a different method such as a tape measure and compare the two measurements.
    • Object velocity in meters per second. This provides a measurement of the velocity in meters per second for an object approaching your robot or your robot approaching an object. A fun classroom challenge would be to write a custom user program to measure the maximum speed of your robot as you drive it towards a wall.
      • Note that objects traveling towards the sensor (whether that be your sensor moving towards a stationary object or vice versa) will report a positive velocity, while objects traveling away from the sensor (again whether that be your sensor moving away from a stationary object or vice versa) will report a negative number. It is important to understand that the sensor is able to do this because it simply takes the rate of change of the distance seen by the sensor over time, which in layman's terms is meters/seconds, or velocity.

Graph illustrating positive velocity data from V5 sensors, showing a trend line with varying values over time, used to analyze performance in robotics applications.Graph illustrating negative velocity in V5 sensors, showing a downward trend in measurement values over time, indicating a decrease in speed.

The following two images show the Device Info page when the Distance Sensor is selected. The first image is an example of an object moving towards the sensor, while the second image is of an object moving away. Note the sign conventions of the velocity in each case.

    • Object size is small, medium, or large. This feature allows your robot to identify an object as being small, medium, or large depending on the sensor’s reading. A fun classroom challenge would be to use the V5 Robot Brain's Device Info screen and place different objects at a set distance, such as one meter, to see if the sensor detects the object as small, medium, or large.
      Note: Object size is an estimation and may be affected by object reflectivity.

V5 Clawbot equipped with foam components, showcasing its design and sensors, used in robotics applications.

Found an object. This feature allows your robot to detect an object when it becomes within the range of the distance sensor. A fun classroom challenge would be to place objects with different reflectivity in front of the sensor, such as a block of black foam rubber or a shiny ball of aluminum foil, to see if the object’s surface has any effect on its detection.


Uses of the Distance Sensor on a Competition Robot:

The Distance Sensor will provide a superior competitive advantage for competition robots. The ability to detect distance to the perimeter wall and be able to measure a robot's velocity will provide a great deal of information when designing autonomous routines.

Object detection and determining the object’s relative size will provide helpful information with the detection of game pieces and or goals.

Distance Sensor detecting a red object, illustrating its functionality in sensing distance and color in robotics applications.

For example in the 2020 - 2021 VEX Robotics Competition Game, Change Up, a distance sensor could be angled to scan the floor in front of your robot's intake. As soon as one of the balls used in the game is detected, this could automatically turn on the robot's intake and pick up the ball.

No matter what the application the VEX Distance Sensor is used for, there is no doubt it will be a welcomed addition for teams. The function of the sensor’s values are open for the imagination of the user.

The Distance Sensor is available on VEX’s Website.

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

Last Updated: