But, even if, the photoresistor is just in front of the led it return always the same value :
1023 for no light ( normal) and 26 for RED/Orange or green light>
You will find my code, below.
Do you have any idea ?
Thanks.
const int ArmP = 5;
const int disarmP = 4;
const int PartP = 3;
const int StatusP = 2;
const unsigned long PRESS_INTERVAL = 3000;
unsigned long initMillis = 0;
void setup() {
Serial.begin(9600);
for (int i=2; i <= 5; i++){
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}
pinMode(A1,INPUT);
}
float makeAction(int action, long initMillis ) {
int lumens = 0;
int lumensTotal = 0;
digitalWrite(action, LOW);
delay(800);
while (initMillis + PRESS_INTERVAL >= millis()) {
lumens = analogRead(1);
if (lumens >= 1020)lumens = 0;
lumensTotal += lumens;
}
digitalWrite(action, HIGH);
return lumensTotal;
}
void loop() {
unsigned long currentMillis = millis();
if (Serial.available() > 0) {
int value = Serial.read();
initMillis = millis();
switch (value) {
case 68:
Serial.print("Disarm");
Serial.print(";");
Serial.println(makeAction(disarmP, initMillis));
break;
case 65:
Serial.print("Arm");
Serial.print(";");
Serial.println(makeAction(ArmP, initMillis));
break;
case 80:
Serial.print("Part");
Serial.print(";");
Serial.println(makeAction(PartP, initMillis));
break;
case 83:
Serial.print("Status");
Serial.print(";");
Serial.println(makeAction(StatusP, initMillis));
break;
}
}
}
The instructable actually seems ok (I skimmed it). But the point of the instructable is not to detect what color of light a LED gives off, but to detect what color an object is by reflecting colored light off of it.
When you do this, you already know what color the LED gives off, because the MCU tells it what to do. Then you use the photo resistor (bare, not in a module) to see how much of that colored light is reflected back by the object.
Your project is completely different. If you can't just read the voltage from the LED pins, you can use two LDRs with color filters, one red and one green.
Why not connect input pins to the correct terminals of the LED, and read the voltage directly?
Or replace the LEDs with a couple of optocouplers, and connect these to input pins?
but I read that photodiode can only do with two values: 0/1
The person who wrote that is terribly misinformed.
Photodiodes are used to measure light levels over a range much larger than that of the human eye. You need a good photodiode amplifier for that range, but these much simpler circuits will work over a lower range.
Raspoutitsa:
Each color has his own luminosity.
As example, I need to increase sensitivity in order to catch the green light.
Green LEDs are often relatively dim - in order to not look brighter than the red and blue ones to the human eye, our eyes are particularly sensitive to green.
Maybe your best bet is by using an RGB colour sensor. Its three colour sensors should be quite well matched to the colours of the RGB LED.