Electronic Design

Single LED Takes On Both Light-Emitting And Detecting Duties

Sometimes people forget that light-emitting diodes can also detect light quite well. They're usable in a wide range of applications as inexpensive, readily available optical detectors. Typically, an LED detects light at a wavelength somewhat shorter than the light it emits, making it a wavelength-selective detector. For example, an LED that emits greenish-yellow light at a peak wavelength of about 555 nm detects green light at a peak wavelength of about 525 nm over a spectral width of about 50 nm.

Almost all LEDs can detect a relatively narrow band of wavelengths, with varying sensitivity. In fact, a standard LED can perform double duty in the same circuit without changing its physical or electrical connections. Figure 1 shows a very simple microcontroller-based circuit that can alternately emit and detect light using just two I/O pins on the microcontroller and an LED and resistor. The circuit can be used as a smart light switch, high-resolution dimmer, code detector, smoke detector, etc.

Because LED photodiodes are considerably less sensitive than commercial photodiodes (with a photocurrent about 10 to 100 times smaller), direct measurement of the photocurrent is difficult without amplification. Typically, it requires a picoammeter and expensive operational amplifiers.

However, most modern microcontrollers have bidirectional I/O ports with configurable internal pull-ups or tri-state (high-impedance) inputs. Using a high-impedance input, the circuit can make a very accurate and precise measurement of the photocurrent by employing a simple threshold technique and the microcontroller's built-in timer-counter.

In detector mode, the LED "charges" to +5 V very quickly (100 to 200 ns). This charge is sustained by the diode's inherent capacitance, typically 10 to 15 pF (Fig. 2, Step 1). Then P1 on the microcontroller is switched to the high-impedance mode (approximately 1015- Ω resistance), Step 2. Under reverse-bias conditions, a simple model for the LED is a capacitor in parallel with a current source, iR(φ), which represents the current induced by light intensity . The model includes leakage current iL through P1, which, at about 0.002 pA typically, is insignificant when compared to a typical photocurrent iR(φ) of 50 pA through the diode in normal ambient lighting. Figure 3a shows the experimental results of the LED discharging, VP1(t), for φ1 and φ2, where 2 > φ 1.

A software routine (written for 16-bit timer-counter TCNT1 on the 8-bit microcontroller) continually polls VP1(t) through its digital equivalent, the logic state of P1, until the logic 0 threshold VTR (approximately 2.2 V) is reached. The decay time Td, in microseconds, is proportional to the amount of light detected and, therefore, measures the diode photocurrent, iR(φ). As the amount of light received increases, the diode discharges more rapidly and Td decreases, and vice versa (Fig. 3a, again).

If the decay time is more than a user-specified light-intensity threshold, represented by Tdcr (critical), the microcontroller can switch the LED on and it emits light as an alarm (Fig. 2, again, Step 3). In addition, other pins on the microcontroller can be used as relay outputs or light-controlled, pulse-width-modulation outputs. Figure 3b shows the voltage output at P2 during the operating steps.

This very low-cost approach provides an inherently digital measurement of light intensity without amplification. Its signal-to-noise characteristics are excellent, due to the signal integration over the measurement. The technique improves the sensitivity of the photodiode, making it more attractive than a conventional (and more expensive) photodiode. A conventional photodiode discharges the capacitance much more quickly, making time-based measurement more difficult and expensive.

The C code listing for this application can be found at ED Online 15980 at www.electronicdesign.com. The code was written for Atmel's AT90S2313 AVR microcontroller, using the CodeVision AVR compiler. However, other microcontrollers, including those from Microchip Technology (PIC) and Texas Instruments (MPS430), are also suitable.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish