The only electronic website that replies to every comment, and addresses all circuit related issues.

## How to Use an Opamp as a Comparator

In this post we comprehensively learn how to use any opamp as a comparator in a circuit for comparing a input differentials and producing the corresponding outputs.

We've been using an opamp IC probably since we started learning electronics, I am referring to this wonderful little IC 741, through which virtually any comparator based circuit designing becomes feasible.

It almost alone is able to handle many complex functions and makes circuit configuration very easy, that's why its one of the favorite chips not only with the new electronic hobbyists but also with the experienced engineers.

Here we are discussing one of the simple application circuits of this IC where it is being configured as a comparator, no surprise the following applications can be modified in numerous different ways as per the user preference.

As the name suggests, opamp comparator refers to the function of comparing between a particular set of parameters or may be just a couple of magnitudes as in the case.

Since in electronics we are primarily dealing with voltages and currents, these factors become the sole agents and are used for operating or regulating or controlling the various components involved.

In the proposed opamp comparator design, where the IC 741 is being used as a comparator, basically different voltage levels are used as the referring and comparaing parameters by the IC.

The two input pins named the inverting (with a minus sign)and the non-inverting pin (with a + sign) become the sensing inputs of the IC 741.

When used as a comparator, one of the pins out of the two is applied with a fixed reference voltage while the other pin is fed with the voltage whose level needs to be monitored.

The monitoring of the above voltage is done with reference to the fixed voltage that's been applied to the other complementary pin.

Therefore if the voltage which is to be monitored goes above or falls below the fixed reference threshold voltage, the output reverts state or changes its original condition or changes its output voltage polarity.

Let's analyze the above explanation by studying the following example circuit of a light sensor switch.

Looking at the circuit diagram we find the circuit configured in the following way:

The IC 741 is at the center.

Its Pin #7 which is the +supply pin is connected to the positive rail, similarly its pin #4 which is the negative supply pin is connected to the negative or rather the zero supply rail of the power supply.

The above couple of pin connections powers the IC so that it can carry on with its intended functions.

Now as discussed earlier, pin #2 of the IC is connected at the junction of two resistors whose ends are connected to the power supply positive and negative rails.

This arrangement of the resistors is called a potential divider, meaning the potential or the voltage level at the junction of these resistors will be approximately the half of the supply voltage, so if the supply voltage is 12, the junction of the potential divider network will be 6 volts and so on.

If the supply voltage is well regulated, the above voltage level will also be well fixed and therefore can be used as the reference voltage for the pin #2.

Therefore referring to the junction voltage of the resistors R1/R2, this voltage becomes the reference voltage at pin #2 which means the IC will monitor and respond to any voltage that might go above this level.

The sensing voltage which is to be monitored is applied to pin #3 of the IC, in our example it is via an LDR. The pin #3 is connected at the junction of the LDR pin and a preset terminal.

That means this junction again becomes a potential divider, whose voltage level this time is not fixed because the LDR value cannot be fixed and will vary with the ambient light conditions.

How an Opamp Comparator Functions

Now suppose you want the circuit to sense the LDR value at some point just around when dusk falls, you adjust the preset such that the voltage at pin #3 or at the junction of the LDR and the preset just crosses above the 6V mark.

When this happens the value rises above the fixed reference at pin #2, this informs the IC about the sense voltage rising above the reference voltage at pin #2, this instantly reverts the output of the IC which changes to positive from its initial zero voltage position.

The above change in the state of the IC from zero to positive, triggers the relay driver stage which switches ON the load or the lights which might be connected to the relevant contacts of the relay.

Remember, the values of the resistors connected to pin #2 may also be altered for altering the sensing threshold of pin #3, so they are all inter-depended, giving you a wide angle of variation of the circuit parameters.

Another feature of the R1 and R2 is that it avoids the need of using a dual polarity power supply making the involved configuration very simple and neat.

As shown below, the above explained operation response can be just reversed by interchanging the input pin positions of the IC or, by considering another option where we only inter-change the positions of the LDR and the preset.

THis is how any basic opamp behaves when it is configured as a comparator.

To summarize we can say that in any opamp based compartaor, the following operations take place:

Example#1

1) When the inverting pin (-) is applied a fixed voltage reference, and the non-inverting (+) input pin is subjected to an altering sensing volatge, the output of the opamp remains 0V or negative as long as the (+) pin voltage stays below the (-) refernce pin voltage level.

Alternately as soon as the (+) pin volatge goes higher than the (-) voltage, the output quickly turns positive supply DC level.

Example#2

1) Conversely, when the non-inverting pin (+) is applied a fixed voltage reference, and the inverting (-) input pin is subjected to an altering sensing voltage, the output of the opamp remains supply DC level or positive as long as the (-) pin voltage stays below the (+) refernce pin voltage level.

Alternately as soon as the (-) pin volatge goes higher than the (+) voltage, the output quickly turns negative or switches OFF to 0V.

•  Stumble

1. Thanks alot.
Please how do I use LM324 for this same purpose.

1. Welcome, see the IC324 datasheet, you will find it has four opamp blocks, each resembling the IC741, use them as discussed in the article.

