LED as a light sensor

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Reverse biasing a LED makes the LED act as a capacitor, holding a small charge. However, how does one find out how long a LED should be reverse biased to ensure it is fully charged before detecting the time it takes to discharge?
 

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Thanks for the help. For now I am just guessing 1 millisecond should be fine, but I am having some problems. See the code below (you can ignore the actual code, just see the comments).

Rich (BB code):
void loop()              //LED anode is pin 4, cathode is pin 5
{
  DDRC = 0xFF;           //All ports set to output
  PORTC = 0b00100000;    //HIGH cathode LOW anode, starts reverse bias
  delay(1);              //charges LED for 1 millisecond
  PORTC = 0b00000000;    //LOW cathode and anode, ends reverse bias
  DDRC =  0b11011111;    //turns cathode pin from OUTPUT to INPUT
  int counter = 0;
  while(analogRead(5) > 500)  //counts the time it takes to reach roughly 2.5 volts, analog voltage is read from the cathode pin.
  {
    counter++;
  }
  Serial.println(counter);    //prints out how many ticks it took
  counter = 0;
}
The problem is, it never gets charged, it always returns 0 ticks, which means there was never enough voltage. Any ideas? I am using a yellow LED and 200 ohm resistor.

EDIT:
While posting this I tried something else, and now it works.
See these two lines:
//LOW cathode and anode, ends reverse bias
//turns cathode pin from OUTPUT to INPUT

I reversed them to this, and now it works:
//turns cathode pin from OUTPUT to INPUT
//LOW cathode and anode, ends reverse bias

The issue is, as soon as the first line is executed, a pull up resistor is enabled on the cathode pin, and that second line terminates the pull up resistor. So it appears that the pull up resistor is charging it?
 
Last edited:

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Just another random observation - the time it takes my LED to charge is ONE microsecond :eek: Plus the time it takes the microcontroller to switch states. Interesting.
 

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Update - I am trying to see the charge/discharge curve through an oscilloscope (textronix 454), but it looks like the probe is discharging the LED's capacitance too much to see any difference.

Would a modern digital oscilloscope require less current through the probe to measure?
 

beenthere

Joined Apr 20, 2004
15,819
It's doubtful - o'scope probes are pretty standard. You might have to build a very high impedance buffer to monitor the effect.
 

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Thanks for the help. Everything is working great - besides the oscope problem (I guess this is why nobody has posted data on this!)

I think I will have to resort to using the microcontroller's ADC to measure the voltage and record. It won't be as precise, but I guess it will work.
 

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
Setting the probe to 10x works - see attached figure.



Unfortunately, the probe still requires too much current, and the LED discharges at roughly 300x times faster rate than if not using the probe, so I am unable to accurately see differences in the curve depending on the light levels. So I still will have to use the microcontroller to measure the differences. At least I am 100% sure the LED is like a capacitor, though :)
 

Attachments

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
I was trying to see how different amounts of light affected the discharge of the LED's capacitance - maybe one day incorporate this stuff into LED displays as a cheap touch screen that measures light differences to tell where fingers are.
 

jbeng

Joined Sep 10, 2006
84
Leds can also act as a photo diode, generating a small voltage/current when you shine a light on them. Have you tried using them in that configuration?
Jeff
 

Thread Starter

Razor Concepts

Joined Oct 7, 2008
214
I am experiencing a weird problem - I have the led mounted unto a cardboard box using hot glue. The length of the RC time constant is about 27000 microseconds as measured by the microcontroller, but if I touch just the cardboard box, it drops to 11000 microseconds. Any ideas why this is happening? The cardboard box isn't conductive. Touching the LED (plastic part) has no effect on the time?
 
Top