Colour Sensor ADJD-S311 with Arduino

Hi,

I'm trying to read 6 different colours using a ADJD-S311 sensor. I'm trying to determine what the paper's colour is.

The problem is that I can have success by determining only 3 colours.
Everything I've been using is from within this link: http://bildr.org/2012/01/adjd-s311_arduino/

I even tried using the EEPROM memory so I can store the values got from calibrateClear, calibrateColors and calibrateCapacitors functions, and then restore them as the system goes online again, in hope that I can catch the good colour.

These are the values I get printed for Red, Green, Blue, Clear:
Red: 250 | 137 | 79 | 906
Green: 124 | 149 | 103 | 760
Blue: 126 | 131 | 150 | 793
Clear: 494 | 460 | 361 | 1023
It's been nearly 6 hours, and still I don't know what the solution could be.

6 hours ? Impatient are we ? 6 hours is nothing here. Wait till your post Reply count is over 100 and then you can start complaining.

The sensor is going to measure the reflectance from the target object in the red, blue and green wavelengths of light. It's not clear what you mean by "clear" ? Do you mean no colour filter on the sensor, or trying to see clear paper ?

What six colours of paper are you trying to measure ?

What you need to do, is test all of your pieces of paper, and determine what values you get from them.

Then,, when you test an unknown piece of paper, and get the answer from it, you choose the colour which is nearest to what you got.

@raschemmel Yeah, I kind of agree with you :smiley:

@michinyon Clear is the brightness. This is how it's called in the sensor's datasheet. The six colours are these: Red, Green, Blue, Orange, Yellow and White. I hardly distinct green from blue. I don't know why. On the other side, the rest of them are pretty okay.

The last setup gave me these values for my colours:
1023 | 1023 | 968 | 1015 on white
997 | 609 | 319 | 582 on orange
676 | 411 | 272 | 405 on red
1018 | 878 | 392 | 692 on yellow
433 | 488 | 356 | 385 on green
426 | 422 | 442 | 384 on blue

I thought of this kind of analysis. What do you think? Provided I have an unknown colour represented by these numbers:

422 | 426 | 308 | 356

Looking at the first number, it seems that it points to blue. So 422 points to blue.
Then we have 426 which sends us to blue again.
Then we have 308 which sends us to orange.
And the last one, 356 sends us to blue.
So the list looks like this:
422 Blue
426 Blue
308 Orange
356 Blue

Looking at orange sequence 997 | 609 | 319 | 582 it clearly indicates that is has nothing to do with the blue sequence 426 | 422 | 442 | 384. Then from the marker I gave to 308 (Orange) I search another one that matches better. I choose red. I compare again the sequence and I find them very different. I search another marker 308 and I find the green sequence. Now the list looks like this:
422 Blue
426 Blue
308 Green
356 Blue

I still have to decide whether the sequence points to green or blue. Looking at the sequence of the unknown colour, green sequence and blue sequence, I find out that the major difference is to be found at the 3rd number in the sequence.

433 | 488 | 356 | 385 on green
426 | 422 | 442 | 384 on blue
422 | 426 | 308 | 356 unknown colour

422 is pretty close to both 433 and 426. So it might be green or blue
426 is more or less close to 422 and 488. So it might be green or blue. More blue in this case
308 is much closer to 356 than 442, besides the difference between 356 and 442 is quite large. It's definitely a green
356 is very close to 385 and 384. So it might be green or blue. The difference is insignificant.

Adding the "colours" we would have this: 4 greens and 3 blues. More greens it means that the sequence represents green.

So 422 | 426 | 308 | 356 points to Green.

Another method would look like this:

Provided we have again this given sequence:
422 Blue
426 Blue
308 Orange
356 Blue

We know Blue is a first order colour, so we'll leave it this way.
Orange, on the other hand is a second order colour. It composes of Yellow and Red. If red wouldn't have been a first order colour, I still wouldn't have had it decomposed into smaller parts because I've already found a primary colour, and it's yellow.
So after all: orange = yellow + red

Now, we have 3 colours, of which all of them primary, and here they are: blue + red + yellow.
If we combine blue and red we get violet. This isn't a colour to be found on my sheets of paper. So it's false thinking that's violet. The last option is by combining blue and yellow, and then we get green. So the sequence points to green.
Maybe this image will help you.

I got to tell you, this sequence was the hardest to be figured out. The rest are in this fashion, but easier to be resolved.

What do you think of these approaches? Which one should I choose? Do you have a better one?

I leave here some data samples, in case you like to toy with them ]:slight_smile:
433 | 512 | 377 | 396
1023 | 898 | 404 | 705
1023 | 1023 | 969 | 1021
669 | 404 | 266 | 402
817 | 509 | 291 | 492
1011 | 878 | 393 | 692
969 | 599 | 319 | 569

This is what I get when I input the first 6 sequences into my computer:

EDIT 1: I think for better results, I should combine both the methods into one, I guess. If both indicate different outcomes, it obligates the system to read again the colour.

You seem very confused.

The last setup gave me these values for my colours:
1023 | 1023 | 968 | 1015 on white
997 | 609 | 319 | 582 on orange
676 | 411 | 272 | 405 on red
1018 | 878 | 392 | 692 on yellow
433 | 488 | 356 | 385 on green
426 | 422 | 442 | 384 on blue

For red paper, the red response 676 is higher than the green and blue response, as it should be.
For orange paper, the red response is also the strongest.
And for yellow.

For the green paper, the green colour response is the strongest.
For the blue paper, the blue colour response is the strongest.

Those figures all look sensible to me. Your device is working.

Distinguishing between them is going to be difficult, because of the inherent differences in reflectance and brightness between the colours. And also because of the way the different pigments work.

I would suggest using a neural net and training it to distinguish the colours.

If that is too hard, I would recommend devising a scheme to normalise the colour readings, which might make the solution more obvious. You are going to have trouble with red and orange, whatever you do.

You need to understand the difference between pigment colour theory and light colour theory.

The absolute level of all those numbers is not important, it is determined by the overall light level.

Your logic should run something like this.

If the blue reading is higher than the red and green sensor reading, the answer is blue.

Otherwise if the green reading is higher than the red, the answer is green.

Otherwise, the red sensor reading is the highest. On your tests, the paper might be red or green or yellow.

If the green number is more than 85% of the red number, it is yellow.

If the green number is more than 68% of the red number, but less than 85%, it is orange.

If the green number is less than 68% of the red number, it is red.