Color sensor reliable? I am experimenting with the light sensor shipped within the mindstorms ev3 package.

My Problem is that the bot is standing quiet at one place. Each value returned by sensor is different, although the bot is not moving. Why? :-(

I am using the Red mode:

SensorMode t = sensor.getRedMode();

float[] sample = new float[1]; 
t.fetchSample(sample,0);
return sample [0];


I tried putting the sensor in different positions and tried different distances to the floor. When it is on a black line the values differ a lot. 

Which sensor modes do you guys use for getting reliable information about underground colour? Or let's say underground brightness?
Light sensors are mainly affected by three independent variables:  


Distance between the sensor and the surface  
Color of the surface  
Amount of ambient light  


What this means is, in order to measure one of these things, the other two variables must be held constant. So, in order to measure color, the distance must be constant and the ambient light should be constant.  

You can maintain a constant distance between the sensor and the floor by attaching the sensor, pointing downward, to a fixed point on the robot. Simple enough. In my experience the sensor should be about 1cm from the floor for best results.  

You can maintain a constant ambient light by avoiding shadows or bright lights. If this isn't possible, you can build a shroud over the sensor to block out external light. You should also recalibrate the sensor at program startup to account for ambient light.  

After doing the previous two things, you can measure the reflected light from the surface by shining one of the colored LEDs and taking a sample. Using only 1 LED should be sufficient to detect differences in grayscale, but to actually measure "color" you can quickly cycle between the Red, Green, and Blue LEDs, taking samples with each, to get a crude estimate of the RGB components of the surface.