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.


#include <Wire.h>

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

void setup()
    // Initialise I2C communication as MASTER
    // Initialise serial communication, set baud rate = 9600

    // Start I2C Transmission
    // Select mode control register1
    // Set RGBC measurement time 160 msec
    // Stop I2C Transmission
    // Start I2C Transmission
    // Select mode control register2
    // Set measurement mode is active, gain = 1x
    // Stop I2C Transmission
    // Start I2C Transmission
    // Select mode control register3
    // Set default value
    // Stop I2C Transmission

void loop()
    unsigned int data[8];
    for(int i = 0; i < 8; i++)
        // Start I2C Transmission
        // Select data register
        // Stop I2C Transmission
        // 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] =;

    // 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.print("Green Color luminance : ");
    Serial.print("Blue Color luminance : ");
    Serial.print("Clear Data Color luminance : ");


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".

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.