Go Down

Topic: Using LEDs as a light/dark sensor (Read 2 times) previous topic - next topic

april

#15
Nov 13, 2012, 08:50 pm Last Edit: Nov 13, 2012, 09:35 pm by april Reason: 1
Hmm I'm working on something similar atm
Using this page
http://www.instructables.com/id/Bi-directional-LED-Sensing-Try-out/

With a 4 LED setup and this code I am getting some results but not anything I can use reliably yet.
I am finding a noticeable difference in the red LEDs compared to the water clear superbright .
The water clear superbright gives pretty good results with up to a half inch separation between the LEDs


I will try your setup Thanks

My Code at present for testing
Code: [Select]
const int led1 = A2;
const int led2 = A1;

int value1, value2;
int threshold1 = 120;
int threshold2 = 120;

void setup(){
 Serial.begin(9600);
 pinMode(led1,INPUT);
 pinMode(led2,INPUT);
 }

void loop(){
 value1 = analogRead(A2);
 value2 = analogRead(A1);
 if(value1 >= threshold1){
   Serial.print("Value 1 : ");
   Serial.println(value1);
   out(led1,led2,threshold1);
   pinMode(led2,INPUT);
 
 }
 else if(value2 >= threshold2){
   Serial.print("Value 2 : ");
   Serial.println(value2);
 
   out(led2,led1,threshold2);
   pinMode(led1,INPUT);
 
 }
}

void out(int a, int b, int threshold){
 pinMode(b,OUTPUT);
 //if (a==led2)
 //delay(30);
 //else
 //delay(60);
 int value = analogRead(a);
   if(value >= threshold){
     analogWrite(b,value);
        }
   else{analogWrite(b,0);    }
    Serial.print("Value Following: ");
   Serial.println(value2);
 }


april

#16
Nov 24, 2012, 05:12 am Last Edit: Nov 24, 2012, 05:13 am by april Reason: 1
I'm getting huge differences in different types of LED's
The small 3 mm seem unuseable if I have them on extension wires which I need to mount through the container for waterproofing purposes.

the 5mm is much better but again varies drasticaly when you extend it . The capacitance varies with the extension leads I suppose..Using your hands to shade them often changes its capacitance greatly  as does heat.

They don't look like something I can reliably use at this point.

Go Up