Analog in fluctuates periodically (0.5 - 0.2 Hz)

Hi all,

Since Google didn't get me any further, I hope this community can help me with this issue... While setting up an experiment involving the so called Mims-effect (after Forrest Mims, reading a voltage from a LED) I ran into the following problem: the voltage signal I try to read from the Arduino Uno analog input fluctuates periodically at ~ 0.5 to 0.2 Hz, depending on the exact configuration. The basic setup is as follows: I inserted the cathode of the LED in the GND socket and the anode of the LED in the A0 or A1 socket (so without the use of any wires/breadboard). The arduio was powered via the USB cable. I ran the following sketch:

int LED_pin = 0;
int LED_Value;

void setup()
{
   Serial.begin(9600);   
}

void loop()                    
{
   delay(100);
   LED_Value = analogRead(LED_pin);
   Serial.println(LED_Value);
   delay(100);
   LED_Value = analogRead(LED_pin);
   Serial.println(LED_Value);
}

I got a voltage (bits) vs. time (ms) signal, showing a fluctuation with a rather stable period of a little under 4 sec between 176 and 192 bits. Covering the LED or exposing it with a torch did give a negative or positive offset to the signal, so the Mims effect was detected. I've also ran the sketch without a LED inserted in the sockets. This also showed fluctuations but this time with a period of a little under 3 sec.

As an extra check I read out an LDR and a TMP36 with the same sketch. This showed very stable signals. Using different analog inputs gave similar results for all the described measurements.

Any clue what is going on here? It kind of ruins my measurements... :-(. I've been thinking about the following solution directions: using a capacitor between cathode and GND (0.1 uF or so?) or using an external reference voltage (like with a 9v battery and a voltage regulator?). Worst case perhaps I have to set up a buffer or some other kind of signal amplifying circuit. Are this useful approaches?

Kind regards,
Al

Any clue what is going on here?

Yep.

The analogue input is a very high impedance and is very prone to picking up interference, that is what you are seeing. Measuring small high impedance voltages is not an easy task. It requires the right sort of instrumentation amplifier with a circuit layout optimized for low pickup.

I am unclear about this experiment, you are not powering the led at all ? Is this one of those schemes to use the LED as a sort of photodiode ?

An unbiased LED (any diode, actually) acts as a photovoltaic cell and in sunlight will produce 1-2 volts depending on LED color but at very low current. The direction of the current flow is opposite the diode polarity (from cathode to anode). As an aside, LEDs respond to light in a fairly narrow range of bandwidths somewhat bluer than the emission color.

Depending on the sampling rate and capacitance of the diode (and associated circuitry) the oscillation that you see could be due to modulation of room lighting (50/60 Hz) and aliasing artefacts. Adding a capacitor (0.1 uF or so) should smooth out the signal.

Note that the current, not the voltage, produced by an LED is proportional to the light intensity. If you want to measure light intensity you need to convert the current to a voltage using a resistor. Normally this is done with an operational amplifier but in your setup you could try putting a 1 Meg resistor in parallel with the LED.

Dear all,

Thank you for your comments! The setup is indeed meant to measure a current that is induced by light that is received by the diode. So it is in a sense the opposite effect of normal LED operation, as nicely explained by jremington.

I have a few issues with believing that interference is the rootcause of my observations. It is most likely not the room lighting, for the simple reason that a covering the led still gives the fluctuation of the signal. So it must be caused then by some frequency content from the USB connection to my computer. Besides that I did another experiment: I measured the voltage over the led using a simple (~15 Eur) digital multimeter. It worked nicely, showing a ~ 50 mV signal when the flash light was on. I did not see any long term fluctuations. So if it is possible to measure the effect with a cheap multimeter, it should be do-able with an Arduino somehow, I would say.

Once I have some time (most likely early next week) I'll try the solutions offered above (capacitor and 1 Meg resistor). The AREF sollution seems a bit of a hasle, from what I read about it in tutorials. In case I need to use an op-amp, what kind of circuit would you suggest? A simple voltage follower, or something more complex?

I have a few issues with believing that interference is the rootcause of my observations.

Then start believing or get another hobby.

I measured the voltage over the led using a simple (~15 Eur) digital multimeter. It worked nicely, showing a ~ 50 mV signal when the flash light was on. I did not see any long term fluctuations.

No you won't see anything on a multimeter, these are too sluggish to register any such variations. Normally they take three about three measurements per second. Where as an arduino takes ten thousand measurements a second.

You can simulate a crappy meter on an arduino setup by sticking a capacitor across the input. or averaging the readings you get.

This current to voltage circuit is typical but requires a dual voltage (+/-) power supply. Just about any op amp will work. Google "photodiode current to voltage" for many more options, including variants that require only a single power supply.

Note: If you sample a signal at close to its frequency of oscillation or a (sub)multiple thereof, you will see a low frequency "beat" signal. This is called aliasing and is likely the cause of the modulation that you see. You are sampling at about 100 ms (delay plus time to print) or about 10 Hz intervals, which is indeed very close to a submultiple of 50 Hz. Modify your delay statements to see if the beat frequency changes.

I_to_V.jpg

How are you going to read your negative voltage with your a/d converter ?

Circuits like this that I've used require only a single supply and output a positive voltage proportional to the light intensity. But the one I posted will produce a positive output voltage if the LED/photodiode is oriented the other way.

The slow oscillations are a beat-frequency between the mains frequency you are picking
up as noise and the rate you are sampling at.

If you sampled at 1kHz you'd probably see the noise much more clearly.

Thanks again for all the comments. I've tried the offered solutions. The 1uF capacitor did not bring much, the observations observed were pretty much the same as without. The 1M resistor did help, but at the cost of the sensitivity of the "detector", it only gave a few mV signal with the flashlight right on it, and 0 otherwise. Inspired by the suggestion by MarkT I sampled the analog in at 100 Hz (approx) by buffering the data in an array before sending it over via the serial port using the following code:

int Delay_Val = 10;
int LED_pin = 0;
int LED_Value;
const int Samples = 500;
int s_val[Samples];
 
void setup()
{
   Serial.begin(9600);   
}

void loop()                    
{
   delay(500);
   for(int i = 0; i < Samples; i++) {
     s_val[i] = analogRead(LED_pin);
     delay(Delay_Val);
   }
   
   for (int ii = 0; ii < Samples; ii++) {
     Serial.print(ii*Delay_Val);
     Serial.print("\t");
     Serial.println(s_val[ii]);
   }
     
   Serial.println();
}

This resulted in the data represented in the first attached graph (blue: covered led, red: uncovered led --> exposed to daylight, x-axis: time [ms], y-axis: bit-reading A0). Based on this result I decided to go for a pragmatic solution to this problem: simply average the data over, say 100 ms at 1 kHz. This I tried using the following code:

int Delay_Val = 1;
int LED_pin = 0;
int LED_Value;
const int Samples = 100;
int s_val[Samples];
int sum_s_val = 0;
int av_s_val = 0;
 
void setup()
{
   Serial.begin(9600);   
}

void loop()                    
{
   //delay(500);
   sum_s_val = 0;
   for(int i = 0; i < Samples; i++) {
     s_val[i] = analogRead(LED_pin);
     sum_s_val = sum_s_val + s_val[i];
     delay(Delay_Val);
   }
   
   av_s_val = sum_s_val / Samples;
     
   Serial.println(av_s_val);
}

This resulted in data as shown in the second graph. This result looks quite OK to me, at least for detecting the Mims effect.

I did also try to make an Op-Amp circuit as suggested by jremington, but unfortunately I only had an LM358 available, so the inverted amplification did not work out.

Thank you all for you comments and suggestions!

Array_data_100Hz.JPG

Averaged_data.JPG