Color sensor with LDR + RGB

Hi guys, Im trying to build a Color sensor with an LDR and RGB LED , i did some researches and i found an exciting website that shows you how to do it, but i still did not get all what is there beacause Im still new in this :confused: So i have two questions :

First is, where did he place the photoresistor and how it placed with the RGB inside that 'cover' ?

And second, i did not really get the code, is it for just the sensor or for the whole project ? if so, can anyone help me with the schematic :confused: ?

thank you guys, it would be really great if you can help me to build this project

Here is the website : http://www.georgegardner.info/arduino/photoresistor-color-sensing-with-the-arduino.html/comment-page-2#comments

First is, where did he place the photoresistor and how it placed with the RGB inside that 'cover' ?

Well you can't see it at all can you?
It looks like he might be using the LED as a photo sensor, there is no photo resistor in that circuit. Unless it is that pot with the arrow pointing in the wrong direction.

However I agree with you it is quite a piece of crap to put out on the internet.

The code looks like something has mangled it and changed the < symbol to '<' this is it corrected.

// Color Match
// January 28, 2012
// by George Gardner

int pwmrgb[] = {11, 9, 10}; //sets the r,g,b cathode pins for the pwm led (must be pwm pins)
int rgbbias[] = {100, 15, 0}; //sets the bias for the illuminated RGB LED: higher number = less intense (max 255)

int rgbds[] = {255, 255, 255};
int maxwhite[] = {773, 624, 542};
int minblack[] = {309, 134, 104};

int sensorValue = 0;

int speed = 5;

void setup(){
pinMode(2, OUTPUT); //sensor red cathode
pinMode(3, OUTPUT); //sensor green cathode
pinMode(4, OUTPUT); //sensor blue cathode
Serial.begin(9600);
for(int i = 2; i< 5; i++) {
 digitalWrite(i, HIGH); 
 analogWrite(pwmrgb[i-2], 
 rgbds[i-2]);
 } 
} 


void loop(){
  int switchstate = analogRead(A5); 
  
  if(switchstate > 1000){
    for(int i = 2; i < 5; i++){
      digitalWrite(i, HIGH);
   analogWrite(pwmrgb[i-2], 255);
}
delay(1000);
switchstate = analogRead(A5);
while(switchstate < 1000){
switchstate = analogRead(A5);
}
delay(500);
}

for(int i = 0; i< 3; i++){
delay(100);
digitalWrite(i + 2, LOW);
delay(100);
sensorValue = analogRead(A0);
rgbds[i] = constrain(sensorValue, minblack[i], maxwhite[i]);
rgbds[i] = map(rgbds[i], minblack[i], maxwhite[i], 0, 255);
printresults(i);
rgbds[i] = (255 + rgbbias[i]) - rgbds[i];
rgbds[i] = constrain(rgbds[i], 0, 255);
digitalWrite(i + 2, HIGH);
}

for(int i = 0; i< 3; i++){
analogWrite(pwmrgb[i], rgbds[i]);
}
delay(speed);
}

void printresults(int i){
if(i == 0) Serial.print("RED: ");
if(i == 1) Serial.print("GREEN: ");
if(i == 2) Serial.print("BLUE: ");
Serial.println(rgbds[i]);
}

However that page is so poor I would look for a better one, it is quite a simple concept.

Yes, Im trying to find something else like that . thank you for your help :slight_smile: also the symbole > changed to >

it's just that i like the aesthetic of his project actually, and the color sensor that he made is so small too !
but as you said the page is so poor :confused:

I don't see how that can possibly work... You usually need 3 light sensors and 3 color-filters, or one sensor and a color wheel filter.

How this works is the RGB LED lights each color in rapid succession while recording the value of the photoresistor for each color. A color, say for instance red, will reflect a red light better than it will reflect any other color.

What? ...So you have to turn-on one LED at a time and read the light level. That's a silly thing to do, since if you (or your program) is controlling the RGB LED, you (or your program) already knows the color and the brightness of that color.

And, he says:

It doesnโ€™t work as well as a color sensor would, but the results are surprising.

P.S.
OK, I get it... He's looking at a color of a surface/object, not the color of light..... You hit the surface with one color at a time (while shielding outside/ambient light) and read the reflection of each color, one color at a time. That should work but you probably have to be careful with glossy surfaces... Maybe be careful about the angle of reflection and/or maybe diffuse the source or reflection.

You usually need 3 light sensors and 3 color-filters, or one sensor and a color wheel filter.

Those are ways but this is another way.

So you have to turn-on one LED at a time and read the light level.

The idea is to turn on the red LED and then use the photo resistor to measure the reflected light. The sensor must be shielded from the direct light of the LED. Do the same for the green and blue LEDs, so one sensor takes three measurement under three different illumination conditions.

The method is valid only the implementation and the documentation is very poor.

hi everybody, my project is night of lamb but sound sensor and LDR I don't know how is use together this sensors.
for example, daylight not working but at night just output sound and working RGB colorfull please can anybody help me

Please read this:-
How to use this forum
Because your post is breaking the rules about hijacking a thread.