UNO analog inputs cycling to 0 every 25s

Hi, I have a project using 4 green leds as light sensors.
The test code loop is really simple:
Serial.Print(analogRead(0);
Serial.Print(" ");
etc for analog inputs 0-3,
delay(1000);

I get good readings to start with, then the inputs appear to randomly drop to all 0.
After a few seconds, the values climb back up to where I expect them to be,
then the cycle restarts.
A voltmeter on a led shows a constant 0.3V.

What's going on here?

TIA

Insufficient information.

Possibly a problem in the sketch that you haven't shown us or the schematic that you haven't shown us?

1 Like

More info needed, but probably, you're cycling in and out of sync with Incandescent or LED lighting. You might be able to prove this, if you can move outside, away from man-made lighting (even outside, parking lot lights might also be a problem, for example). You'd then be able to sense your hand obscuring the LEDs, for example.

The LEDs are very inefficient as sensors, but will pick up a little bit of this.

Most likely the circuit is wrong. Post the schematic diagram.

Just a guess and a suggestion -

If you have fluorescent or LED lighting it may be flickering (faster than you can see) and you are reading the light for one instant every second and the readings will "look random". (1)

A multimeter has some filtering. You may be able to use some electronic or software filtering/averaging, depending on how fast it needs to react.

You can make a voltage divider (2 resistors) to duplicate the 0.3V and if that's not more-stable, you've got a software problem.

(1) The same thing happens when you sample audio, which is a constantly-changing waveform... The readings "look random".


This sensor has worked OK with another CPU, a few years ago.

Hi camsysca, that is something to check in normal daylight tomorrow.
You get a similar effect in a video of a prop-driven aircraft, where the prop seems to be turning at 100rpm.

Your circuit is very dependent on the input characteristics of the analog inputs, in particular as you read inputs, charge transfer is likely from one input to the next, spoiling your experiment. Still, it's worth playing with.
FWIW, to avoid charge transfer issues, it's also worth discarding the first read of each input as you scan through them, only keeping the second and subsequent values.

Usually, though, the video effect is a beat pattern between the video and the device being viewed. Similarly, it can appear that a tire/wheel is spinning in reverse in old video footage.

If I modify the loop delay, & insert different small delays between the analog reads, the display is all over the shop!
I shall try adding some capacitors to the leds, to calm things down.

Always keep these bits of info from the 328P datasheet in mind when using the analog inputs:

The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the S/H capacitor, with can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer to the S/H capacitor.

Signal components higher than the Nyquist frequency (f ADC /2) should not be present for either kind of channels, to avoid distortion from unpredictable signal convolution. The user is advised to remove high frequency components with a low-pass filter before applying the signals as inputs to the ADC.

The LEDs require load resistors, as photodiode current output is proportional to the light intensity. Choice of load resistor is not trivial, because the ADC requires source low impedance (20K maximum) for accurate readings.

Look up "transimpedance amplifier" to learn about how photodiodes are normally used to measure light intensity.

Note that LEDs used as photodiodes respond only to light in a narrow wavelength band, shifted to typically 50 nm shorter wavelength than the emission band.

Hi DVDdoug, looking with my scope (fiinally!), I see a lot of 50Hz noise, but with very low p-p values.
Also, with a potentiometer on an input, I get stable readings (+/-2), but random readings on the other inputs.
I will try your idea of a divider network on the inputs, to see if the readings become stable (I guess this will be so).
Next, to check if the sensors can influence (correctly) the inputs.

When I used this sensor before, there was a lot of software handling the I2C ADC, which maybe added some damping. Also, I think the ADC handled open inputs differently. I never saw random values.

Regards,

Diksan

That could certainly explain a lot.

What kind of light are you trying to detect?

Hi jim-p, I'm trying to detect sunlight for a heliostat project (I'm retired, so I need some intellectual simulus. I don't do Sudoku, but I do play a lot with Arduinos!).

Concerning the discussion, I have put 68K+68K resistors on the 4 inputs, & the results are stable. E.g:
511 513 511 509
511 513 510 509
511 513 511 508
511 513 512 509
511 513 510 509
511 513 510 508
Now to see if the sensors work.

Regards,

Diksan

Since I cannot come up with any physical explanation as to why the reading go through that 25 second cycle in sunlight, I would appreciate your letting us know the results of the last test.

Hi jim-p,
That 25s cycle occured at night! I have not discovered another solar cycle :slight_smile:
I have had no luck this time with using leds as sensors.
I have just done a test with an LDR, which gives an acceptable range of values.

I'm thinking that the analog inputs float, if nothing is connected. That would explain the random values. Note that an unused analog input on the Arduino is used for the random function!

The 25s cycle, with a +/-1s code loop, is probably caused by all the 50Hz noise in my place of work. I could see spikes at 50Hz & 100Hz on my scope, using the FFT function.

I am about to order some LDRs to continue the experiment.

Regards,

Diksan

That also explains a lot.

I'm thinking that the analog inputs float, if nothing is connected. That would explain the random values.

If nothing is connected, yes it would but you have LEDs connected.

The 25s cycle, with a +/-1s code loop, is probably caused by all the 50Hz noise

Isn't this device outside? Are you trying to measure sunlight through a window?

That will continue until you decide to add load resistors for the LEDs.

Photodiodes are current sources, not voltage sources.

1 Like

I guess this is just an error in the opening post, but I presume you were not wanting to analog read the serial Rx pin but meant this:

Serial.Print(analogRead(A0);