2. hai swagatam your projects are so nice .it is useful for me. and one help for me.using IC741 or 555 we need to design a circuit and make a project. so please send some ideas for my projects contact me at rethinavelpreethi@gmail.com thanks for your wonderful works

1. Hi Preethi,

Thanks very much!

There are plenty of circuits which can be made with 555 and 741 ICs, some are very simple, some are moderate and others are difficult....what kind of circuit would you prefer??

3. HOW TO DESIGN A CIRCUIT USING 741 IC COMPARATOR WHICH GETS ON WHEN IT IS GETTING 2.5V SUPPLY AND TURNS OFF WHEN IT GETS 1.5V SUPPLY AND IT SHOULD GET ON ABOVE 2.5 V SUPPLY

1. opamps don't work at 1.5V, so it might be a complex circuit if designed.

4. Hi Swagatam,
I plan to use LM339 as comparator. My input voltages are in the range 0.3 to 1.2V. The output should be 0V for inputs less than 0.3V. Do I need to use an amplifier or will it work without one ?

1. I think an amplifier won't be required, you may connect the supply directly with the relevant inputs of the IC

5. hi swagatam
i tried this kind of circuit but all resistances as 1kohm
at the end i used an led to show the output but when am connecting my comparator circuit to the sensor the LED is glowing for any output of the sensor
actually i used another ic741 after the comparator to invert the out put of comparator
i dont under stand why the LED is glowing even if am switching off the whole power supply for IC's in the bread board n jus the sensor output
thanq

1. Hi Naiduanvesh,

this might be happening due to two reasons:

either the output resistor with the led is too low in value and is unable to restrict the leakage voltage at the output of the IC.

or the sensor is not providing sufficient change in order to make pin3 of the IC go higher than pin2.

6. I've seen a very similar circuit used to detect a low-battery condition. Instead of R1/R2 a 1K resistor and a 4.7V Zener is used. My question is: say I'm using a 9V battery and I want the LED to come on at 5.0V, how does the PRESET come into play? Can you explain the procedure?

1. since in the zener circuits the preset is connected to pin#3 of the IC, it should be adjusted such that the voltage at pin#3 just exceeds the zener voltage at pin2 when the supply voltage is 5V. This will make the output go high illuminating the connected LEd. The LED will remain ON as long as the supply voltage is higher or equal to 5V

2. Thanks, I got it working!

7. file:///C:/Users/user/Desktop/I%20am%20rich/power_inverter_op_enlarged.gif gud evening sir,using the circuit in this link above,pls can u give me a brief explanation of happens in d shut down circuit using d voltage divider and my ics.

1. good evening...the image is not opening.

8. Hi,thanx a lot for your projects .How do I go about constructing a minute circuit which senses light and create an alarm if the light gets below a particular set value?

1. Hi, thanks, you can try the last circuit shown in the folowing article:

You can replace the relay with a small buzzer for getting the required alarm.

9. Hi Swagatam, I am trying to make a kind of comparator cum voltage level detection circuit. Basically there are two main components to it. First is the strain gauge which gives either NEGATIVE voltage or POSITIVE voltage - only one is present at a time. Now whenever this voltage is present I require an output of 5 VDC from the circuit. This 5volts should be triggered when the input voltage is either 2.5 V and above or -2.5V and above i.e. upto -5 volts. I want to use dual rail 12 volt supply as it is available with my system. Kindly suggest me a circuit design.

1. Hi Janesh, you can do it by using two 741 IC opamp configured as comparators, as shown in the above diagrams, but the supply will need to be dual not single. It should be dual 5V supply since the required output is 5V

So the supply (+)5v and (-)5v go across the R1/R2 and the pin7/4 rails.

The outputs of the two opamps may then be connected to the input of a bridge rectifier...the output from the bridge will generate the intended 5V for the specified conditioned.

one of the opamps will have its pin3 clamped with +/- via rail via R1/R2 while the other with its pin2.

The free ends of the relevant opamp inputs could be configured with the strain gauges.

The +/- 5V supply can be created with the help of 7805/7905 complimentary pair ICs

2. .......The R1/R2 should be referenced to ground and not to (-) of the supply

3. Is is possible to use the above using +12 & -12 supply ?

4. will do but the output will be 12V then,

a 7805 may be used after the bridge for obtaining the required 5V

5. Thanks for the above clarification. Another query was that you mentioned "The outputs of the two opamps may then be connected to the input of a bridge rectifier". What is the use of the bridge rectifier, as the outputs would be DC if i am not wrong. Kindly help.

6. the bridge will enable you to get a +12V regardless of the input polarity condition, whether it's negative or positive, in other words it will convert the toggling +/- outputs of the opamps to always a (+) voltage

10. hi..
If I am having a certain power on one hand and we have to compare it with a variable power. Is there is a possible way.

1. you can try the concept explained in the above article.

11. Hi, i am Amarnath i want know that how op amp is working on single polarity supply instead of using dual polarity supply making +ve and -ve of dual polarity supply connected to ground

1. Amarnath, the circuit is actually working with a dual supply...the potential at pin#2 is divided by 50% of the supply to create the required +/- supplies, with reference to the power supply (-) which now acts like the ground.