Optical Sensing#
To make Optical Sensor blocks appear in VEXcode V5, an Optical Sensor must be configured in the Devices window.
For more information, refer to these articles:
Set Optical Light#
The Set Optical Light block is used to set the light on the Optical Sensor to on or off. The light lets the Optical Sensor see objects if it is looking at an object in a dark area.
set [Optical7 v] light [on v]
Choose which Optical Sensor to use.

Choose whether to turn the light on or off.

In this example, the Optical Sensor will turn its light on for two seconds before turning it off.
when started
set [Optical7 v] light [on v]
wait (2) seconds
set [Optical7 v] light [off v]
Set Optical Light Power#
The Set Optical Light Power block is used to set the light power of Optical sensor
set [Optical7 v] light power to (50)%
The The Set Optical Light Power block block accepts a range of 0% to 100%. This will change the brightness of the light on the Optical Sensor. If the light is off, this block will turn the light on.
Choose which Optical Sensor to use.

In this example, the Optical Sensor’s power light is set to 75% before it waits to detect an object to print a message.
when started
[Set the Optical Sensor's light power to 75%]
set [Optical7 v] light power to (75)%
[Don't print the message until an object is detected.]
wait until <[Optical7 v] found an object?>
print [Object detected.] on [Brain v] ◀ and set cursor to next row
Optical Sensor Found Object#
The Optical Sensor Found Object block is used to report if the Optical Sensor detects an object close to it.
<[Optical7 v] found an object?>
The Optical Sensor Found Object block reports True when the Optical Sensor detects an object close to it.
The Optical Sensor Found Object block reports False when an object is not within range of the Optical Sensor.
Choose which Optical Sensor to use.

In this example, the Optical Sensor’s power light is set to 75% before it waits to detect an object to print a message.
when started
[Set the Optical Sensor's light power to 75%.]
set [Optical7 v] light power to (75)%
[Don't print the message until an object is detected.]
wait until <[Optical7 v] found an object?>
print [Object detected.] on [Brain v] ◀ and set cursor to next row
Optical Sensor Detects Color#
The Optical Sensor Detects Color block is used to report if the Optical Sensor detects the specified color.
<[Optical7 v] detects [red v]?>
The Optical Sensor Detects Color block reports True when the Optical Sensor detects the specified color.
The Optical Sensor Detects Color block reports False when the Optical Sensor doesn’t detect the specified color.
Choose which Optical Sensor to use.

Choose which color the Optical Sensor will check for.

In this example, the Optical Sensor’s will wait until it detects a blue object before printing a message.
when started
[Don't print the message until the color blue is detected.]
wait until <[Optical7 v] detects [blue v]?>
print [Color blue detected.] on [Brain v] ◀ and set cursor to next row
Optical Brightness#
The Optical Brightness block is used to report the amount of light detected by the Optical Sensor.
([Optical7 v] brightness in %)
The Optical Brightness block reports a number value from 0% to 100%.
A large amount of light detected will report a high brightness value.
A small amount of light detected will report a low brightness value.
Choose which Optical Sensor to use.

In this example, the Optical Sensor will print the current brightness value to the Brain’s screen.
when started
print ([Optical7 v] brightness in %) on [Brain v] ◀ and set cursor to next row
Optical Hue#
The Optical Hue block is used to report the hue of the color of an object.
([Optical7 v] hue in degrees)
The Optical Hue block reports a number value that is the hue of the color of an object. It returns a number between 0 and 359.
The value can be thought of as the location of the color on a color wheel in degrees.
Choose which Optical Sensor to use.

In this example, the Optical Sensor will print the currently seen hue to the Brain’s screen.
when started
print ([Optical7 v] hue in degrees) on [Brain v] ◀ and set cursor to next row