LockedLED as photodiode

Author
Guest
Super Member
  • Total Posts : 80499
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2005/12/13 14:55:25 (permalink)
0

LED as photodiode

Hi,

I'm trying to detect light intensity with a LED. I've followed the method described in the references mentioned at the end of this post, namely applying a reverse voltage across a LED and flipping the high pin to 3 state and timing how long it takes to drop to zero.

The problem that I'm having is the LED isn't driving the input low unless there is a very bright light source near the LED.

I'm using a PIC16f628a and I've tried using RA0 (Schmitt) and RB0 (TTL) as the input with RA1 & RB1 as the ground pin respectively. Neither get driven low (Over multi session periods).

When I insert the LED into my multimeters' capacitance test it reads 18pf

Does anyone have any ideas whats going wrong? Do I need to find a LED with a higher capacitance? I figured this would make the fall time longer?

Alternatively, does anyone have any working source for a modern PIC (16f628a pref.)?

TIA

References:
http://www.jdm.homepage.dk/solarpic.htm
http://www.merl.com/publications/TR2003-035/

aspforum.mchp.guest
#1

19 Replies Related Threads

    Olin Lathrop
    Super Member
    • Total Posts : 7463
    • Reward points : 0
    • Joined: 2004/02/26 17:59:01
    • Location: Littleton Massachusetts
    • Status: offline
    RE: LED as photodiode 2005/12/13 15:07:04 (permalink)
    0
    namely applying a reverse voltage across a LED and flipping the high pin to 3 state and timing how long it takes to drop to zero.

    I'm not clear how the LED is connected or what else is in the system. Show a schematic.
    #2
    ric
    Super Member
    • Total Posts : 22098
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: LED as photodiode 2005/12/13 15:47:37 (permalink)
    0


    It is all explained in the links he posted.
    This is a very clever technique, if it works.
    The explanation in the second link seems reasonable.
    If it doesn't work, it is not the capacitance of the LED which is the problem, it's insufficient photocurrent being generated.
    Fig 9 in the second reference clearly shows that there is not enough current under room lighting, but there is when you shine another LED directly onto the receiver LED.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    dchisholm
    Super Member
    • Total Posts : 3805
    • Reward points : 0
    • Joined: 2003/12/14 15:30:12
    • Location: St Louis Mo
    • Status: offline
    RE: LED as photodiode 2005/12/13 16:16:01 (permalink)
    0
    That Mitsubishi report is interesting! It gives you a few clues about what to look for: "The LED is a photodiode that is sensitive to light at and above the wavelength at which it emits (barring any filtering effects of a colored plastic package)." (Section 2.)

    - I suspect that LED's with clear plastic encapsulation will be more sensitive to broad-spectrum illuminitaion (like daylight) than LED's with colored encapsulation.
    - Green LED's (shorter emitted wavelength) may be more sensitive to broad (visible) spectrum illumination than yellow or red LED's.
    - Figure 9 in the report shows that "normal room illumination" (whatever that means!) is insufficient to discharge the junction capacitance during one sensing period. That agrees with your observation that you need a "very bright source" to make your application work.
    - The LED's photocurrent is fighting leakage currents on the PIC pins and your PWB. Make absolutely certain that internal pull-ups are disabled. (I suspect your circuit wouldn't work AT ALL if they were enabled, but it's easy to check this in your code.)
    - Then, give your PCB Assy a good shot of household spray-on cleaner (Formula 409, Mr Clean, etc), scrub it a little with a toothbrush, and rinse under a lot of running water. Stand the board on edge and dry it under a hair dryer or in your thermal chamber. In my personal experience, flux residue and handling oils reduce the isolation between PWB pads to a few megohms, and stray leakage currents can get as high as a microamp. This is the same order-of-magnitude as the photocurrent you're trying to detect.

    Dale
    #4
    DSchabel
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2005/05/24 14:00:34
    • Location: Western NY State
    • Status: offline
    RE: LED as photodiode 2005/12/13 16:46:22 (permalink)
    0
    ORIGINAL: ric

    It is all explained in the links he posted.
    This is a very clever technique, if it works.

    It is a clever idea, if it could be made to work.
    I'm very doubtful about the way it was presented, though.
    they seemed to want to measure the voltage discharge on a capacitor:
    a) Not having any real knowledge about how big or small that cap could be
    and
    b) depending on the leakage current of a PIC's input port.

    Especially concerning b): not only is the magnitude of the current not quantifiable, but its direction is not known from part to part, condition to condition!

    I'd think that if this was to have any hope of working reliably, not just in a one-off situation, you'd have to build some kind of deterministic discharge path (a resistor, at the least), and perhaps also a known capacitor to hold the charge. Even then, repeatability would be poor.
    #5
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: LED as photodiode 2005/12/14 01:25:05 (permalink)
    0
    Hi Guys,

    Wow, busy forum! I may stick around here for a while ;)

    Thanks for all your posts. I can understand the points made about LEDs with clear casing and the fact that green LEDs have a shorter wavelength but I'm a programmer dabbling with electronics here and what I don't understand is why the input pins are not being read as low? Is it somthing to do with the difference between zero volts being present and no voltage being present?

    In the second reference he shows a graph of voltage against time and explains that the voltage does not drop during his sample period under normal lighting conditions but his sample period was in the milliseconds, about 4ms from memory, I'm waiting _seconds_ in normal light before presenting the LED to a 60w bulb!

    Can some one give a poor programmer a quick overview of why the pin one is not being read as low when the pin zero is held at logic low? And (probably related) what photocurrent has got to do with it all?

    Thanks

    aspforum.mchp.guest
    #6
    ric
    Super Member
    • Total Posts : 22098
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: LED as photodiode 2005/12/14 06:20:51 (permalink)
    0
    In the second reference he shows a graph of voltage against time and explains that the voltage does not drop during his sample period under normal lighting conditions but his sample period was in the milliseconds, about 4ms from memory, I'm waiting _seconds_ in normal light before presenting the LED to a 60w bulb!

    It doesn't matter how long you wait, it will never drop.

    Can some one give a poor programmer a quick overview of why the pin one is not being read as low when the pin zero is held at logic low? And (probably related) what photocurrent has got to do with it all?

    The pin is NOT being "held at logic low" at all!
    Under strong light conditions, the LED generates enough current (we are talking microamps here), to overcome the leakage current of the pin, and drive it low.
    Under room light, not enough current is generated, so the pin is essentially floating, and so could read high or low.

    The original authors never say that you can read any light level by waiting longer.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    schen
    Super Member
    • Total Posts : 790
    • Reward points : 0
    • Joined: 2004/11/15 01:40:07
    • Status: offline
    RE: LED as photodiode 2005/12/14 08:38:17 (permalink)
    0
    A few years ago, I stumbled over the photosensitivity of LED. Some of them even produced measurable (by a DVM) open circuit voltages under light. I tested a few samples from my collection of red LEDs with various unknown manufacturers. I could not get a consistent result among devices.

    It would be fun to make a toy out of this, but I would not apply it for any serious work.
    #8
    danish.ali
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2004/11/16 02:02:02
    • Location: Surrey, UK
    • Status: offline
    RE: LED as photodiode 2005/12/14 10:30:17 (permalink)
    0
    And many years ago, transistors like the OC71 were available in (transparent) plastic packages covered in black paint. You could scrape the paint off and convert them into the (more expensive) phototransistor OPC71.

    Later Mullard used an opaque filling for the OC71 to prevent this.
    #9
    schen
    Super Member
    • Total Posts : 790
    • Reward points : 0
    • Joined: 2004/11/15 01:40:07
    • Status: offline
    RE: LED as photodiode 2005/12/14 11:10:56 (permalink)
    0
    Before these cheap video cameras are available, we used to replace the top of a ceramic DIP memory with glass, charge the bits and watch them decay under a camera lens and get a crude image.
    #10
    maxwell
    Super Member
    • Total Posts : 1510
    • Reward points : 0
    • Joined: 2003/11/07 12:35:27
    • Status: offline
    RE: LED as photodiode 2005/12/14 13:12:42 (permalink)
    0
    This idea is not new. Several decades ago (3?) a free lance author who wrote books for the electronics enthusiast and columns for Popular Electronics and/or Electronics Now became involved in a legal dispute over who actually invented this idea first. His name is Forrest Mims (spelling?) and in one of his popular books he described how an LED could be used as both a fiber optics detector and emitter. This would make fiber optic links easier to build since the single element would perform both functions, eliminating the need for fancy optics to separate sending and receiving. Later a large electronics firm came out with the same scheme, prompting a legal battle, which, I believe, he lost.

    John N. Power
    #11
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: LED as photodiode 2005/12/16 01:37:20 (permalink)
    0
    Hey Guys,

    Just a quick update: I've switched to using a green LED with a clear casing and I'm now getting some readings.

    I'm using the comparator module and the reference voltage generator (set to about 3.5v) instead of the digital buffers which gives some flexibility.

    I'll post source & schematics if anyone's interested. Although it's only a proof of concept at the moment.

    TTFN
    #12
    bkil
    Super Member
    • Total Posts : 319
    • Reward points : 0
    • Joined: 2005/07/08 06:21:43
    • Location: Hungary
    • Status: offline
    RE: LED as photodiode 2005/12/16 13:09:57 (permalink)
    0
    Just a comment on the topic: I've tried that trick once with one PIC, one board and a single yellow LED, and it worked like a charm./oh and of course I used a clear casing/ I don't recall the exact readings but it sure helped to display the time on an LCD. (I've probably used a 1k resistor.) And if I recall right, used microseconds not milliseconds in the delay loop (or was that my capacitive touch sensor?). Oh yeah, it measured ms, now I remember, I used a 24 bit timer, as it had usually overshot a bit. In dark conditions (when covered or behind a cast shadow), it needed seconds to switch. (This whole trick might only work because of the presence of the 230 V mains... Could someone who can reach a point that is far from power lines verify this?) I had success with a regular spotlight (has low rating, is above my desk) with a regular placing (on the ceiling...).
    Tips: Watch out for lead length. Keep the path between the PIC pin to LED junction as short as possible.

    schen: It might be a toy, but automatic (re-)calibration would sure help solving the problem. I haven't made any communication using this technique yet (wink), but constantly applying min-max level detection over (probably overlapping) periods of a few hundred ms should do the trick. It would sure be fun to have an extra cheap method of optical detection on a follower robot or to have a 96 baud communication line between two nearby robots! Smile

    Cheers!
    -bkil
    < Message edited by bkil -- Dec. 18, 2005 8:24:47 PM >

    "We make a living by what we get, we make a life by what we give." -- Sir Winston Churchill
    #13
    lbodnar
    Super Member
    • Total Posts : 1148
    • Reward points : 0
    • Joined: 2005/12/18 06:06:09
    • Location: UK
    • Status: offline
    RE: LED as photodiode 2005/12/18 06:32:45 (permalink)
    0
    ORIGINAL: bkil
    Oh yeah, it measured ms, now I remember, I used a 24 bit timer, as it had usually overshot a bit. In dark conditions (when covered or behind a cast shadow), it needed seconds to switch.
    How about paralleling a LED with a high value resistor to help discharging the LED's capacitance in the darkness? This will put a limit on discharge time in total darkness, say at 12pF LED capacitance 10 MOhm resistor will result in 120 microseconds time constant so in about 0.5mS it will be over in any light conditions.

    On the same account adding a ceramic capacitor in parallel with a LED will make it proportionally longer to discharge with the same current so could be useful if it discharges too quickly in bright conditions.
    #14
    bkil
    Super Member
    • Total Posts : 319
    • Reward points : 0
    • Joined: 2005/07/08 06:21:43
    • Location: Hungary
    • Status: offline
    RE: LED as photodiode 2005/12/18 11:37:15 (permalink)
    0
    Sounds like a good idea, too bad I'm far from my tools at the moment. It would be a nice thing if someone could verify these things, as it really would only take a couple of minutes...

    so in about 0.5mS it will be over in any light conditions.

    I see you're targeting 1200 Baud inner-PIC communication too.wink

    "We make a living by what we get, we make a life by what we give." -- Sir Winston Churchill
    #15
    lbodnar
    Super Member
    • Total Posts : 1148
    • Reward points : 0
    • Joined: 2005/12/18 06:06:09
    • Location: UK
    • Status: offline
    RE: LED as photodiode 2005/12/18 12:30:08 (permalink)
    0
    ORIGINAL: bkil

    Sounds like a good idea, too bad I'm far from my tools at the moment. It would be a nice thing if someone could verify these things, as it really would only take a couple of minutes...

    so in about 0.5mS it will be over in any light conditions.

    I see you're targeting 1200 Baud inner-PIC communication too.wink
    Actually, I might tomorrow. I was going to make a logger for my electricity meter (that flashes its LED 1000 per kWh) so that I can look at my energy consumption and maybe even have a dynamic display of current wattage (proportional to 1/time_between_pulses) on LCD module. I was contemplating to do a proper photodide+opamp+differentiator circuit but now I might just stick a photodiode directly between a PIC pin and the ground. Even series resistor is not needed because I am not going to apply direct voltage to a photodiode to light it up. Just a PIC and a lonely photodiode (or LED). This is ridiculously simple!
    < Message edited by lbodnar -- Dec. 18, 2005 12:30:54 PM >
    #16
    lbodnar
    Super Member
    • Total Posts : 1148
    • Reward points : 0
    • Joined: 2005/12/18 06:06:09
    • Location: UK
    • Status: offline
    RE: LED as photodiode 2005/12/19 10:30:31 (permalink)
    0
    OK, it works just perfectly. As I said, my main purpose was to use clear cap photodiode but I have tried a random orange LED and it works too. I have grounded one photodiode's pin but, obviously, when used to both emit and sense light it should be tied to another port pin which is cleared low during sensing light.


    ;
    ; PORTA.2 ----|<|------ GND (or another port pin that held low throughout this code)
    ; add port init, startup, RS232, delay code as needed

    bsf PORTA,2 ; set pin PORTA.2 high
    MainLoop
    ; LEDcntr = 0
    clrf LEDcntr1
    clrf LEDcntr2
    clrf LEDcntr3
    clrf LEDcntr4

    bsf STATUS, RP0 ; Select Bank 1
    bcf TRISA,2 ; Set PORTA.2 as output

    call Delay1ms ; charge time

    bsf TRISA,2 ; Set PORTA.2 as input
    bcf STATUS, RP0 ; Select Bank 0

    CountLoop
    ; LEDcntr++
    incf LEDcntr4,F ; LSB
    skpnz
    incf LEDcntr3,F
    skpnz
    incf LEDcntr2,F
    skpnz
    incf LEDcntr1,F ; MSB

    btfsc PORTA,2 ; has LED discharged?
    goto CountLoop ; not yet

    ; LEDcntr -> RS232
    movf LEDcntr1,W
    call TxRS232
    movf LEDcntr2,W
    call TxRS232
    movf LEDcntr3,W
    call TxRS232
    movf LEDcntr4,W
    call TxRS232

    goto MainLoop


    With the above photodiode and 16F877 at 20MHz I get LEDcntr
    2000,000 total darkness
    200 dimly lit room (dusk)
    50 another LED shines straight into photodiode
    This is insane range so I suspect it can be very very accurate and/or sensitive. I haven't looked how photocurrent depends on temperature...

    Using LED brings the counts into hundreds of thousands under normal light due to decreased sensitivity [compared to dedicated photodiode] but still very impressive.

    Adding 1.5MOhm resistor in parallel drops count to about 50 (too much) so maybe 10-20MOhm should be fine. This is non-linear now, so count is not [roughly] proportional to 1/light_level anymore.

    Adding capacitor (820pF) to the photodiode proportionally increases all counts about 15 times as expected. Since diode's capacitance slightly depends on reverse voltage, adding external capacitance should improve linearity and bring count (time) closer to 1/light_level dependence.

    So yes, it works. In particular, I have achieved my goal (detecting another LED pulse) - telling apart 200,000 and 50 is no sweat! The whole schematic is just PIC+photodiode :)

    Another experiment would be to see if ST input is any better than plain TTL. Port A also feeds ADCs that might be connected via MOSFET switch before the first input buffers which lowers input impedance so maybe using Port B is better idea. But don't turn pull up resistors on or it will never discharge!

    [Edit: corrected measurements]
    < Message edited by lbodnar -- Dec. 22, 2005 8:42:38 AM >
    #17
    electricdruid
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2007/06/28 02:51:34
    • Location: 0
    • Status: offline
    RE: LED as photodiode 2007/06/28 02:57:56 (permalink)
    0
    Someone already mentioned Forrest M. Mims work on this topic. He found that LEDs make reasonable narrow-band light sensors. By using various colours of LED, you are able to measure the light spectrum. Here's an article describing one use he found for this:

    http://www.sas.org/tcs/weeklyIssues_2005/2005-07-29/feature2/index.html

    For the money that it costs against the results that are possible, this is an incredible piece of work.

    I've looked this up a time or two in the past reckoning that it is an interesting trick to know, and the MERL paper mentioned in the first post seems to be the most complete treatment of the topic I could find online.

    Regards,
    Tom
    #18
    bryan1
    Starting Member
    • Total Posts : 58
    • Reward points : 0
    • Joined: 2004/07/25 16:24:15
    • Location: Adelaide Hills, Australia
    • Status: offline
    RE: LED as photodiode 2007/07/10 04:34:13 (permalink)
    0
    I'm currently on designing a solar PV tracker and between my friend and I we are designing the automation using 2 10mm green led's to sense the brightest part of the sky. My first tests have sort of proved fruitfull but i need to get the a/d code working properly. Redrock.com have been using multiple green led's for pv trackers for ages so the idea of this being a project for fun just doesn't cut the mustard. The initial idea came from an old 555 based tracker circuit I found on the net and tested and yes it worked so i thought using a pic would be much better. I'll keep you guy's posted on my success/failure on this project but i do think it will workout.
     
    Cheers Bryan
    #19
    paulbergsman
    Super Member
    • Total Posts : 1517
    • Reward points : 0
    • Joined: 2006/05/25 12:18:23
    • Location: Merion Station, Penna.
    • Status: offline
    RE: LED as photodiode 2007/07/10 05:51:05 (permalink)
    0

    Later a large electronics firm came out with the same scheme, prompting a legal battle, which, I believe, he {Forrest Mims} lost.


    You can not patent an idea.



    Paul Bergsman, N3PSO


    For the most cost effective PIC prototyping board around:
    http://mysite.verizon.net/vzes94mj/picprototypingboard
    #20
    Jump to:
    © 2017 APG vNext Commercial Version 4.5