Help with TCS3471 Color Sensor I'm a noob.

Hi, I´m new in the world of programming and robots, and I need to sense color green. I have this sensors (http://5hertz.com/index.php?main_page=product_info&cPath=12_13_153&products_id=744) but I don´t know how to program them.

I´ve seen this library from gitHub (https://github.com/raivisr/TCS3471-Arduino-Library) but still don´t get it.

How do I integrate that in my program, I just need to make a function like isGreen(); and return HIGH if green, I am not asking you to make the function and share it (I´ll appreciate if you do that) but I´m really looking forward to understand how it works

Thank you.

Look at the example in that library

It clearly shows how to determine when a colour is ready and also reads in the three colour components, red green and blue

However what you call "green" is a issue of perception and you are unlikely to ever read a colour value of RGB

0,255,0

I'd run the sample and look at its output for the green things you want to measure versus the non green things.

This will help you determine an algorithm to convert the RGB values to a Boolean for green items

Thank you, but what I don't understand is the interrupts, maybe that's just i2c basics but I'm really hurried because we have 4 day to finish our robot and Between the shoot and homeworks I don't have enough time to learn i2c, or dou you know an easy explanation?

I'm thinking in making a function isGreen( ) an inside the function place the example code the part that is inside of if (colorAvailable) {} and add some stuff to check if green is higher than red and blue, but I don't know is if the function readGData() returns any other thing than a Word variable, or how can I get a value from 0 to 255

Magdiel:
but I don't know is if the function readGData() returns any other thing than a Word variable, or how can I get a value from 0 to 255

Do you know what a word is? Read the documentation on the sensor, what is the maximum value that will spit out? Scaling that down to 255 should just be a matter of division (or a bitshift if you're smart).

My values of 0 to 255 were just an arbitrary example.

I don't have the particular piece of hardware that you do. So I can't comment on exactly what values get returned in the word data type from that function e. readGData

Regardless of that, I doubt that your simplistic approach of just comparing green to red and green to blue will work without defining a threshold e.g. An relative offset between green and red or green and blue

E.g.

I doubt your eye would perceive. A RGB colour of 128,129,128 as green, even though the green channel is higher , you would see this as grey

Colour perception theory is a science in its own right, but if collect enough data you can probably work out an algorithm for the things you want to measure

And how can I transform a word variable to a value from 0 to 255 to make the decisions easier for me, because it gives me big values, how can I convert them to an hex color value like ff0033 or something like that?

I'm not sure why you'd want to do this, but either use Serial.print(value,HEX) or look at sprintf()

However on AVR sprintf is somewhat limited and may not support HEX

I need to check if the sensor is over something green, but after checking it over a variety of object but I don´t see any major difference in the values from blue and green. And I don't understand those values and I´d like to see them in a range from 0 to 255 to plot them or vie a color generation and use those values, then see what is the color the sensor detected in a graphic way

it would help everyone if you'd share your data

e.g show us what values you collected

This are the values that it throws when I placed the sensor like 2 or 3 cm above a yellow Post-It (Image attached) end when i place the RGB values in an Hex to RGB converter it says its kind of brown and when I repeat that process over a white plastic table, a blue pencil box and the greenish Arduino box it is always a brown color

Are you missing something like a lens to focus the image into the sensor?

What lighting are you using, sunshine, or indoor lighting , you will not get good results using light from sources like low energy lamps as they don’t have the full spectrum of light.

Btw. You can cut and paste text from the serial window. Screen grabs are not that helpful

You should collate you data which you cut from the serial window into a spreadsheet