LM741 behaviour Question - Page 1
Forum section: electronics / beginners

author: higginsdj
author_rank: Contributor
timestamp: May 23, 2025, 04:39:08 am
content: I built the circuit shown to use an LDR to drive an LED On/Off based on light level. I thought a simple comparator circuit - it works BUT I do not understand what I am seeing in the measurements on the circuit. The output at pin 8 varies from -7.12v to 7.82v - Expected. The input at the Inverting Input is 4.5v - the VRef - Expected.However, the input at the Non Inverting input (on my oscilloscope) shows a typical charging and discharging capacitor curve with a DC Offset (1.92v offset with a 3.84v peak when the LDR is fully lit to 6.08v offset with a 6.64 peak when the LDR is fully covered). The result it that the output of the 741 oscillates with a square wave at 128hz with varying duty cycle between when the Non inverting input peak reaches VRef (1% duty cycle) to when the DC offset reaches VRef (100% duty cycle). Note the frequency of the charge/discharge cycle does not change with the change in voltage.There are no capacitors in this circuit BUT the circuit is on a breadboad. I am confused as to what is going on here.

author: David Hess
author_rank: Super Contributor
timestamp: May 23, 2025, 05:24:33 am
content: It is oscillating and needs some hysteresis. Put a 1 to 10 megohm resistor between the output pin 6 to non-inverting input pin 3.

author: Ian.M
author_rank: Super Contributor
timestamp: May 23, 2025, 06:03:39 am
content: The open loop gain of the LM741 is about 200000, so it only takes a tiny amount of light from the LED reaching the LDR (which is wired to turn the LED off when illumination increases), in combination with the notoriously slow response of a LDR to illumination changes, to cause oscillation - the LED lights, the LDR resistance starts to decrease, the LED then goes out, and the LDR resistance starts to increase till the LED lights, repeat ad-nauseum. As David points out, hysteresis is needed to keep the circuit from dwelling in the high gain linear region very close to its transition point, but as with any light level controlled switch that switches a lamp on when its dark, its important to shield the sensor from the light of the lamp as much as possible to avoid oscillation which is inevitable if the optical feedback overcomes the hysteresis.

author: higginsdj
author_rank: Contributor
timestamp: May 23, 2025, 06:28:04 am
content: Quote from: David Hess on May 23, 2025, 05:24:33 amThis made no difference to the behaviour.

author: higginsdj
author_rank: Contributor
timestamp: May 23, 2025, 06:43:18 am
content: Quote from: Ian.M on May 23, 2025, 06:03:39 amThe room is lit by an LED overhead light. The small Green LED is shielded from the LDR. The only light source impacting the LDR is the overhead lamp (and any reflected light from that light). Passing my hand over the LDR to shield it from the overhead light I can hold a position producing a relatively fixed Duty cycle and a solid 128hz oscillation. I tried 1M-10M resistors between output and pin 3 and saw no change to the behaviour. Could the overhead LED light be the source of the oscillation?

author: Ian.M
author_rank: Super Contributor
timestamp: May 23, 2025, 06:57:00 am
content: I would expect lighting flicker to be at either twice line frequency (i.e. 100 Hz) or a much higher frequency.Eliminate the LED e.g. by removing it and using your DMM on volts to monitor the output and see if the oscillation stops.

author: Zero999
author_rank: Super Contributor
timestamp: May 23, 2025, 07:24:38 am
content: Check your wring. Note the op-amp has a dual power supply. Do you have two 9V batteries or DC power supplies in series?I notice there's no decoupling capacitor?Please post a photograph of the construction.

author: Ian.M
author_rank: Super Contributor
timestamp: May 23, 2025, 08:24:33 am
content: Zero999 has a good point. The LM741 min. specified supply voltage is +/- 5V, which is 10V if you are using a single supply. If you are using a single small 9V battery (PP3), you are out of spec even with a brand new battery, and its possible the relatively high internal resistance of the battery, combined with the additional load of the LED switching on is modulating the supply voltage enough for feedback due to insufficient PSRR to cause oscillation. The time constant would be due to chemical reactions and ionic mobility in the battery.If you are using a battery supply, try covering the LED (including its back) with blu-tack to block all light from it. If it still oscillates, its almost certainly due to insufficent PSRR at the low supply voltage.

author: Terry Bites
author_rank: Super Contributor
timestamp: May 23, 2025, 10:13:46 am
content: It’s hard to add meaningful hysteresis in this circuit. Hysteresis needs to be independent of the sensed input voltage. Solution, swap over pins 2 and 3 so the reference voltage now appears at the non-inverting terminal and the LDR divider is connected to the inverting terminal. Connect the LED and its resistor from +9V to the opamp output. Increase the LED resistor to 680R to get the same brightness. The circuit now performs as before. Now put a high value resistor between pins 3 and 6 say 100k to 1Meg.The LED current is ~18mA and that could cause voltage transients on the power rails which then feedback into the opamp. And with no or very little hysteresis a tiny small blip is enough to cause unwelcome positive feedback.No capacitors at all? Try adding 100n caps from pins 4 and 7 to ground. Put the caps as close to the opamp as possible. Text book circuits often (usually) ignore the need for power supply decoupling/ bypassing. Note that the majority of modern opamps cannot be operated as comparators. A 741 is one of the exceptions. If you need a comparator, use a comparator.Moan....The 741 came to market in 1968, before man walked upon the moon and Bob Widlar was only smoking two packs a day.A lot of learning material seems to be still stuck at that point in time when the five opamps avaiable then would all work as comparators.See what I mean.www.electronics-tutorials.ws/opamp/op-amp-comparator.htmlnot a mention.Though it does point out that you can't use a comparator as an opamp!

author: David Hess
author_rank: Super Contributor
timestamp: May 23, 2025, 10:36:49 am
content: Quote from: higginsdj on May 23, 2025, 06:28:04 amThen lower the resistance to increase the hysteresis.

author: MK14
author_rank: Super Contributor
timestamp: May 23, 2025, 02:22:52 pm
content: Quote from: higginsdj on May 23, 2025, 04:39:08 amLDRs, usually have very significant delays, between resistance changes, due to light level changes. Such as 20 milliseconds. They can even take several seconds or longer, to properly/fully settle.I suspect that, combined with (already mentioned by Ian.M), the rooms LED lamp, flashing on and off, at that sort of frequency or more. The tens of millisecond LDR resistance change (gradual overtime), can then interact with the rooms LED flicker/flash rate, perhaps producing the oscillation frequency you observed (like a beat-frequency or similar).Hysteresis might help, but maybe not. But I think the big delay that the LDR already naturally introduces, will in effect self-stabilize the signal enough to make it unnecessary. Because when it has switched/flipped the 741 output (assuming fixed new light intensity level), the LDR will carry on moving in the direction of resistance change, as it finishes settling in to its new resistance level.Maybe capacitive (RC) filtering, perhaps with a capacitor across R3, might improve the situation? Possibly something like 10µF.Quote from: Terry Bites on May 23, 2025, 10:13:46 amYou want to be careful. Because (as I assume you know), LEDs (depending on colour and type (chemistry)), can be fairly bright even at 2 volts and with little current. A 741 only seems to guarantee 3 volts maximum voltage drop, between the output and supply rail (output voltage swing). So, the output LED, might end up never fully turning off.From a marginal design point of view, it MAY just work, depending on how good your actual 741 is (typical figures should just about or fully turn the LED off).Edit:On reflection, hysteresis may still be needed, especially in rare cases, where the light level, is going to coincidentally settle on JUST the right switching transition level. But if so, I would have expected higher frequency oscillations, than you have been seeing, such as tens of kHz.

author: tooki
author_rank: Super Contributor
timestamp: May 23, 2025, 04:59:20 pm
content: Clickbaity title aside, this covers some really sound reasons to avoid the 741, as well as elucidating a bit on op-amp characteristics in general:

author: higginsdj
author_rank: Contributor
timestamp: May 24, 2025, 12:22:16 am
content: Quote from: Zero999 on May 23, 2025, 07:24:38 amI have 2 DC power supplies wired up in series with the centre point as ground. No caps (I am using a circuit from an Online course). Photos attached. (Note I have switched over to an LM358 in the photo and see the exact same behaviour)

author: higginsdj
author_rank: Contributor
timestamp: May 24, 2025, 12:32:52 am
content: Quote from: MK14 on May 23, 2025, 02:22:52 pmThe output of the 741 on a dual rail swings from +7v to -7v (in my case) so the LED 'turns off' because it blocks reverse current. On a single rail (0-9v) - yes the LED does not switch off because the output does not drop below 2v.

author: MK14
author_rank: Super Contributor
timestamp: May 24, 2025, 12:38:13 am
content: Quote from: higginsdj on May 24, 2025, 12:32:52 amWhich sounds fine. I was really pointing the comment, at the other poster, who was suggesting a different circuit configuration.The main point of my post, was to explain why I think the oscillations you see, are to be expected and normal, given what you have described (i.e. LDR's significant delay, messing things up, and the room LEDs bulb, assumed to be, flashing/flickering).

author: themadhippy
author_rank: Super Contributor
timestamp: May 24, 2025, 01:13:42 am
content: As a sanity check id be tempted to nip out the ldr and replace it with a pot

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 24, 2025, 01:36:02 am
content: Adding a resistor between pins 2 and 6 does add hysteresis,but 1Meg only adds a very small hystereses, expecially with only 1k input resistance. So try a lower value resistor. 100k, 10k or even 1k are all valid to try.Replacing the LDR with a potentiometer is also good for testing. Especially if your poteniometer has a scale on it.One problem with an opamp used as a comparator is that when the output switches, the input offsets also change, and this can lead to oscillations near the "balance point". By adding hysteresis you go quickly and only once though the small zone where oscillations can occur.For a rough estimation, assume you want 10mV of hysteresis, from a 15V output sweep, (That is a ratio of 1500), then the hysteresis resistor be 1500x bigger then the input resistance. Your input resistance is about 1k. (resistorR3 parallel to LDR R4) and this results in 1M5. So apparently the input characteristics shift by more then 10mV.

author: Xena E
author_rank: Frequent Contributor
timestamp: May 24, 2025, 04:01:35 am
content: Unsurprising behaviour, it's what you'd see if the circuit input was at switching threshold, with no hysteresis.Quote from: themadhippy on May 24, 2025, 01:13:42 amYup...Quote from: MK14 on May 24, 2025, 12:38:13 amModulation?...Decouple the supply!Try illuminating with an incandescent lamp from a DC source.Post a photo of the layout? 🤨(Don't build your circuits with long fly leads, or on soggy toast...theabsolutely very best way to create an oscillator.)Regards,X

author: higginsdj
author_rank: Contributor
timestamp: May 24, 2025, 04:54:48 am
content: Quote from: Doctorandus_P on May 24, 2025, 01:36:02 amA 10k resistor did the trick - the oscillation was there at the LDR but the output just switched. A different LED Lamp produced a shallow sinusoidal oscillation at the LDR so the LED desk lamp was the primary culprit.Cheers