Color Sensor not working in Grayscale

I have spent all day trying to write a program to drive forward until the color sensor detects a black line (using grayscale values), then stop. I am using the new RobotC Graphical programming. I have tried using the code on page 20 of the Introduction to Programming VEX IQ with ROBOTC4 Users Guide, and I have tried my own version. Nothing works correctly.

If the color sensor is in the default port 9, the sensor will not turn on the LED light, and the sensor will not control the motors. It does see values, and I can see them in the sensor view pane during the debug process. The values do change when I move the sensor over different colors.

If the color sensor is in a different port (port 2, for example), the LED light will turn on, but the sensor will still not control the motors.

I did get the color sensor to work correctly in port 9 using the “Basic Line Track Left” function (sensor mounted under chassis about 1/4 inch above table). The light turns on, and detects black, and runs the motors. I did get the color sensor to detect the line using “GetColorHue” in port 9, mounting the sensor about 3 inches above the table. The hue function doesn’t use the LED light.

How can I get the sensor to turn on the LED light and stop at a black line using grayscale values? What am I doing wrong?


Hi Linda,

We’re sorry that you are having this issue. After looking further into it, this appears to be a bug in the latest version of ROBOTC Graphical programming environment. ROBOTC is working to correct this problem now.

In the meantime, this problem can be resolved by going to View > Convert Graphical File to Text. In the text editor, delete the setRobotType line. Then change the “colorSensorNL” in the repeatUntil block to “port9”. The code (shown below) will now work.

#pragma config(Sensor, port9,  ,               sensorVexIQ_ColorGrayscale)
#pragma config(Motor,  motor1,           ,             tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor,  motor2,           ,             tmotorVexIQ, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
    repeatUntil(getColorGrayscale(port9) < 100) {
    setMotor(motor1, 50);
    setMotor(motor2, 50);


  • Art

Hey Linda, We have a new version of ROBOTC available (it’s an internal development build) that changes quite a bit with graphical to allow any robot types/configuration to work with the graphical interface. If you wish to try out this new version, please e-mail me at and I’d be happy to send you an early version to try.