LED PWM and Photodiode

Hello everyone,

I am currently trying to set up a simple spectrophotometer in which I have 10 LED's of different peak output wavelengths ranging from 400 to 700 nM, and I have a photodiode (this one to be specifichttp://www.mouser.com/Search/ProductDetail.aspx?R=TSL257-LFvirtualkey57530000virtualkey856-TSL257-LF.

The setup is as follows: The LED's are mounted on a circular PCB that is attached to a stepper motor. A sample test tube is placed between an LED and the photodiode, and the motor rotates the LED disk and shines different LED's through the sample while the diode makes the reading.

The stepper motor is driven using a simple L293/298 pair and is pulsed by the Arduino using a digitalWrite HIGH/LOW loop. The diode emits a signal ranging from 0 to 5 V and is being read using analogRead, and the LED's are being driven and dimmed using analogWrite.

The issue I am having is that when an LED is driven using PWM, the sensor is fast enough to be able to detect each pulse of the LED. When hooking up the photodiode to a scope and having it read the intensity of the LED, it fluctuates between ang. This is because the response time of the diode is less than 1 microsecond as given by the data sheet. So when the Arduino does an analogRead on the sensor pin to get its voltage, the voltage could be pulsing anywhere between 0 and 0 to 5 V at the rate of the LED PWM while the reading is occurring (because it takes about 100 microseconds to perform an analogRead), so I get all sorts of analogRead values that are useless. When illuminating the photodiode using digitalWrite and dimming the LED using a filter of sorts, the analogRead values are 100% accurate because the light isn't pulsating.

So what do I do to get an accurate value of light intensity when dimming the LED using PWM???

I wanted to know how I could go about obtaining an accurate reading from the photodiode

you could set a treshlod and then average the values for a second ;)

The problem is that if the actual value should be like 500, the arduino gets all kinds of readings from 0 to 1000, so averaging wouldn't do anything for me.

It sounds like you want to generate a true analog current through each LED instead of PWM, right? Here is the type of circuit I think you will want:

http://ruggedcircuits.com/html/circuit__20.html

NOTE: This circuit will NOT work for your application ā€“ it is just the form Iā€™m suggesting. First, you do not want to output 10V to the photodiode but some voltage above its forward voltage and use a resistor to limit current. Second, you will need an op-amp with higher drive current, one that can illuminate the LED to your desired brightness.

The details are what will determine the right op-amp and resistors to use.

An alternative solution is to use a constant-current LED driver and a digital potentiometer to set its current level, but I think this is more complicated.

ā€“
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected

Sounds like what you need to do is feed the photodetector output through an integrator. That'd give you the "area under the curve". But you'd need to control the integration time. And keep it in phase with the PWM, so you're not integrating partial pulses.

You might be able to get by with an RC filter, like the ones people use to turn a PWM output into a continuous analog voltage. You may have problems with ripple, though. Maybe two stages of filtering, with a really long time constant in the second stage??