Skip to main content
Teacher Portal

Sort Colors Example

Teacher Toolbox icon Teacher Toolbox - Facilitating the Sort Colors Example Page

What the Teacher Will Do:

  • Instruct students that they will be working together in their groups to follow the steps on this page.
  • Circle the classroom as students work through these steps and answer any questions that arise.
    • These steps involve a lot of project modification and changes. Check with students as you circle the room to see if they need any assistance with following the instructions. Tips for how to support students during these steps are provided in a Teacher Tips box below.
  • As groups check in, ensure they have built their project correctly before moving on. Guidance for this check in is provided in a Teacher Toolbox at the bottom of this page.

Now that you have recorded the locations of Points 1-5, you will open the ‘Lab 7- Sort Disk’ project from the previous Lab. The ‘Lab 7- Sort Disk’ project utilizes [If then else] blocks. We will restructure and rename the project to use [If then] blocks to determine how the arm on the Workcell should move once it detects a certain color using the Optical Sensor.

In VEXcode V5, follow the steps in this video to open the 'Lab 7- Sort Disk' project, select 'Save As,' and name the new project as 'Lab 8- Sort Colors.'

For Your Information

The [If then] block is a block that is based off of conditionals.

  • If the condition of the [If then] block is reported as true, the blocks inside of the [If then] block will run.
  • If the condition of the [If then] block is reported as false, the blocks inside of the [If then] block will be skipped.

callout fyi

Follow the steps in this video to add a {When brain screen} block and two [If then] blocks to the project.

Once you have added a {When brain screen} block and two [If then] blocks to the project, add additional blocks to create the stack of blocks shown in this image.

build a project

Follow the steps in this video to delete the stack of [Print] blocks that prints the colored buttons on the Brain’s screen.

Also delete the stack of blocks used from the previous project to pick up a red disk using the buttons on the Brain's screen. This stack of blocks is no longer needed now that you have created the new stack of [If then] blocks that will trigger the arm's movements based on pressing the Brain's screen.

For Your Information

The V5 Optical Sensor mounted on the Workcell is a sensor used to detect the color of an object as well as if an object is near or far away from the sensor. In this Lab, the Optical Sensor will be used to distinguish the color of disks. For more information on the V5 Optical Sensor, view this article from the Knowledge Base.


Follow the steps in this video to add the Optical Sensor to the robot configuration.

For Your Information

When the Optical Sensor is added to the robot configuration, blocks from the 'Sensing' category appear in the Toolbox. Two of these blocks are the [Set optical light power] block and <Optical detects color> block.

  • The [Set optical light power] block will be used to set the power of the light in the Optical Sensor to 100%. This is used to improve the accuracy of the color detection by providing a consistent light source.
  • The <Optical detects color> blocks will be used in conjunction with the [If then] blocks to trigger the arm to perform certain behaviors based on the color of the disk that the Optical Sensor detects.


Now that the Optical Sensor has been added to the configuration, follow the steps in this video to add a [Set optical light power] block and <Optical detects color> blocks. 

Teacher Tips icon Teacher Tips


  • Check in with each group to make sure they selected 'Save As' before naming the project 'Lab 8- Sort Colors.' If groups do not chose 'Save As' and continue working, they will overwrite their Lab 7 project.

Save As button in VEXcode V5

  • As students add and remove blocks, they may make a mistake that they want to undo. Show them how to open the context menu and select 'undo,' or direct students to this Knowledge Base article.

context menu

  • Direct students who need additional reminders of what each block does to the Help in VEXcode V5. They can follow the steps in this Knowledge Base article to see how to access the Help.
  • If any students need help adding [Comment] blocks, direct them to this Knowledge Base article.

Teacher Toolbox icon Teacher Toolbox - Check in

 Review the following with the group during their check in:

  • Ensure groups have built their project correctly. All groups should have the same elements in their projects, but because of the restructuring and deleting stacks of blocks, the layout of where stacks are placed may differ slightly from one group to another.
  • Check that all groups have configured the Optical Sensor in Smart Port 6 and changed the [Set optical light power] and <Optical detects color> blocks to the parameters shown.

optical sensor blocks