Go Down

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


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

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(){

void loop(){
 value1 = analogRead(A2);
 value2 = analogRead(A1);
 if(value1 >= threshold1){
   Serial.print("Value 1 : ");
 else if(value2 >= threshold2){
   Serial.print("Value 2 : ");

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


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131