Go Down

Topic: LEDs as Photo-diodes (Read 2 times) previous topic - next topic


Reversed biased leds do work as photo-diodes. Find below code that provides a solution to controlling leds from a led light detector. This can be a multilevel dark detector too!

Code: [Select]
* -----------------------
* This program uses separate led's for light and sensing light.
* Works with room ambient or daylight.
* LED light sensing modified from Hunter's Instructible. Acheives sharp
* cut off and on according to "int light = X". Could also fade lights
* in/out on analog pins.
* Hunter Carlson
* June 9 2009
* Edits added Nov. 9, 2012 -fabelizer
* Requires at least 2 (or 3 or more) LEDs, one to analog pins 4 & 5, other
* to D8 & GND through a resistor. I used a water clear superbright
* red led for the sensor led, white for led1.
* See comments below for polarities and connections.

int sense01 = 5;        // sensing LED anode connected to analog pin5
int sense02 = 4;        // sensing LED cathode connected to analog pin4
                        // you can switch out different leds on these
                        // pins to see which works best. Run the
                        // serial monitor and watch the changes.
int LED01 = 8;          // LED anode to dig pin8, cathode to 220R
                        // 220R to GND.
int LED02 = 9;          // LED anode to dig pin9, cathode to 220R
                        // 220R to GND.
int val01 = 0;          // variable to store the value read from sense01
int val02 = 0;          // variable to store the value read from sense02

int light1 = 110;       // set light threshold for led1
int light2 = 80;        // set light threshold for led2

void setup()
  Serial.begin(9600);        // setup serial (comment out to save memory)
  pinMode(LED01, OUTPUT);    // led1 pin set to output
  pinMode(LED02, OUTPUT);    // led2 pin set to output

void loop()
  val01 = analogRead(sense01);      // read sense01 led
  val02 = analogRead(sense02);      // read sense02 led
   //debug print
  Serial.print(val01              // comment this section out to save memory
  Serial.println(val01-val02);    // result is printed and compared with light1 or 2
  Serial.println();               // blank line between values
                                    // first led 'led1'
if ((val01 - val02) >= light1) {   // check if light in area
      digitalWrite(LED01, LOW);     // if light enough, turn off led1
    } else {                     
      digitalWrite(LED01, HIGH);    // if dark enough, turn on led1
                                    // second led 'led2'
if ((val01 - val02) >= light2) {   // check if light in area
      digitalWrite(LED02, LOW);     // if light enough, turn off led2
    } else {                     
      digitalWrite(LED02, HIGH);    // if dark enough, turn on led2
delay(100);                         // just to slow things down a bit



Udo Klein

My page offers explanations plus links to the original research: http://blog.blinkenlight.net/experiments/measurements/led-camera/

You do not even need to reverse bias them. No matter in which direction you bypass them.
The reverse bypassing is only needed if you do not have an ADC but only digital inputs. With ADC inputs you can measure and find out that they work as photodiodes no matter how you bypass them.
Check out my experiments http://blog.blinkenlight.net


Folks at Mistubishi started this. Google their article.


Keywords are Mitsubishi and iDropper.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Heres an example of somone using an arduino, and LEDs as both lights, and sensors. The top corner LEDs are also sensors to control what the cube does.


There is an instructible about it, and i think he did the whole 4x4x4 cube with no ICs (drivers or shift registers)

Go Up