Spectrum sensing

johndk

Senior Member
I'm doing some work with pulsing the individual elements of RGB LEDs. Now that I've got that code pretty well worked out, I need a good (and cheap) way to measure the light intensity, preferably in different parts of the spectrum. I'm considering using LEDs in reverse, but wonder if the picaxe has enough sensitivity to get a decent reading. If anyone has tried this, I'd appreciate some feedback.

Alternately, I'd purchase a ready-made sensor if there's one available at a decent price. I've got my eye on a light to frequency module, the TCS3200 Color Sensor, and wonder how good that is. I wouldn't be using the light source LEDs on that, so there would have to be a way to turn those off when taking measurements.

I pretty much need to cover the visible spectrum, no IR but a little near UV would be nice. I'm looking to measure the light intensity of my flashing units over periods of time. Ultimately, I need to know how much light has been produced in various regions of the spectrum. Although I can calculate these values from the timings I'm sending, I want the feedback to keep the data honest. There's no guarantee, for instance, that all my LEDs will operate at the same intensity throughout the run. So I'll use the sensor to take a snapshot every so often.

Ideas and suggestions welcome.
 

johndk

Senior Member
I'm not yet at that level of accuracy. At this point I'm looking for a double check. If the preliminaries go well, I'll need to invest in certified equipment or send it out to a lab for a fully qualified analysis. So, to answer the question, "I'm not".
 

AllyCat

Senior Member
Hi John,


Ideas and suggestions welcome.
For some time, I've been working on the possibility of measuring a wide range light levels (perhaps up to 1,000,000 : 1) using just a PICaxe. Not for specific wavelengths (colours), just "daylight", but perhaps still relevant to your application. Unfortunately, I have very limited internet access for a few days so can only offer a "teaser" at the moment:

Firstly, I think you need to measure the (short-corcuit) current through a photodiode to give useful linearity/accuracy. In practice, this seems to be very similar to the (photoelectric) reverse leakage current of the diode (at low voltages), and it's easier to remember in which direction this current flows through the diode. :)

A good method to measure this current is at the "virtual earth" (negative) input of an Op-Amp with negative feeedback applied. An external Op-Amp is the obvious solution, but I'm always striving for PICaxe designs using minimum peripheral components. PICAXEs don't have on-chip Op-Amps, but most do have one or more Comparators (although they are not directly supported by the PE for M2 devices). However, a comparator is not quite the same as an Op-Amp, but we can can actually take advantage of this by combining the ADC function (in the form of a current-to-frequency converter) :

Basically, connect the current source (photodiode) and a capacitor (perhaps 1 - 10nF) between ground and the comparator negative input, with a resistor feedback from the comparator output to the same input. With some hysteresis introduced the circuit becomes an oscillator, where the (short) pulse of current when the comparator output goes "high" balances the continuous current through the diode. However, several refinements are required which I will have to explain later. For example the input offset voltage of the PICaxe is rather poor, particularly when biassed around ground level.

Perhaps I will be able to say something useful about the LEDs, sensitivity and colorimitry aspects the next time I have some internet access.

Cheers, Alan.
 

eggdweather

Senior Member
This is the logic to use:

1. Wire an LED in series with a 220R resister between any two pins, such that the LED can be forward biased and hence lit or reverse biased to act as a light detector.
2. Configure one pin high and another low, to light the LED by making the anode positive (1) and cathode negative (0), this will light the LED and discharge the junction capacitance.
3. Now reverse the LED by changing the pin logic levels so the anode is connected to the same pin, this time (0) and cathode to a (1), which will charge the LED junction capacitance, it's small capacitance, so really only needs to be pulsed for 10-20mS.
4. Now change the pin that provided the (1) to the anode in step 2 to an ADC input and make the other pin a (0). Now the PICAXE can measure the charge voltage from the LED junction with a readadc command. Save it (temp-1).
5. Wait for the ambient light to discharge the LED junction capacitance, the longer you wait the more it discharges. So wait say 1-sec and take another measurement. Save it (temp-2).
6. Now subtract the two, so now temp1-temp2 is a form of measurement of the light level.
7. The longer you leave light to discharge the junction capacitance, the more sensitive the measurement.

