Light sensors find their way into a host of interesting applications. For instance, a light sensor in a camera measures the amount of light that the film will be exposed to. Once the amount of light is known, the proper lens aperture can be calculated to make sure that the picture is taken with the proper amount of exposure.
In a smoke detector, a light sensor can be used to measure the amount of light transmitted by a known light source, such as an LED, through the air inside the sensor assembly. When the air becomes smoky, the amount of light received by the sensor changes. If the amount of light change goes above a preset threshold, then more than likely something nearby is burning, and a horn is activated to indicate there’s a fire in the building.
There are many other applications for light sensors, such as flame detectors, security systems, lighting control, robotics, etc. In these applications, many of us think that since the sensor produces an analog output, interfacing this type of sensor to a microcontroller will require a conventional analog-to-digital converter. Actually, though, by using just a few discrete components, interfacing a light sensor to an A/D-less microcontroller is very simple.
Photodiodes and phototransistors are two of the most popular and lowcost light sensors. These devices are readily available in the $1 range. Both devices produce current outputs as a function of light intensity. The operating range of such devices varies depending on the manufacturer. Many of these sensors are equipped with builtin lenses tuned to particular wavelengths, so they’re most effective for detecting or measuring light with those wavelengths. To get the best performance, the voltage across the sensor must be held constant during measurement.
The circuit shown represents a very simple method of interfacing a light sensor to the PIC12C620 microcontroller (see the figure). The light sensor selected in the example is Photonic Detectors’ PDB-C107 (available through Digi-Key). The PNP transistor (Q1) and resistors R1 and R2 are used to provide a constant sensor voltage (VS) within 1 to 1.3 V. The collector current of Q1 is approximately the same as the sensor current (IS). Capacitor C1 integrates IS and generates a voltage ramp with a slope that’s proportional to the light intensity seen by the sensor.
The microcontroller has two voltage comparators and an internal voltage reference. One of the voltage comparators and the voltage reference are used to interface to the sensor circuitry. The second voltage comparator, left unused in this example, is available for other application-defined tasks, such as temperature measurement using a thermistor, ac-line zero-crossing detection, etc. The RA3 pin has multiple functions. It can be configured as a digital I/O, or an analog connection to the inverting input of the voltage comparator. Both RA3 and RA0 pins are used to control the sensor. Initially, the system is in an idle state, where RA0 is a high output to disable the sensor, and RA3 is a low output to discharge C1 through R3. This idle state helps minimize power consumption.
To start a measurement, RA0 is set to a low output to activate the sensor circuitry. RA2 is now set to an input and connected to the voltage comparator’s inverting input. The noninverting input of the comparator is connected to the internal voltage reference. The capacitor voltage then starts to ramp up. The microcontroller now begins its timer while monitoring the state of the comparator’s output. When the capacitor voltage and the voltage reference are equal, the comparator output goes from a high to a low state.
As soon as the microcontroller detects this transition, it stops its timer. At this point, the measurement is completed, and the micro sets the RA3 and RA0 port lines back to the idle state. The time measured during the ramp is inversely proportional to IS. The microcontroller can process this information to meet whatever the application’s goal is, such as activating the horn in a smoke detector, running the motor in a robot, or simply sending the reading to the host computer.
Depending on the application, system calibration and linearization may be required. The size of C1 and the maximum measurement time depend on the light sensor, amount of light used in the application, and the internal voltage-reference setting.
In many other applications in which the measurement resolution and accuracy aren’t critical, such as detecting whether the lamp is 25% or 50% on, an even lower-cost microcontroller without any analog peripheral (such as the 8-pin PIC12C508) can be used. Instead of utilizing a voltage comparator with an internal voltage reference, the capacitor voltage measurement can be done on a regular I/O pin. The microcontroller now will measure the voltage ramp from 0 V to its high input threshold voltage. The system measurement error, stability, and repeatability will directly reflect the threshold voltage variations due to the system’s powersupply voltage, process variations, and the device temperature.
i am passing monochromatic(LED) light through a solution, i want to measure the absorbance of light,by using photoresistor and microcontroller(18f4520).reading should be displayed on lcd.can you please help me
santhanakumar -July 04, 2008
any way this could work on a basic stamp? I think it should be able to, but without any source code or conversion formulas I can't do it myself....
Anonymous -February 06, 2008
light intensity controller using microcontroller
nitin -August 14, 2007
cant u help me about my assignment aboutluminous intensity
edison -July 07, 2007
YOU SUCK THIS DIDNT HELP ME AT ALL!! DIE *****!
Anonymous -November 20, 2006 (Article Rating: )
Fine article but lacking on detail but it was a useful start.
paul -September 16, 2006 (Article Rating: )
dear sirs,
I am student of m.tech power electronics and i have got a minor project on LIHGT INTENSITY METER WITH LOW AND EXTREMELY HIGH INTENSITY WARNING AND INDICATION.can you help me out for the project.
Your article is very good, but i want to know the code's configuration for analog comparator module. Thanks
Billy -April 11, 2006 (Article Rating: )
Light sensors which can detect light of a room
Anonymous -February 11, 2006
Light sensors which can detect light of a room
Anonymous -February 11, 2006 (Article Rating: )
Can I get some info on the interface between light sensor and the micro where no voltage comparator is being used. Thank you
Raymond -February 07, 2006 (Article Rating: )
Hello sir, Your article is really good. Since am doing project in this topic, am in need of source code. If u help me, that will be very useful. Regards, Anand.
Anand -December 22, 2005 (Article Rating: )
only a mention of how to detect temperature from amount of light not told how it works
Anonymous -November 29, 2005 (Article Rating: )
the article seems to be informative for students who wish to pursue projects in the feild of automation. no details regarding the range of the sensors is given.
sudharshan -November 16, 2005 (Article Rating: )
your article is just give somebasic idea.I want to know about how to control the intensity of computer monitor and tell me something about one hand keyboard with figure
Anonymous -September 01, 2005
u have not mentioned here the output voltage that u get at photodiode/phototransistor.please mention it.
ashwini -August 21, 2005
This is not a good way to detect smoke. Dust build up on either the sensor or the emitter would produce the same effect.
JohnD -February 24, 2005 (Article Rating: )
Your article is very good, but there is not enough explanation on how to convert the electricity result, such as current, into the light intensity.
Seso -September 16, 2004
This artical is a good approach toward industrial automation. Good effort.
Shahzad -July 04, 2004
Your Comments:
Enter the text from the image below
Please refresh the page if you have trouble reading this text.
Search Electronic Design
Web Seminar
Sponsored By:
Title: Read Pacing: A Performance Enhancing Feature of PCI Express Gen 2 Switch Devices