I've been working with some photodiodes (Honeywell SD3410-001) to create a brightness detecting display that turns on when it is dark. Instead of a simple on-off mechanism, I wanted to see if I could create a fade in/fade out mechanism using the value read from the photodiodes and mapping the value between 0 and 255 to send to the analogWrite() function.
I followed this tutorial to get an idea of how to use the photodiodes, but noticed that there are a lot of fluctuations in the readings. I plotted the value out and saw that this was happening:
Mapping these values directly to analogWrite will cause the LED lights to flicker a lot, so I tried averaging the values out... But the sinusoidal pattern still persists.
I want to know why this is happening. I've searched the forum a bit and saw that it might be due to the voltage provider of the Arduino (I am using the USB port to provide power) or because of the frequency of the lights themselves. It happens in sunlight too, so I'm guessing that it's due to the voltage provider...
Not without seeing the properly posted code (use code tags) and a circuit diagram (not Fritzing, please). The tutorial you linked does not use a photodiode, it uses an LDR.
From the Due's analogue-in part of the datasheet:
"Applying more than 3.3V on the Due’s pins will damage the SAM3X chip."
I think I see the photodiode connected to 5volt.
Leo..
No, that diagram is not helpful. We need to know exactly how you have wired the collector and emitter of the phototransistor. The collector should be connected to 3.3V.
If you wired it backwards, it might have been destroyed by applying 5V, as that is the EC breakdown voltage.
See above about damaging the analog input!
Since the saturation voltage drop of the phototransistor is about 1.1V, this gives you very little dynamic range for light levels. This part is not a good choice for your project.
Wow, thanks for pointing the 3.3V out! I switched to a different board just in case I damaged the other one. The original one, thankfully, seems to operate okay...
jremington:
No, that diagram is not helpful. We need to know exactly how you have wired the collector and emitter of the phototransistor. The collector should be connected to 3.3V.
According to the data sheet, the one closest to the little tab on the casing (as can be seen from the picture) is the emitter. Thus, like you said, the collector is connected to the 3.3V (not 5V anymore).
I'm going to use the newly wired set and see what it does in sunlight tomorrow. That will help me figure out what the cause of the fluctuations is.
allanhurst:
Take an average , or provide some analog smoothing.
What are some analog smoothing methods I can use? I've read some things about moving averages, but I wonder if you guys have any other suggestions.
Wawa:
Assuming you want to measure ambient light...
Can't you just use a slooow photoresistor (LDR).
And a cap across, to make it even slower.
+1
If you still want to use the photodiode:
To filter the signal, you could use a single-pole digital filter, and then use hysteresis to decide whether to turn on or off the lights.