This is routinely done with the Arduino chip, but I won't post any C code examples as it generates negativity - sorry.
 

johndk

Senior Member
Thanks for both suggestions. From my own reading as well as these posts, it seems I need to set up a simple LED oscillator circuit to do the measurement I'm seeking. I look forward to more detail. (I'm familiar with C. So don't worry about negativity from my part.)

The TCS3200 seems to do all of this in a nice little package and I've ordered a couple to play with. That is not to say that I will abandon my efforts at discrete color sensors. My goal is to disperse them over the lighted area to average the incident light. The TCS3200 is more of a pinpoint solution and becomes a little pricey for multiple locations. If I can use low cost RGB LEDs to get color discrimination, they would not only cost less, but take up less space as well.

If anyone has used the TCS3200, I'd like some feedback on that unit. Always nice to build on someone else's experience, much as I enjoy reinventing the wheel.
 

techElder

Well-known member
I appreciate the programming and coding complications in all of this, however, I still don't read anything that will allow you "... to keep the data honest. "

Unless you define a STANDARD to measure to, you just have numbers.
 

eggdweather

Senior Member
I suppose if various colour LED's are used and knowing their individual light frequencies, that will go some way towards establishing an overall reference, or indeed just one colour reference, making the measurements relative.
 

johndk

Senior Member
Just to clarify.

I'm not trying to create a spectrophotometer. Because I already know the spectral output of the LEDs I'm using for the light source (yes, provided the published numbers are accurate), I need only to verify that I'm getting the intensity for each color that I'm expecting from my code. If my reds are failing, for instance, I'd like to get an indication that there's a problem.

One of the problems with using LEDs for color detection is that they respnd to light at frequencies above (and not at or below) their light output wavelength. That means, using an RGB LED I'd have a short, medium, and wide sensitivity range. So I would have a three step range in which I could measure light levels. But I would be out of luck if my red sensing LED were at the same wavelength as my red source LED because the sensor would only respond to frequencies above its output range. Whether RGB or discrete, I'd have to select my sensor LEDs carefully, keeping that in mind.
 

rq3

Senior Member
Just to clarify.

I'm not trying to create a spectrophotometer. Because I already know the spectral output of the LEDs I'm using for the light source (yes, provided the published numbers are accurate), I need only to verify that I'm getting the intensity for each color that I'm expecting from my code. If my reds are failing, for instance, I'd like to get an indication that there's a problem.

One of the problems with using LEDs for color detection is that they respnd to light at frequencies above (and not at or below) their light output wavelength. That means, using an RGB LED I'd have a short, medium, and wide sensitivity range. So I would have a three step range in which I could measure light levels. But I would be out of luck if my red sensing LED were at the same wavelength as my red source LED because the sensor would only respond to frequencies above its output range. Whether RGB or discrete, I'd have to select my sensor LEDs carefully, keeping that in mind.
johndk, I don't think that's quite right. The original use of LEDs as photodetectors goes back to the 1960's, and used red LEDs to detect their own output. From a quantum mechanic level, that makes sense, although the output may be low.

I do know that it is possible to use a Picaxe to detect the photodiode voltage of a 1603 SMD LED and use the result to regulate the intensity of an array of LEDs. Like you, I have toyed with the idea of building an "almost spectrophotometer", but so far visual calibration (and a selection of micropipettes for dyes) has served well.

Rip
 

johndk

Senior Member
As much as I like to tinker, I also have to get this project done. I'm going to give the TCS3200 a try and see how that works. The specs show a good spectral response and it's a nice small package. After considering everyone's responses, I'm not sure I could build a home-grown one for less.
 
Top