How to grab the color from RGB code fetched from LDR?

Hello,

I have an assignement that I'm struggeling with :

I need to use a Pololu Zumo 32U4, and a color sensor made from LDR + RGB LED (schematic attached)

I'm able to successfully fetch the RGB codes (see the code)

Code (too long to fit on the post message)

But I actually need to recover the color that that RGB code signify

I have a checkerboard with 6 colors which are [Black, White, Red, Green, Blue and Yellow], and the robot will need to make a specific action after having scanned the color

Black and White will not be an issue though as Black report as ~{0,0,0} and White ~{255,255,255} due to the calculation method used

But the issue here is the other 4 colors, especially Yellow

I was thinking about a percentage-based method but the yellow will effectively not work as it will only use the three primary color and I couldn't find the minimal percentage of Red and Green needed for that color to be actually Yellow

If someone had an idea that would be awsome

Thanks in advance

What are the RGB values for each of the colours ?

I can't know for sure actually, I need to make a range that will lock the color, as the sensor is not that precise and very sensible to environement light

Oh, I just found a way while typing that, I'll retake mesures when I'll be able and setup ranges (That yellow will still be an issue though)

Thanks anyway

You have to set ranges indeed, and do consider shielding your sensor setup from ambient light as it will otherwise seriously mess up your readings.

Maybe sum the RGB values read by the sensor like this

unsigned long value = (R << 16) + (G << 8 ) + B;

then testing whether the result is in one of the required colour ranges having derived the ranges by empirical measurement

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.