LED as a light sensor

Discussion in 'General Electronics Chat' started by Razor Concepts, Dec 24, 2009.

  1. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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?
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
  3. sara145

    New Member

    Dec 24, 2009
    1
    0
    it depends upon which semicondutor you are using as LED in recersed bias
     
  4. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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).

    Code ( (Unknown Language)):
    1.  
    2. void loop()              //LED anode is pin 4, cathode is pin 5
    3. {
    4.   DDRC = 0xFF;           //All ports set to output
    5.   PORTC = 0b00100000;    //HIGH cathode LOW anode, starts reverse bias
    6.   delay(1);              //charges LED for 1 millisecond
    7.   PORTC = 0b00000000;    //LOW cathode and anode, ends reverse bias
    8.   DDRC =  0b11011111;    //turns cathode pin from OUTPUT to INPUT
    9.   int counter = 0;
    10.   while(analogRead(5) > 500)  //counts the time it takes to reach roughly 2.5 volts, analog voltage is read from the cathode pin.
    11.   {
    12.     counter++;
    13.   }
    14.   Serial.println(counter);    //prints out how many ticks it took
    15.   counter = 0;
    16. }
    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: Dec 26, 2009
  5. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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.
     
  6. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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?
     
  7. beenthere

    Retired Moderator

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

    Moderator

    Jan 28, 2005
    9,030
    214
    So is everything working correctly now?

    hgmjr
     
  9. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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.
     
  10. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    Setting the probe to 10x works - see attached figure.
    [​IMG]


    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 :)
     
  11. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Would you mind sharing with us why you are seeking to charge and discharge the LED as you are doing?

    hgmjr
     
  12. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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.
     
  13. jbeng

    Member

    Sep 10, 2006
    19
    1
    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
     
  14. Razor Concepts

    Thread Starter Active Member

    Oct 7, 2008
    212
    1
    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?
     
Loading...