Using Optical Sensor with VEX EXP

The EXP Optical Sensor is one of the powerful EXP sensors which are designed for complete integration with the EXP robotics platform.

EXP_optical.png


Description of the Sensor

The EXP Optical Sensor is a combination of the following sensors:

  • Ambient light sensor: Reports the current amount of ambient light that the sensor is detecting. This could be the brightness levels a room, or the brightness of a particular object.
  • Color sensor: Color information is available as RGB (Red, Green, Blue), hue and saturation, or grayscale. Color detection works best when the object is closer than 100 millimeters (mm).
  • Proximity sensor: The proximity sensor measures reflected IR (infrared) energy sourced from an integrated IR LED. As such, the values will change with ambient light and object reflectivity.

lit_up_EXP_optical.png

The Optical Sensor also contains white LEDs.

These LEDs can be turned on and off, or set to a specific percentage of brightness.

This provides a consistent light source when detecting colors regardless of the surrounding light conditions.

Screen_Shot_2022-01-27_at_12.16.46_PM.png

The back of the sensor's housing has five holes to provide flexibility when mounting the sensor to a robot.

highlighted_EXP_optical.png

On the face of the sensor there is a small window where the Optical Sensors are located.

EXP_brain_with_optical.png

In order for the Optical Sensor to be functional with the EXP Brain, the sensor’s Smart Port and an EXP Brain’s Smart Port need to be connected with a Smart Cable.

The Optical Sensor will work with any of the 12 Smart Ports on the EXP Brain.

When connecting an EXP 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 Optical Sensor Works

The EXP Optical Sensor receives light energy and converts the energy into electrical signals. The sensor's internal electronics (a hardware state machine) converts these signals into output signals to be received as an input by the EXP Brain.

As previously mentioned:

  • The sensor’s color detection works best when the object is closer than 100 millimeters (mm) or approximately 3.9 inches.
  • The proximity sensor measures reflected lR light intensity. This will cause the values to change with ambient light and object reflectivity.

The Optical Sensor needs to be paired with the VEXcode EXP to create a user program for the EXP Brain to utilize the sensor’s readings to control the robot’s behavior.

The EXP Brain in concert with a user program can be used with the Optical Sensor to:

  • Turn the sensor’s white LED lights on or off.
  • Set the white LED lights' percentage of power.
  • Detect an object.
  • Detect a color.
  • Measure the percent brightness of ambient light.
  • Measure the hue of a color in degrees.

Setup of the Optical Sensor

Placement

EXP_CC_Lesson_4_Tile_Optical_sensor.png

The placement of the Optical Sensor is very important to obtaining accurate readings.

Be sure no structure on the robot is in front of the small Optical Sensor 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 Optical Sensor Values

exp-brain-screen-read-optical.png

It is helpful to use the Devices screen on the EXP Brain to see the information the Optical Sensor is reporting.

  • LED: the current brightness percentage of the LEDs. 0 is off, and 100% is fully on.
  • BRT: the percentage of brightness of the ambient light in the room, or of an object
  • PROX: the proximity of an object as near or far
  • Hue: a hue value between 0 - 359 degrees. Each hue value has a color shade association.

    To use the Sensor Dashboard, follow the steps in this article. 

Adding the Optical Sensor as a Device in VEXcode EXP

Whenever a sensor is used with a programming language, it needs to be configured within that language. 

Add_a_Device_Screen.png

With VEXcode EXP, this is accomplished by using the ‘Add a device’ feature from the Devices window.

To add the Optical Sensor to the configuration, follow the steps in this article. 

Optical_Sensor_Blocks.png

Once the Optical Sensor has been added to your project, a new set of sensor blocks will become available.

For more information on the blocks from the ‘Sensing’ category pertaining to the Optical Sensor, view the Help information (Blocks project).


Common Uses of the Optical Sensor

The Optical Sensor can produce several measurements which can be used to change the behavior of the robot. These features include:

Detect an object

Detect_an_object.png

This feature allows your robot to detect an object when it becomes within the range of the Optical Sensor.

The example project shown on the left is used to code a robot with an Optical Sensor mounted on the front to drive until it detects an object, such as a cube, and then stop driving once the object is detected by the Optical Sensor.

Detect a color

EXP_looking_at_objects_optical.png

This feature allows your robot to identify the color of an object.

An example could be to code a robot with an Optical Sensor to turn until it detects an object, such as a colored cube.

Once an object is detected, the robot stops turning for 5 seconds and drives towards the cube.

 

Measure ambient light

Ambient_light.png

This feature allows your robot to measure the brightness of the light around it.

The example project shown on the left is used to drive a robot in a circle when the lights in a room are turned on, and stop the robot from driving when the lights are turned off.

Measure the hue value

vex-rainbow-circle-graphic_2.jpg

This feature allows your robot to provide a number for the hue of color of an object.

The Optical Sensor reports the corresponding hue value in degrees from 0 to 359 based on the color wheel to the left.

This provides a more precise measurement of color as compared to a generalized red, green, or blue designation.

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

Last Updated: