Raw RGB data to Color?
Not sure what language you are using, or calls you are making before this, but:

float var_Min = var_R; if (var_G &gt; var_Min) var_Min = var_G; if (var_B &gt; var_Min) var_Min = var_B;


Should be (note the use of &lt; rather than >)

float var_Min = var_R; if (var_G &lt; var_Min) var_Min = var_G; if (var_B &lt; var_Min) var_Min = var_B;


Your posted code is putting the maximum value into the minimum variable, messing up things down the line...

Another thing that will help is to not use the RawColorSensor call. Change your main task to this:

ColorSensorReadType csr;

task main(){
   csr.Port=S3;
   SetSensorColorFull(csr.Port);
   while(true){
       SysColorSensorRead(csr);
       RGBToHSL();
   }
}  


And the first few lines of your RGBToHSL call to this:

R = csr.NormalizedArray[0];
G = csr.NormalizedArray[1];
B = csr.NormalizedArray[2];


This will normalize the values between the values of 0,255 (or at least roughly). I've had more luck with this call since it also tries to calibrate the values.

After this, you'll need to find the color values you're using with a tool like http://www.colorpicker.com/ . For example, orange would have HSV (HSB on that site) of (40,100,100). (The scaling on these values may differ). So, to detect orange, check if:
Hue>30 AND Hue&lt;50 AND saturation>90 AND value>90.
Make sure there is play with your thresholds, otherwise the check will work once in a hundred tries.