CdS Photocell weirdness

I've stumbled across something very weird in the combination of Arduino and CdS photocells: when I regularly read a CdS photocell using the standard voltage divider arrangement on an Arduino analog input, it produces oscillatory outputs that closely approximate sine waves.

The amplitudes of these oscillations are roughly 5% of the average reading; their frequencies, however, vary with the frequency of the sampling rate. I tried sampling periods of 10 msec, 100 msec, 300 msec, 1000 msec, and 10000 msec, getting different periodicities for each sampling rate. The sampling rates between 100 ms and 1000 msec produced the closest approximations to sine waves; the sampling rates of 10 msec and 10000 msec produced jerky oscillations. Yet in every case, the periodicities appeared to be stable.

I also tried different analog pins, finding minor differences between them, but the differences were smaller than the amplitudes of the oscillations. I also tried using both the USB power source and the plug-in battery source; there was no significant difference.

I thought that somehow this might be the result of heating of the photoresistive material by the sampling current, but cooling the photocell with an air spray had only a tiny effect.

I also used an ohmmeter on the cell, getting a stable output to within 0.1%.

I also tested two very different photocells, getting much the same results with the two photocells.

I also ran the same test on a simple resistor, and got rock-solid stable output.

So we have some sort of interaction between the Arduino analog measurement system and the photocell. It looks for all the world like some sort of harmonic interaction, but I cannot for the life of me figure out what's going on here.

First, could somebody replicate my findings?

Second, does anybody have any hypothesis that would explain this weird behavior?

Third, can anybody suggest a workaround that would give me stable readings from the photocell?

Your light source is probably turning on and off faster than you can detect it. Florescent lights? LED lights?

Cover your sensor so it can't see light. What do you get?

Put your sensor in direct sunlight what do you get?

Paul

You nailed it! Yes, it's a beat frequency between the sampling cycle and the lighting cycle. I'm using all LED lighting. First I tried it at two sampling periods close to the 16.667 msec of the power: 16 ms and 15 ms. I figured that, with the other delays in the loop, these would come close to the LED frequency, producing very different beat frequencies. Sure enough, they DID produce very different beat frequencies. Then I got an LED flashlight, which operates on DC and therefore is continuous, turned off all the other lights, and illuminated the photocell with that. Sure enough, I got rock solid stable readings!

Problem solved. I must say, that's a damn good bit of sleuthing on your part! I'm impressed. Thanks so much.

Gee, I don't see any place to give a thumbs up or other recognition of your help. Am I blind?

Also, I see that you live in the central Oregon desert. I'm outside of Jacksonville, near Medford.

GeezerFrog:
Gee, I don't see any place to give a thumbs up or other recognition of your help. Am I blind?

Add Karma.

GeezerFrog:
You nailed it! Yes, it's a beat frequency between the sampling cycle and the lighting cycle. I'm using all LED lighting. First I tried it at two sampling periods close to the 16.667 msec of the power: 16 ms and 15 ms. I figured that, with the other delays in the loop, these would come close to the LED frequency, producing very different beat frequencies. Sure enough, they DID produce very different beat frequencies. Then I got an LED flashlight, which operates on DC and therefore is continuous, turned off all the other lights, and illuminated the photocell with that. Sure enough, I got rock solid stable readings!

Problem solved. I must say, that's a damn good bit of sleuthing on your part! I'm impressed. Thanks so much.

Strobbing has always been a very dangerous situation around rotating machines. Early fluorescent lights were very troublesome because of the short duration of the light from them. The mercury arc switches off and on at a 120 Hz rate. Today the phosphors stay light for a longer time and the problem is not so bad. LED lights sometimes had the same problem, but are also better, now.

Also, you are far from being the first new Arduino user to discover this problem and post about it on the forum.

Glad you have it fixed.

Paul