RGB problem

Okay so i have this code with this project that i want to build.

It is a color sorter.

Problem here is that i don't use the same color sensor but a different one, this one:

And is hell... i cannot get the colosrs that i want becomes everything overlap.

I've only added two colors because everytime that i try to add more to my if statements then nothing works...

Any tips?!

#include <Servo.h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Servo topServo;
Servo bottomServo;
int color;



void setup(void)
{
  Serial.begin(9600);
  topServo.attach(7);
  bottomServo.attach(8);

  if (tcs.begin())
  {
    Serial.println("Found sensor");
  } else
  {
    Serial.println("No TCS34725 found ... check your connections");
    while (1);
  }

}

void loop()
{
  topServo.write(115);
  delay(500);

  for (int i = 115; i > 65; i--) //Picking up a candy to read.
  {
    topServo.write(i);
    delay(2);
  }

  uint16_t r, g, b, c, colorTemp, lux;  //Reading the RGB for the candy.
  tcs.getRawData(&r, &g, &b, &c);
  colorTemp = tcs.calculateColorTemperature(r, g, b);
  lux = tcs.calculateLux(r, g, b);

  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  Serial.println(" ");


  if (r > 7000) //If red is dominante then do something.
  {
    color = 1;
  }
  else if (g > 6000) //If green is dominante then do something.
  {
    color = 2;
  }
  else
  {
    color = 0;
  }
  delay(5000);


  switch (color)
  {
    case 1:
      bottomServo.write(50);    //Change the path and then drop the candy.
      delay(300);

      for (int i = 65; i > 29; i--)
      {
        topServo.write(i);
        delay(2);
      }
      delay(200);

      for (int i = 29; i < 115; i++)
      {
        topServo.write(i);
        delay(2);
      }
      break;
    case 2:
      bottomServo.write(90); //Change the path and then drop the candy.
      delay(300);

      for (int i = 65; i > 29; i--)
      {
        topServo.write(i);
        delay(2);
      }
      delay(200);

      for (int i = 29; i < 115; i++)
      {
        topServo.write(i);
        delay(2);
      }
      break;
    case 0:
      bottomServo.write(70);
      delay(300);

      for (int i = 65; i > 29; i--)
      {
        topServo.write(i);
        delay(2);
      }
      delay(200);

      for (int i = 29; i < 115; i++)
      {
        topServo.write(i);
        delay(2);
      }

      break;
  }
  //Read again.
  tcs.getRawData(&r, &g, &b, &c);
  colorTemp = tcs.calculateColorTemperature(r, g, b);
  lux = tcs.calculateLux(r, g, b);

  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  Serial.println(" ");
}

And is hell... i cannot get the colosrs that i want becomes everything overlap.

"Overlapping" is probably normal... "Pure" colors don't exist in nature and human perception of color is complicated so your "readings" may not represent what you see. As you probably know your computer monitor is RGB, so if you see yellow it's really red & green... There is no yellow, but your brain says "yellow". If you're looking at an object you can't tell if you're seeing the true color(s) or not.

If you had red & green filters the fake-yellow would get-through, but true-yellow would be blocked. An RGB sensor might not see the true-yellow at all!!! (It probably will, but theoretically it might not.)

So the real question is, can you get different readings with different colors? Are you getting different readings with red & green so you (and the software) knows what to expect with red & green, etc?

Otherwise, make sure the lighting is consistent. You'll probably need to put the color sensor in a box with internal illumination. A regular-old incandescent light is probably best because there is a "smooth" white light spectrum. LEDs & fluorescent lamps can have peaks & dips in the spectrum (although, maybe you can calibrate them out).

Problem here is that i don't use the same color sensor but a different one

That problem is easily solved.

Buy the sensor used in the project.

What values are you seeing for R: G: and B:?

Are the patterns similar for the same color? Are the patterns different for different colors? I would try to determine the average RGB values for each of the colors you are sorting. Then compare the RGB you get with the median RGB for each output category. Find the pattern that most closely matches and use that category.

Calibrate your sensor.

Write simple script that just shows you the measured RGB values. Point your sensor at the various colours you want to detect, and write down the (range of) RGB values you see. Go from there.