Pages: 1 [2]   Go Down
Author Topic: Using LEDs as a light/dark sensor  (Read 2524 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
  }

« Last Edit: November 13, 2012, 03:35:31 pm by april » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 23, 2012, 11:13:52 pm by april » Logged

Pages: 1 [2]   Go Up
Jump to: