Here is the circuit I have set up in my breadboard

enter image description here

It is a light sensor using an LDR. I am using the op amp as comparator.

When indoors light is reduced, the LED lights up and I am able to set the lighting threshold with the help of the potentiometer.

But when indoors lighting is on, something strange (to me) happens. The LED is OFF except for a tiny region of potentiometer resistance. In this region, the voltmeter reads from -0.53 V to -0.29 V. This seems strange. When the voltmeter reads a value smaller than -0.53 V, the LED is OFF. This is logical. Additionaly, in a small region where the voltmeter reads positive values (from 0V up to 0.5 V) the LED is OFF. But if there is positive differential input, shouldn't the op amp go high?

Why the op amp behaves strangely in the aforementioned regions of the differential input voltage close to 0 V?

  • \$\begingroup\$ Maybe the LED light is feeding back to the LDR and forming an oscillator. \$\endgroup\$
    – Andy aka
    Nov 18, 2018 at 16:34

2 Answers 2


When the lights are on, the LDR can have a very low resistance, say 10 k ohm or less. That means that the voltage at the - input of the LM358 will be around 9 V * 100k/(10k+100k) = 8.1 V

So the opamp then needs to compare at 8.1 V when it's supply is only 9 V. It cannot do that ! The input voltage range of an LM358 is 0 V to supply voltage - 1.5 V. See "Voltage Range" in table 6.5 of the datasheet

So at a 9 V supply voltage you cannot expect the opamp to work properly above input voltages higher than 7.5 V. To confirm, measure the voltages at the inputs of the opamp and see if these rise above 7.5 V

The simplest way to fix this is to make the opamp's input voltages low when there is a lot of light:


simulate this circuit – Schematic created using CircuitLab

This then "moves" the issue to the "dark side" (pun intended). If you want to make the circuit better in dark situations you could consider replacing R2 with a 1 Mohm resistor.


Do you have access to an oscilloscope? This might provide you with more insight into what is going on. What sort of lighting do you have? Some lighting (florescent for example) will have a significant main frequency flicker component, which the LDR might be picking up. So although the average voltages should turn the LED on of off, there may be mains frequency voltages causing the LED to be on for some of the time only. Even of you don't have an oscilloscope, you could try placing a capacitor across R1 to smooth out any AC. Also, it is common with comparators to connect a very high value resistor between the output and non-inverting input as positive feedback or hysteresis to prevent oscillation around the switch point.

  • \$\begingroup\$ LDRs are generally quite slow in response so I don't think that the flickering can be an issue. \$\endgroup\$ Nov 18, 2018 at 12:02
  • \$\begingroup\$ I'm not sure they're so slow as to remove all mains frequency ripple. Your point about common mode input range being exceeded is a good one. You could also place a resistor in series with the LDR in its original position to restrict swing. \$\endgroup\$ Nov 18, 2018 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.