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.

Angled view of the V5 Distance Sensor.


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.

V5 Distance Sensor is shown with the tabs on its sides and the slotted holes in the Tabs highlighted and labeled.

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

V5 Distance Sensor is shown with the window for its laser highlighted and labeled.

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.

V5 Distance Sensor is nested and mounted into a V5 C Channel piece using two screws and two 1/4 inch Standoff pieces.

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 Distance Sensor is shown connected to a V5 Brain using a Smart Cable.

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 application icon.


Setup of the Distance Sensor

V5 Distance Sensor is shown placed on the front of a claw arm on a V5 robot build. A red ball is in front of the sensor, to indicate that the sensor can be used to detect objects.

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:

    Brain screen is shown in the Home menu with the Devices option highlighted.

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

    Brain screen is shown in the Device Info menu which has a list of all of the Brain's Smart Ports and connected devices. The Distance Sensor icon in the Device Info menu is highlighted to indicate that items can be selected to open their information menus.

    Touch the Distance Sensor icon on the Device Info screen.

    Brain screen is shown in the Distance Sensor menu that lists the sensor's data. The menu reports data of an object's size, velocity, and distance. The menu also has a diagram that visualizes the distance and how it changes over time. In this screenshot, the object's size is large, its velocity is 0 meters per second, and its distance is 1904 mm.

    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.

VEXcode V5 Toolbar with the Devices icon highlighted in between the Code Viewer and Print Console icons.

Select the Devices icon.

VEXcode V5 Devices menu with the Add a device button highlighted.

Select ‘Add a device.’

VEXcode V5 Devices menu after the Add a device button has been selected. The Distance option is highlighted.

Select ‘DISTANCE.’

VEXcode V5 Devices menu with the Smart Port menu shown. The first Smart Port is highlighted.

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

VEXcode V5 Devices menu after setting the new Distance Sensor's Smart Port option to 1. Above, the device's name is highlighted to indicate that it can be changed. Below, the Done button is highlighted.

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.

VEXcode V5 with the blocks Toolbox shown. The Distance Sensing category of blocks is now available.

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

VEXcode V5 Toolbar with the File menu open and the Open Examples option highlighted. Open Examples is the fifth option in the menu, below New Blocks Project, New Text Project, Open, and Open Recent.Thumbnail for the Distance Sensing example project.

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.

Brain screen is shown in the Distance Sensor menu that lists the sensor's data. The menu's diagram shows the distance to the detected object, and an arrow indicates that the distance is shrinking. The Velocity value reads 0.21 meters per second, also indicating that the distance is shrinking.Brain screen is shown in the Distance Sensor menu that lists the sensor's data. The menu's diagram shows the distance to the detected object, and an arrow indicates that the distance is growing. The Velocity value reads negative 0.29 meters per second, also indicating that the distance is growing.

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 Distance Sensor is shown mounted to a claw arm on a V5 robot build. A foam block has been placed in front of the sensor.

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.

V5 Distance Sensor is shown mounted to a claw arm on a V5 robot build. A red ball is shown in front of the sensor, to indicate that the Distance Sensor could be used to detect a game object in a competition.

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: