Using the VEX IQ (1st gen) Color Sensor

The Color sensor uses reflected light to detect an object’s color, hue value, grayscale value, brightness, and proximity.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational robotics projects.

The VEX IQ Color Sensor is included in the VEX IQ Super Kit and can also be purchased here.

Using a 2nd Generation VEX IQ Robot? See an overview of 2nd Generation sensors here, and information on the Optical Sensor, the 2nd Generation version of the Color Sensor.


Description of the Color Sensor

The VEX IQ Color Sensor has multiple modes, which allow it to capture different types of information from its environment. The information it collects is affected by the lighting conditions of its environment as well as the distance between the sensor and the object or surface it is reading.


Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational robotics projects.


How the Color Sensor Works

The Color Sensor can detect both color and proximity.

Detecting Colors

Diagram of VEX IQ sensors, illustrating various types and their functions within the VEX IQ Robotics platform, designed for educational purposes and beginner robotics enthusiasts.

Diagram illustrating various VEX IQ sensors, including their placement and connections, to aid in understanding the components of the VEX IQ Robotics platform for educational robotics projects.

When in brightness mode, the Color Sensor is used to detect the intensity of all light in the robot’s environment. The more light that reaches the Color Sensor while it's active, the higher the percentage value sent to the Robot Brain.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational robotics projects.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections within the robotics system for educational purposes.

If the detected brightness percentage is low or unreliable, the Color Sensor’s lamp can be turned on or the lamp’s brightness percentage can be raised by using the following set light to block:

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections within the system, aimed at aiding educators and students in understanding robotics concepts.

The Color Sensor can report the color it sees as either a color value or as a hue value.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their components and functionalities for educational robotics applications.

Color values. There are 14 listed colors that the Color Sensor can detect. The colors missing from the image of the block are red, green, blue, white, and yellow.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections, designed to aid educators and students in understanding robotics concepts and enhancing project development.

Hue values. Hue values are like color values but numerical. The hue value ranges from 0 to 360, like degrees. The color values listed above have their own equivalent hue value ranges. 

It is important when detecting colors and hues that the Color Sensor have the proper amount of light to do so. Be sure to test, also known as calibrating, your Color Sensor in different levels of light and with the lamp set at different levels to determine which is the most reliable setting for your robot’s Color Sensor.

Detecting Proximity

The Color Sensor includes an infrared sensor-emitter. The infrared emitter shines an invisible light and then detects its reflection. If most of the infrared light bounces back toward the sensor, it tells the Robot Brain that an object is close.

Diagram showcasing various sensors used in the VEX IQ Robotics platform, illustrating their placement and functionality for educational robotics projects.

Common Uses of the Color Sensor

Color sensors are used in many technology applications where having specific colors on displays or products is important.

Some common uses in daily life include:

  • Color calibration tools check if a digital screen is displaying accurate colors, and then adjust the display settings as needed. It is important for graphic artists and any designer who works with color on a digital screen to be able to see exactly the correct color being displayed. Misunderstandings and wasted resources result when the colors are not accurate.
  • Cameras and camcorders use color sensors to adjust settings based on the lighting conditions they are in, in order to enhance their photos and videos by maximizing light levels and enhancing otherwise dull colors. These sensors also allow a photographer to focus on specific colors in their photos.
  • Color sensors are sometimes used in manufacturing, to quickly inspect if a product has the correct color before it gets shipped to a customer. For example, fruits and vegetables that turn colors when ripe or ready to be eaten can be scanned to ensure that they are the correct color to send to market. 


Some common uses with a VEX IQ Robot include:

  • This sensor can be used to detect the color of an object.

  • This sensor can be used to detect and/or follow a line.

  • This sensor can detect whether an object is near.

Color Sensors on a Competition Robot

Remember, it is important when detecting colors and hues that the Color Sensor have the proper amount of light to do so. Be sure to test, also known as calibrating, your Color Sensor each time you arrive at a new competition site because different levels of light can affect how your Color Sensor performs. Test your project with the lamp set at different levels to determine which is the most reliable setting for your robot’s Color Sensor. 

The information collected by the Color Sensor is useful for programming a competitive robot to respond to a variety of conditions. The Color Sensor can make a competition robot better in the following ways:

  • It lets the robot detect the color of an object near the sensor. This is useful if you want the robot to sort differently colored objects, drive up to a specifically colored object, or detect the color of objects as they pass by the sensor.
  • It lets the robot detect how much light is reflected back into the sensor. This allows your robot to drive until it reaches a line on a surface, or even to follow a line.
  • It lets the robot know whether an object or surface is near. This is helpful in determining whether a detected color is a reading from a nearby object or potentially, an anomalous reading of a distant surface or light. 

Coding the Color Sensor in Blocks

Diagram showcasing various sensors used in the VEX IQ Robotics platform, illustrating their placement and functionality for educational robotics projects.

The <Found an object> block is a Boolean reporter block that reports a condition as either true or false. Boolean blocks, like the <Found an object> block fit inside blocks with hexagonal (six-sided) inputs for other blocks.

The <Found an object> Boolean block reports 'true' if the 'true' if the Color sensor detects an object, and 'false' if the sensor does not. To learn more about Boolean blocks visit the Help or the Block Shapes and Meaning article.

 

Diagram illustrating various sensors used in the VEX IQ Robotics platform, showcasing their placement and functionality to aid educators and students in understanding robotics concepts and enhancing project development.

In this example, the <Found an object> block is used to detect proximity along with a [Wait until] block, to make the robot drive forward until an object is detected.

Diagram illustrating VEX IQ sensors, highlighting their types and functions within the VEX IQ Robotics platform, designed for educational purposes and beginner robotics enthusiasts.

The <Color detects> block is also a Boolean reporter block that reports a condition as either true or false. The <Color detects> block reports 'true' if the 'true' if the Color sensor detects the selected color and 'false' if the sensor detects any other color. To learn more about Boolean blocks visit the Help or the Block Shapes and Meaning article.

 

Diagram illustrating VEX IQ sensors, showcasing various types and their applications in robotics, designed to support educational purposes and enhance understanding of sensor integration in VEX IQ projects.

In this example, the <Color detects> block is used along with a [Wait until] block to cause the robot to drive forward until the Color Sensor detects a green object. The robot will then stop driving. This is illustrated in the first video above.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, showcasing their placement and functionality to enhance robotics education and project development.

The (Brightness of) block reports the amount of light detected by the Color Sensor. It is a reporter block used inside other blocks with circular spaces.

The (Brightness of) block reports a range of 0% to 100%.

 

Diagram showing various VEX IQ sensors, including distance, color, and gyro sensors, used in robotics projects for educational purposes.

In this example, the (Brightness of) block is used to have the robot detect and follow a line, as shown in the second video above.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections, designed to support educational robotics projects and enhance understanding of sensor integration in robot building.

The (Hue of) block reports the hue of the color detected by the Color Sensor. It is a reporter block used inside other blocks with circular spaces.

The (Brightness of) block reports a range of 0 to 360.

 

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections, designed to enhance educational robotics projects for beginners and support learning in programming and building robots.

In this example, the (Hue of) block is used to have the robot check a range of hue values that correspond to the color red, and to turn right for 90 degrees if those values are detected by the sensor. If any other hue values are detected, the robot will turn left for 90 degrees.

The (Hue of) block can be useful when it is necessary for the robot to detect certain colors when ambient light conditions may be inconsistent.

Coding the Color Sensor in Python

Note: To code an VEX IQ (1st generation) Bumper Switch in Python, it must be connected to a VEX IQ (2nd generation) Brain. The VEX IQ (1st generation) Brain does not support Python.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections, designed to aid educators and students in understanding robotics concepts.

The color.is_near_object command reports True when a Color sensor detects an object or surface close to the front of the sensor and False when a Color Sensor does not detect an object or surface close to the front of the sensor.

Note: The name of the Color Sensor that appears in the command corresponds to the name it is given in the configuration. 

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections within the system, aimed at enhancing educational robotics experiences for beginners and educators.

In this example, a While loop with a not condition is used with the color.is_near_object command to make the robot drive forward until the the Color Sensor detects an object close to the front of the sensor.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, showcasing their placement and function within robot designs, aimed at enhancing educational understanding of robotics components and programming.

The color.color command reports the color currently being detected by the Color Sensor.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational and beginner robotics enthusiasts.

In this example, a While loop with a not condition is used with the color.color command to make the robot drive forward until the Color Sensor detects a green object. The robot will then stop driving. This is illustrated in the first video above.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections to enhance robotics education and project development.

The color.brightness command reports the amount of light detected by the Color Sensor. It reports a range of values from 0% - 100%.

Diagram illustrating various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational robotics projects and programming.

In this example, the color.brightness command is used to have the robot detect and follow a line, as shown in the second video above.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections for educational robotics applications.

The color.hue command reports the hue of the color detected by the Color Sensor. It reports a range of hue values from 0 to 360.

Diagram illustrating the various sensors used in the VEX IQ Robotics platform, highlighting their functions and connections within the system for educational and beginner robotics enthusiasts.

In this example, the color.hue command is used to have the robot check a range of hue values that correspond to the color red, and to turn right for 90 degrees if those values are detected by the sensor. If any other hue values are detected, the robot will turn left for 90 degrees.

The color.hue command  can be useful when it is necessary for the robot to detect certain colors when ambient light conditions may be inconsistent.

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

Last Updated: