Oscillating output from op amp with analogRead

I'm using a phototransistor in a common emitter configuration to capture the brightness of an LED. Since i'm operating on a pretty small range (due to the low brightness of the LED), I hooked up the PT output to an op amp in a non-inverting, negative feedback config, with the PT output connected to V+, a 10k R between Vout and V-, and a 220 R between V- and ground. So my expected gain is in the ballpark of 46x. My power supply is 5V.

I used analogRead(A0) on my UNO to read Vout, but the problem is that my reading oscillates significantly; with everything else stable a particular reading can oscillate between 2.51V - 2.76V with a period of around 1.5s. Strangely, I get stable readings with a multimeter, which means the problem may lie with the UNO board. I've attached a reading from the serial plotter where you can see the oscillation waveform.

Anyone experienced a similar issue before?

Data sheets for the op amp and photo transistor are below:

A schematic drawing would help a lot. Op-amp circuits can be a little tricky. Figure 4-12 on the datasheet gives a circuit that should work for what you are doing.

My first thought is that a 1.5 second period is very very slow for an opamp.

Given not much information I might guess it is 60 HZ pickup (or 50Hz) that is being sampled at nearly 60 Hz or 30 Hz. The result you see could be the difference frequency between the noise 60 Hz and the sampling frequency.

Your multimeter will filter out such variations.

Remember, the UNO A/D is like taking a flash photo of someone moving. The photo will show the subject for only that instant. Likewise the UNO A/D will take a measurement that is near instantaneous as far as your project is concerned.

Easiest way to make an oscillator is trying to make an amplifier and vice versa. :slight_smile:

I've attached my schematic so its clearer what i'm building.

JohnRob:
My first thought is that a 1.5 second period is very very slow for an opamp.

Given not much information I might guess it is 60 HZ pickup (or 50Hz) that is being sampled at nearly 60 Hz or 30 Hz. The result you see could be the difference frequency between the noise 60 Hz and the sampling frequency.

Your multimeter will filter out such variations.

Remember, the UNO A/D is like taking a flash photo of someone moving. The photo will show the subject for only that instant. Likewise the UNO A/D will take a measurement that is near instantaneous as far as your project is concerned.

I'm using a DC source, is sampling frequency relevant?

Wangmaster's pic:

I would start by removing Q1 and replacing it with a resistor, say about 1k. See if the circuit gives stable readings. It's possible that you are picking up flickering in your light source.

Also, do you have a decoupling cap across the op-amp power pins? Usually a .1uF. You might also need about 10uf along with that to smooth the supply. Both caps should be very close to the chip.

After that, a cap across the 10k resistor in the feedback (220pf might be a decent value), maybe even up to .1uf to slow the response and eliminate oscillations.

Op amp circuit layout can be very critical. Many schematics drawings are perfect, but how the parts are laid out will ruin the design. A picture of your project might help a lot.

I'd say its 95% likely this is mains frequency variation in the stray light aliased down to 0.6Hz by sampling not
quite at a multiple of 50/60/100/120 Hz or whatever. So what is the sampling rate?

Wangmaster:
Strangely, I get stable readings with a multimeter, which means the problem may lie with the UNO board. I've attached a reading from the serial plotter where you can see the oscillation waveform.

Not strange at all. Look at the specs for your MM. You may find that the MM has a high input impendence. With that bit on information you may want to look into matching, more closely, the input impendence of the A:D.

Think of your MM as a resistor that you are putting between the measuring point and ground.

Wangmaster:
I'm using a phototransistor in a common emitter configuration to capture the brightness of an LED.

Interesting notation. I believe you meant "emitter follower", but really with the bases not connected (as there is rarely any reason to do so and newer devices do not offer a base connection,) there is no actual distinction; they are merely a two wire polarised component.

Hi,
How do you know the period of the oscillation is 1.5s?

You can use the Serial Plotter as the x axis is not a constant time base.

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,
How do you know the period of the oscillation is 1.5s?

You can use the Serial Plotter as the x axis is not a constant time base.

Thanks.. Tom.. :slight_smile:

OP posted the graph below, but the axes have no labels:

The period seems to be 25 of whatever the x axis is.

Hi,
Each point on the X-axis is a Serial.print statement, so it will be loop time.

Not a constant time interval, with Serial speed thrown in.

Tom... :slight_smile:

Maybe could try putting a 5 or 10 microfarad capacitor in parallel with your 20 kohm resistor, and see what happens.

TomGeorge:
Hi,
How do you know the period of the oscillation is 1.5s?

You can use the Serial Plotter as the x axis is not a constant time base.

Thanks.. Tom.. :slight_smile:

Yup i know the serial plotter axes arent that reliable, 1.5s period is from my own timing.

Im also quite confused, im using a DC source here, is impedence relevant in this case? Or is my 5V arduino power an oscillating DC source?

unless you're in a field far from any power lines, you can pickup mains ac interference. The higher
the circuit impedance, the more susceptible it is to pickup.

In a typical home the stray ac voltage fields around the place can easily be dozens of volts.

And if you have a light sensor near any mains powered lighting, the light itself is modulated
at twice the mains frequency.

Wangmaster:
Yup i know the serial plotter axes arent that reliable, 1.5s period is from my own timing.

What method did you use for your own timing? And what scale is the x-axis in that plot?

I ran several tests and found that most likely, it was the fluorescent tube in my lab causing aliasing issues in my readings. Running the test in the dark with just my LED seems to solve the problem, adding a capacitor was icing on the cake.

I discounted the fluorescent lighting as the root cause earlier since the un-amplified photo-transistor reading seemed stable enough in Fl light. The aliasing waveform probably became significant once amplified 45 times.

Resolved, thanks for the help all.