How to convert RGB values in different colors.

Hi, I am new to the sensor coding.

I am using this color sensor to detect the RGB values.

Because RGB are primary colors So anyone can help me how can I convert these values to detect the different colors.

Code

#include <Wire.h>

// I2C address of the BH1745NUC
#define Addr 0x38 

void setup()
{
    // Initialise I2C communication as MASTER
    Wire.begin();
    // Initialise serial communication, set baud rate = 9600
    Serial.begin(9600);

    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register1
    Wire.write(0x41);
    // Set RGBC measurement time 160 msec
    Wire.write(0x00);
    // Stop I2C Transmission
    Wire.endTransmission();
    
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register2
    Wire.write(0x42);
    // Set measurement mode is active, gain = 1x
    Wire.write(0x90);
    // Stop I2C Transmission
    Wire.endTransmission();
    
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register3
    Wire.write(0x44);
    // Set default value
    Wire.write(0x02);
    // Stop I2C Transmission
    Wire.endTransmission();
    delay(300);
}


void loop()
{
    unsigned int data[8];
    for(int i = 0; i < 8; i++)
    {
        // Start I2C Transmission
        Wire.beginTransmission(Addr);
        // Select data register
        Wire.write((80+i));
        // Stop I2C Transmission
        Wire.endTransmission();
        
        // Request 1 byte of data from the device
        Wire.requestFrom(Addr, 1);
        
        // Read 8 bytes of data
        // Red lsb, Red msb, Green lsb, Green msb, Blue lsb, Blue msb
        // cData lsb, cData msb
        if(Wire.available() == 1)
        {
            data[i] = Wire.read();
        }
        delay(300);
    }

    // Convert the data
    int red = ((data[1] & 0xFF) * 256) + (data[0] & 0xFF);
    int green = ((data[3] & 0xFF) * 256) + (data[2] & 0xFF);
    int blue = ((data[5] & 0xFF) * 256) + (data[4] & 0xFF);
    int cData = ((data[7] & 0xFF) * 256) + (data[6] & 0xFF);
    
    // Output data to serial monitor
    Serial.print("Red Color luminance  : ");
    Serial.println(red);
    Serial.print("Green Color luminance : ");
    Serial.println(green);
    Serial.print("Blue Color luminance : ");
    Serial.println(blue);
    Serial.print("Clear Data Color luminance : ");
    Serial.println(cData);

}

I want this output to convert into different colors.

Thanx for the help in advance.

Please edit your post to add code tags, as described in "How to use this forum".

Explain or give an example of what you mean by "convert into different colors".

jremington:
Explain or give an example of what you mean by "convert into different colors".

Glad it's not just me who didn't understand... the rgb mixes are the different colours.

I simply want to detect the different colors using that sensor, but I have that above code which is giving the RGB values(RED, GREEN, BLUE).

As we know that these are the primary colors and we can make any color using these three colors.

So my question is can I convert these colors to detect multiple colors

Maybe I'm just being thick today (or thicker) but I still have no idea what you mean.

You have an object of some colour, perhaps it's pink or grey or royal blue or British Racing Green. The sensor looks at that and says it consists of so much each of red, green and blue.

What do you want to happen next?

Please explain what you mean by "detect multiple colors", using some examples.

The sets of RGB values ARE the colours.

A simple comparison might look like this:

  if(green > 127) Serial.println("Object is green");

A bright white object has that same amount of green but "obviously" does not look green to your eye.

Convert to the HSV color space and then Hue "is the color" without the brightness information that confuses the simple comparison.