Single LED Takes On Both Light-Emitting And Detecting Duties

,

By adding just two MCU I/O pins, a standard LED can also perform as a light-detecting photodiode.

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.

A standard LED, connected to a pair of microcontroller bidirectional I/O pins with a high-impedance capability, can act as a photodiode to detect light intensity.
Figure 1. A standard LED, connected to a pair of microcontroller bidirectional I/O pins with a high-impedance capability, can act
as a photodiode to detect light intensity.

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.

The LED photodiode circuit operates in three steps, with control provided through the microcontroller and a C-based software routine.
Figure 2. The LED photodiode circuit operates in three steps, with control provided through the microcontroller and a C-based
software routine.

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.

The LED photodiode circuit operates in three steps, with control provided through the microcontroller and a C-based software routine.
Figure 3. With greater light intensity on the LED, the decay time (TD), during which the voltage on P1 discharges, is shorter (a).
The voltage on P2 goes high if TD exceeds TDCR (b). These are experimental results using a 5-mm, high-intensity red LED.

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.

electronicdesign.com

1-4 Layer PCBs $2

You may have to register before you can post comments and get full access to forum.
User Name