colour sensor to RGB converter

Dicky Mint

Senior Member
Hi

I'm trying to build a proof of concept of a colour sensor to RGB LED converter!

What I'm trying to do is use an LDR to sense reflected red, green and blue light from Superbright LEDs then use this
information to pwm an RGB LED.

I've built a prototype module on a PCB and it responds after a fashion

I'm a bit stuck and would appreciate some help or a push in a right direction?

I've tried to calibrate using black, white and coloured cards but in practice the RGB LED appears to light at random!

How can I calibrate it to sense the coloured LEDs reflections and ignore the other colours?



My program is as follows:-

[#picaxe20M2

;Test Program for electronic Chemeleon 06
;13/2/13 Rick HSI-Inc

symbol RED_LED = B.3 ;assign names to pins
symbol GREEN_LED = B.2
symbol BLUE_LED = B.1

symbol RED_RGB = C.5
symbol GREEN_RGB = C.3
symbol BLUE_RGB = C.2

symbol LDR = B.0

main:

high RED_LED
Pause 333
readadc LDR,b0 ;measure amount of reflected RED light

let b0 = b0 - 95 * 10 ;scale LED brightness response

pwmout RED_RGB,255,b0 ;signal to control brightness of RGB LED
low RED_LED


high GREEN_LED
Pause 333
readadc LDR,b1

let b1 = b1 - 95 *10

pwmout GREEN_RGB,255,b1
low GREEN_LED


high BLUE_LED
pause 333
readadc LDR, b2

let b2 = b2 - 65 *5

pwmout BLUE_RGB,255,b2
low BLUE_LED
debug ;press F8 to show variables screen
Pause 333 ;blank all LEDs

goto main]

I'll post a circuit diagram and a photo if that would help?

Rick
 

BeanieBots

Moderator
Your method (if I've understood it correctly) is the opposite to how it's 'normally' done but does rely on the assumption that what appears to be say 'green' will only reflect green light.
The more normal method is to use a single source (eg white LED) and have three sensors that are sensitive to restricted wave lenghts (eg red, green and blue).
You could still use a cheap and simple sensor such as LDR but you will need three of them each with a colour gel in front of it to make it sensitive to a very restricted range.

As for calibration, this is a very complex arena with only very vague rules and a lot of subjectivity.
"Beauty is in the eye of the beholder".
You need to create what is known as a "colour space" index.
This is how things like colour monitors are 'calibrated' against a 'known' colour.
Unfortunately there is no standard (that is agreed on) that you can use to say "my sensor is calibrated".
That's why some monitors/tellys not only appear different but may also be preferred by one person but not by another.

So, long story short.
Get a set of values from your sensor(s).
Create the same colour (as appears to you) with the RGB LED.
Devise a formula/function that will map several results correctly or use a very large lookup table.
It is totally subjective and nobody can say you got it wrong or right except you.
 

Dicky Mint

Senior Member
ok that's sorted that then!

Sounds like a lot of work with a probably dubious outcome?

I'll try the other way round as I've got some coloured gels.

In a way I'm pleased as now I know its not a trivial task which I have failed to envisage?

while I'm here.. are some RGB LEDs better than others wrt colour mixing as atm I've got three defined colours with little mixing?

Rick
 

boriz

Senior Member
I think you're going about it basically the same way I would, if I were to brew my own. Some things to consider:

Ambient light: LDRs are very sensitive and for a good result you must find a way to exclude all but the colour under test.

Consistent range: The sensor module must always be at exactly the same range from the test surface. Varying even just a little will skew the results.

Bleedthrough: You must be absolutely sure that no light can get directly from the LEDs to the sensor. It must ALL be reflected.

LDR specrum: An LDR has similar spectral sensitivity to the human eye, which means for example it is more sensitive to green than to blue. You will need to compensate for this by biasing your readings somehow.

LED brightness: Not all LEDs are created equal. (Even if it says so on the packet). You will need to carefully adjust/calibrate the LED currents so you are getting similar outputs for the detected brightness of different colours. EG: A pure blue test card and a pure green test card, judged by yourself to be of equal brightness, should produce equal readings.
 

westaust55

Moderator
Another point to be aware of is the different sensitivities to different colours.
Whether you use a white light and three different colour receptors (as per many commercial modules) or an RGB LED and singleight sensor, there will be different levels for the final signal that require calibration/accounting for.
 

boriz

Senior Member
One more thing to consider:

If you are using the simple divider circuit, with the LDR and a resistor in series between the power rails, there is a non-linearity introduced. The brighter the light, the lower the LDR reistance, the greater the current flow. So a small change in brightness when the output's near one end of the range will produce a larger response than an identical change when the output is near the other end of the range. It becomes less and less sensitive to change as the current increases.

For best sensitivity and linearity you should replace the divider resistor with a constant current source. This however will mean your range is reduced, so careful selection of the LDR current will be needed and possibly a range switch (Picaxe automatically changes LDR current between two fixed levels according to required sensitivity)
 

Kecked

Member
Trick led

One more thing to consider:

If you are using the simple divider circuit, with the LDR and a resistor in series between the power rails, there is a non-linearity introduced. The brighter the light, the lower the LDR reistance, the greater the current flow. So a small change in brightness when the output's near one end of the range will produce a larger response than an identical change when the output is near the other end of the range. It becomes less and less sensitive to change as the current increases.

For best sensitivity and linearity you should replace the divider resistor with a constant current source. This however will mean your range is reduced, so careful selection of the LDR current will be needed and possibly a range switch (Picaxe automatically changes LDR current between two fixed levels according to required sensitivity)
You can use LEDs as the detectors as well. This way they are selective to themselves in terms of wavelength. Bear in mind (growl) that the more points you use in the formation of the final color the better it will work and that reflected light doesn't translate to transmitted light. You lo need a frosted white plastic in front of the LEDs making light to mix the colors together.
 
Top