Using the Eye Sensor in VEXcode VR

The VEX VR Robot has a multitude of sensors, including two Eye Sensors.


Eye Sensors on the VR Robot

Diagram illustrating the features of the VEXcode VR robot, highlighting components and functionalities designed for coding and robotics education in a virtual environment.

The VR Robot has two Eye Sensors, one that faces forward, and another that faces down. The sensors can detect if there is an object present as well as detect color (red, green, blue, none).

Diagram illustrating the key features of the VEXcode VR robot, highlighting its programming capabilities, sensors, and design elements that support educational objectives in coding and robotics.

The Eye Sensor values can be displayed on the Dashboard in VEXcode VR. To learn more about the Dashboard, view the Dashboard - Playground Features - VEXcode VR article.

Illustration of VEXcode VR robot features, showcasing the virtual robot's design and capabilities within the online programming environment, highlighting its educational applications in coding and robotics for students and educators.

The Eye Sensor values can be displayed on the Monitor Console in VEXcode VR. To learn more about the Monitor Console, see this article.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.


VEXcode VR Blocks Used with the Eye Sensors

<Color near object> block

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

The <Color near object> block reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none).

Diagram illustrating the features of the VEXcode VR robot, highlighting components and functionalities that support coding and robotics education in a virtual environment.

The Front or Down Eye Sensor can be selected from the drop-down menu on the block.

Diagram illustrating the features of VEXcode VR robot, highlighting its capabilities in programming, simulation, and educational applications for STEM learning.

The <Color near object> block is a Boolean block that reports true when the Eye Sensor is close to an object that has detectable colors, and reports false when it is not close enough to an object with detectable colors.

<Color sensing> block

Diagram showcasing the features of VEXcode VR robot, highlighting its capabilities in programming, problem-solving, and robotics education, suitable for both beginners and advanced users in a virtual learning environment.

The Color sensing block reports if the Eye Sensor detects a specific color.

Diagram showcasing the features of VEXcode VR robot, highlighting its capabilities in programming, problem-solving, and robotics education, suitable for both beginners and advanced users in a virtual learning environment.

The Front or Down Eye Sensor can be selected from the drop-down menu on the block.

Diagram illustrating the key features of VEXcode VR, an online programming environment for virtual robotics, highlighting its block-based and text-based coding options for learning coding concepts in STEM education.

The color that the Eye Sensor is looking for can be selected from the drop-down menu on the block.

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

The <Color sensing> block is a Boolean block that reports true when the Eye Sensor detects the selected color, and reports false when it does not detect the selected color.


VEXcode VR Python Commands Used With the Eye Sensor

near_object Command

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

The near_object command reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none). The front or down Eye Sensor can be selected when dragging in a command from the Toolbox or when typing in the command.

Diagram illustrating the features of VEXcode VR robot, highlighting its capabilities in programming, simulation, and educational applications for STEM learning.

The near_object command is a Boolean that reports true when the Eye Sensor is close to an object that has detectable colors, and reports false when it is not close enough to an object with detectable colors.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.

detect Command

Diagram illustrating the features of VEXcode VR robots, highlighting components such as sensors, motors, and the virtual environment used for programming and testing code in STEM education.

The detect command reports if the Eye Sensor detects a specific color. The front or down Eye Sensor can be selected when dragging in a command from the Toolbox or when typing in the command.

Diagram illustrating the features of VEXcode VR robots, highlighting components such as sensors, motors, and connectivity options, designed to enhance coding and robotics education for students and educators in a virtual environment.

The color that the Eye Sensor is looking for can be selected through the autocomplete feature when adding the command. For more information on using the autocomplete feature in VEXcode VR with Python, see this article.

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

The detects command is a Boolean that reports true when the Eye Sensor detects the selected color, and reports false when it does not detect the selected color.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.


Using the Front Eye Sensor in a VEXcode VR Project

The VR Robot can use the Front Eye Sensor to initiate a sequence of behaviors when an object or color is detected. This can include driving until an object (like a wall, disk, or castle) is detected then stop driving to avoid a crash or driving and sensing a specific color and executing an action depending on the color detected. 

VEXcode VR Blocks Wall Maze Playground
Image illustrating the features of VEXcode VR robot, showcasing its block-based and text-based coding interfaces, designed for educational purposes in STEM, highlighting programming concepts for beginners and advanced users. Image illustrating the features of VEXcode VR robots, showcasing the virtual robot's design and capabilities within the online programming environment, aimed at enhancing STEM education through coding and robotics.
VEXcode VR Python
def main():
drivetrain.drive(FORWARD)
while not front_eye.near_object():
wait(20, MSEC)
drivetrain.stop()

In this example, using the Wall Maze Playground, the VR Robot will drive forward until it detects that it is near an object, in this case the wall, then stop driving.

Disk Color Maze Playground
Diagram showcasing the key features of VEXcode VR robots, highlighting their capabilities and components in an educational context for coding and robotics learning.
VEXcode IQ Blocks
Diagram illustrating the features of the VEXcode VR robot, highlighting its components and capabilities for programming and robotics education.
VEXcode IQ Python
def main():
drivetrain.drive(FORWARD)
while True:
if front_eye.detect(GREEN):
drivetrain(stop)
wait(2, seconds)
drivetrain.drive_for(REVERSE, 200, MM)
wait(20, MSEC)

In this example on the Disk Maze Playground, the VR Robot will drive forward until the Front Eye Sensor detects a green object, then it will stop and wait, before driving in reverse. Notice that in the Dashboard, the Front Eye Sensor values are reporting true that an object was detected, and the color of that object (disk) is green.


Using the Down Eye Sensor in a VEXcode VR Project

The Down Eye Sensor can be used on the Playgrounds to help detect the color of disks in the Disk Mover Playground, find the edge of the Castle Crasher Playground, and more. One thing to note about the Down Eye Sensor, is that it is tuned to not detect the floor of a Playground as an object. Other items, such as disks, will register as an object.

VEXcode VR Blocks Disk Mover Playground
Diagram illustrating the key features of the VEXcode VR robot, highlighting its capabilities and components in a virtual programming environment designed for educational purposes. Illustration of VEXcode VR robot features, showcasing a virtual robot with various components and coding interface, highlighting its use in teaching coding concepts and robotics principles in an educational setting.
VEXcode VR Python
def main():
drivetrain.drive(FORWARD)
while not down_eye.detect(BLUE):
wait(20, MSEC)
drivetrain.stop()
magnet.energize(BOOST)

This project can be used with the Disk Mover Playground. In this project, the VR Robot will drive forward until the Down Eye Sensor detects blue, then stop driving and set the Electromagnet to 'boost' to pick up the disk.

VEXcode VR Blocks Castle Crasher Playground
Illustration of VEXcode VR robot features, showcasing the virtual robot's design and capabilities within the online programming environment for coding education. Illustration of VEXcode VR robot features, showcasing the virtual robot's design and capabilities within the online programming environment, highlighting its applications in STEM education and coding concepts.
VEXcode VR Python
def main():
drivetrain.drive_for(FORWARD, 300, MM)
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive(FORWARD)
while not down_eye.detect(RED):
wait(20, MSEC)
drivetrain.stop()

In this example on the Castle Crasher Playground, the VR Robot will drive until the red border is detected by the Down Eye Sensor.

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

Last Updated: