• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Electronics Theory / How to Use an Op amp as a Comparator Circuit

How to Use an Op amp as a Comparator Circuit

Last Updated on March 28, 2022 by Swagatam 56 Comments

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

What is an Op amp Comparator

We've been using an op amp 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.

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 op amp comparator design, basically two different voltage levels are used at the input pins for comparing them, as shown in the below diagram.

how to configure op amp input pins for voltage comparison
REMEMBER, THE VOLTAGE ON THE INPUT PINS SHOULD NOT EXCEED THE DC SUPPLY LEVEL OF THE OP AMP, IN THE ABOVE FIGURE IT SHOULDN'T EXCEED +12 V

The two input pins of an op amp are called the inverting (with a minus sign) and the non-inverting pin (with a plus sign) become the sensing inputs of the op amp.

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, as shown below.

how to add fixed reference to op amp

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.

Video Demo

How an Opamp Comparator Works

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:

We can see that the Pin #7 of the opamp 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.

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.

Interchanging the Sensing Parameter with Adjustment Parameter

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:

 Practical 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 voltage goes higher than the (+) voltage, the output quickly turns negative or switches OFF to 0V.

Basic Comparator Working

The circuit in the below figure operates in a relatively straightforward manner: The combination of R2 and Zener diode D1 produces a fixed reference voltage (VREF). It is applied straight to the op-non-inverting amp's input terminal, pin 3. Via the current limiting resistor R1, the input or test voltage VIN is connected to the inverting input terminal (pin 2). When VIN is less than VREF, the op amp output is high (to positive saturation), but when VIN is greater than VREF, the output is low (to negative saturation).

Op amp Comparator with High Voltage Input

As shown in the below figure, using a VOLTAGE DIVIDER, we can utilize a voltage comparator to provide high-value, variable voltage triggering. There is no regenerative switching in this circuit.

Op Amp Comparator with High Value Input, Regenerative Switching

The next circuit, like the previous one, provides high-value, variable-voltage input switching (0 to 150 V). It has regenerative switching capabilities.

Op Amp Comparator as Over Current Indicator

When the load current reaches a value defined by R6, the output turns high to indicate an over current situation. By inverting the connections to IC1's pins 2 and 3, the output will go low to indicate an over-current situation.

The diagram below demonstrates how a comparator circuit may be configured to operate as an over-current switch, producing a high output when the load current exceeds a given value - which you can set using potentiometer R6. Current sensing resistor RX is set such that it drops around 100 millivolts at the appropriate trip point. As a result, a fixed reference voltage equal to 1/2 the supply voltage is provided to pin 3 of the op amp through the voltage divider comprised of R3 and R4. Pin 2 receives a similar but current-dependent voltage through Rx, R1, R6, and R2.

In fact, the two sets of components form a Wheatstone bridge, with one side supplying pin 3 and the other supplying pin 2, and the op-amp serving as a bridge-balance detector. As a result, the circuit's trip points are unaffected by fluctuations in supply voltage but are very sensitive to changes in load current.

You'll also like:

  • LIFePO4 compressedLiFePO4 Battery Charging/Discharging Specifications, Advantages Explained
  • flex circuitHow Flex Resistors Work and how to Interface it with Arduino for Practical Implementation
  • cascadingIC4033circuitHow to Cascade IC 4033 in Multiple Digit Counter Display
  • use2BpotsHow a Connect a Potentiometer

Filed Under: Electronics Theory Tagged With: Comparator

About Swagatam

I am an electronics engineer and doing practical hands-on work from more than 15 years now. Building real circuits, testing them and also making PCB layouts by myself. I really love doing all these things like inventing something new, designing electronics and also helping other people like hobby guys who want to make their own cool circuits at home.

And that is the main reason why I started this website homemade-circuits.com, to share different types of circuit ideas..

If you are having any kind of doubt or question related to circuits then just write down your question in the comment box below, I am like always checking, so I guarantee I will reply you for sure!

Previous Post: « Homemade 2000 VA Power Inverter Circuit
Next Post: How to Make a Telephone Amplifier Circuit »

Reader Interactions

Comments

Neeraj says:
April 15, 2024 at 11:02 am

So here’s the all the issues I am facing right now
1. The voltage is floating in all the components in the circuit
2. Bc557 is not functioning as puch to on function
3. Getting 1.5~1.4 voltage at leds terminal but the led is not on
4. Getting 12v at pin7 and pin4 of the ic but ic is not responding
5. I have Checked twice the connection and all the connection is right

These are all the issues I am facing right now

Reply
Swagatam says:
April 15, 2024 at 2:26 pm

Please try the following setup.

Move the preset up/down, the LED should illuminate and shut-off alternately at a particular point on the preset.

https://www.homemade-circuits.com/wp-content/uploads/2024/04/op-amp-test-jig.jpg

Reply
Swagatam says:
April 15, 2024 at 2:37 pm

This will confirm whether your iC is good or bad.

Reply
Neeraj says:
April 15, 2024 at 3:33 pm

After turning fully upside the lower led which is connected to the 1k resistor was on and after turning fully downside the led which is connected to the pin6 was not on and also the second led was off ! I am giving 18v to the circuit and there is 13.2v at the second led (when it’s on) and 1v at first led !

Reply
Swagatam says:
April 15, 2024 at 4:43 pm

You must use 12v, not 18V, at 18V the 741 IC can burn.
Both LEDs are connected in series so both will turn ON/OFF together, not one by one.
Both the LEDs must turn ON and OFF at a “sharp” particular point of the preset rotation, not fully upwards or fully downwards.
Please change the IC and test again with 12V supply.

Reply
Neeraj says:
April 15, 2024 at 8:03 pm

Sir listen can you make this circuit with my requirements and ship it to me please because of it I can find out my mistake more accurately i will pay the shipping charges please ?

Reply
Swagatam says:
April 15, 2024 at 10:43 pm

Neeraj, Sorry, that may not be possible for me either.

Reply
Neeraj says:
April 15, 2024 at 8:01 pm

Same nothing changed now with the 12v and I got 7v at the second led and first led didn’t turned on now at the sharp point it get turned on but the issue is same as before one more thing the second led which was lighted up now it’s was dimm means the led was not on its full potential

Reply
Swagatam says:
April 15, 2024 at 10:42 pm

Neeraj, in that case I cannot understand your circuit problem because I cannot check what’s wrong with your connections or parts.

Reply
Neeraj says:
April 13, 2024 at 1:02 pm

So which circuit should I follow to check the ic ? 741!

Reply
Swagatam says:
April 13, 2024 at 1:36 pm

Please use the same circuit which I discussed in my previous comment.
Connect its pin2 to ground via 1k resistor, adjust the preset somewhere midway. Press the push button to latch the ic. Then manually connect pin2 with the positive rail momentarily, if the latch breaks, your ic is good. Repeat the procedure a few times to confirm the results.

Reply
Neeraj says:
April 13, 2024 at 3:00 pm

https://www.homemade-circuits.com/wp-content/uploads/2024/02/latch-circuit-using-741.jpg

So I will work on this circuit and for checking the ic I will connect pin 2 of the ic with positive rail and remove the 1k resistor between pin2 to ground just for momentarily okay?

Reply
Swagatam says:
April 13, 2024 at 8:43 pm

No, 1k will remain connected to ground as it is, in rhis position just touch pin2 with positive just for a second, and remove. This should break the latch.
Then press the button again to latch the circuit and again touch pin2 to positive to break the latch….
This will confirm 741 is good.

Reply
Neeraj says:
April 13, 2024 at 10:25 pm

Gotta I think I found the issue after touching the pin2 with the positive the circuit didn’t latch but led turned off and after removing the connection with the positive the again turned on is that means the 741is faulty!?

Reply
Swagatam says:
April 14, 2024 at 6:34 am

Circuit should latch and LED should illuminate when push button is pressed.

Latch should break and LED should shut off when pin2 is touched to positive.

Reply
Carlos says:
February 2, 2023 at 10:01 pm

Hello, I am interested in the current control circuit.. but I would like to know what the 10k resistor connected between the output and GND is for…
Thank you very much.

Reply
Swagatam says:
February 3, 2023 at 8:41 am

Hi, 10K is the output pull down resistor. But I think it is not required, it can be removed.

Reply
Seun says:
February 26, 2021 at 12:07 pm

Good day Swag, please a need a comparator circuit, that can sense differences between 2 batteries, and difference of 0.2v will trigger led light. Thanks

Reply
Swagatam says:
February 26, 2021 at 2:31 pm

Hi Seun,

You can try the following concept:

https://www.homemade-circuits.com/wp-content/uploads/2021/02/battery-differnce-tester.png

When B1 voltage is higher than B2 by 0.2 V, the LED will light up and vice versa…

Reply
Seun says:
May 27, 2025 at 10:45 pm

Hello sir, please I lost my folder, please can you kindly help Me repost the circuit in this comment?

Reply
Swagatam says:
May 28, 2025 at 8:25 am

Hello Seun, image upload facility is not currently available in the comments section….instead you can upload it to any online image hosting website and provide me the link here…I will check it out…

Reply
Seun says:
May 29, 2025 at 11:37 pm

please kindly help Me to redraw another op amp.

Reply
Swagatam says:
May 30, 2025 at 9:15 am

Seun, please refer to your previous comments above you will able to the see diagram using two batteries, as requested by you..

Reply
Seun says:
May 29, 2025 at 11:34 pm

Sir, I requested for it, and you helped to draw an op amp for the circuit.

Reply
Seun says:
March 1, 2021 at 7:52 pm

Thanks Sir Swag,please what can I adjust to make the differential 0.5v

Reply
Swagatam says:
March 2, 2021 at 7:56 am

Seun, you can modify the circuit with preset as shown in the following figure, and adjust it to get the 0.5 V differential output.

https://www.homemade-circuits.com/wp-content/uploads/2021/03/op-amp-battery.png

Reply
Seun says:
March 2, 2021 at 2:38 pm

Thanks Sir Swagatam, what is the value of preset and how will I set the differential value.

Reply
Swagatam says:
March 2, 2021 at 6:21 pm

You are welcome Seun, preset value can be 10k, connect a 12V source at (-) input, and connect another source 12.5 V at (+) input of the op amp….adjust the preset until the red LED just starts glowing.

Reply
Seun says:
February 27, 2021 at 1:14 am

Thanks Sir, what of vice versa if B2 is higher, can it work interchangeably with one circuit, to light up the LED

Reply
Swagatam says:
February 27, 2021 at 9:18 am

If B2 is higher then the red led will shut off. You can connect another LED across positive to op amp output with a 1k series resistor for indicating B2

Reply
Pekka Ritamaki says:
February 15, 2021 at 10:58 pm

You have very good opamp as comparator circuits, but you must warn not to use real comparators in your circuits.
The real comparators need most of time output resistors to VCC.

Now there are some comparator circuits, which need not output resistors.
The Microchip has done such comparators like MCP6541
It needs not output resistor.
It can gives 2mA output current to both sides.

Reply
Swagatam says:
February 16, 2021 at 10:03 am

Yes, for true comparator like LM393 or LM339, which have an open collector transistor set at the output pin, must have a pull up resistor, but the above article is about op amps, so that may not be required here….

Reply
Klaas says:
July 17, 2020 at 3:25 am

I build various of your circuits and all works 100% and was what i need, so thanks a lot. I want to build above to put between my solar batteries and an extra battery for charge purposes. My system is 12v , but the volts go up to 13,6. If I put the same value resistor on both 2 and 3 and power from the solar batteries and extra battery will this then work till voltage is equal.

Regards

Reply
Klaas says:
July 17, 2020 at 12:35 pm

Sorry English is my second(poor) language. I refer to the circuit with the adjustment parameter. So if I connect 7 and 2(with resistor) to the positive of the extra battery and the 3(with resistor) to solar pack. This must then open the relay till the voltage of both are equal. The negative will be of both batteries.

I am not a expert on electronics so I use basically your knowledge to build circuits.

Reply
Swagatam says:
July 17, 2020 at 7:49 pm

Yes that’s correct you can refer to the designs explained in the following article for a detailed info:

https://www.homemade-circuits.com/make-6v-4ah-automatic-battery-charger/

Reply
Swagatam says:
July 17, 2020 at 10:20 am

Glad my circuits are helping you accomplish your goals. however, i am unable to figure out which circuit are you referring to. Please specify the circuit schematic.

Reply
David Culver says:
May 6, 2019 at 10:21 am

Hi Swagatam,
I am interested in finding a circuit design for my solar tracker.

I’m using a small pv panel as my voltage source. It’s output is 11 to 15 volts dc.

The motor to rotate the tracker is a small 12v geared motor with 5 rpm output shaft. The motor shaft turns an all thread rod, which pulls the movable deck of the tracker around about a center pin.

I would like to use two LDR’s to sense when the tracker is properly aligned with the sun and shut the motor off at that point. As the sun moves the circuit will turn on the motor again so that the tracker will follow the sun.

The tracker will only move in one direction and I will reset it manually after about 2 hours of use. It’s for a solar cooker.

The motor only needs to turn one direction, and it needs a controller with the light sensing ability to shut off the motor when the light is equal on both LDR’s.

I am hoping you might know of a circuit design that would accomplish this task.
Thank you very much.
David

Reply
Swagatam says:
May 6, 2019 at 1:25 pm

Hi David, I think I already have this circuit in my website. Please check out the following article, and let me know if you have further doubts:

https://www.homemade-circuits.com/how-to-build-dual-solar-tracker-system/

Reply
tinuke says:
December 22, 2018 at 8:45 pm

What should be the minimum difference value for inv and non inv. Thanks.

Reply
Swagatam says:
December 22, 2018 at 9:00 pm

for what? what are you trying to accomplish?

Reply
tinuke says:
December 23, 2018 at 9:43 pm

To calculate the appropriate resistor for battery monitor using lm324

Reply
Swagatam says:
December 24, 2018 at 8:49 am

OK but that’s not the right way, because the cut-off difference can vary from opamp to opamp. Instead you can randomly select a fixed reference much lower than the supply voltage and then adjust the preset to create a cut off just above or under this reference voltage. Later this preset could be removed by replacing it with an appropriately matched fixed resistor.

Reply
Badrikedar jadhav says:
April 5, 2017 at 3:45 pm

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

Reply
Swagatam says:
April 6, 2017 at 4:58 am

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.

Reply
Umang Agarwal says:
October 16, 2015 at 11:12 am

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.

Reply
Swagatam says:
October 17, 2015 at 2:31 am

you can try the concept explained in the above article.

Reply
Swagatam says:
December 25, 2014 at 4:32 pm

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

Reply
Janesh Joshi says:
December 25, 2014 at 1:39 pm

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.

Reply
Swagatam says:
December 24, 2014 at 11:28 am

will do but the output will be 12V then,

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

Reply
Janesh Joshi says:
December 24, 2014 at 10:04 am

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

Reply
View Older Comments

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

circuit simulator image



Subscribe to get New Circuits in your Email



Categories

  • Arduino Projects (92)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (84)
  • Datasheets and Components (109)
  • Electronics Theory (148)
  • Free Energy (39)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (16)
  • Inverter Circuits (94)
  • Lamps and Lights (157)
  • Meters and Testers (71)
  • Mini Projects (28)
  • Motor Controller (66)
  • Oscillator Circuits (28)
  • Pets and Pests (15)
  • Power Supply Circuits (90)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (105)
  • SMPS and Converters (32)
  • Solar Controller Circuits (60)
  • Temperature Controllers (43)
  • Timer and Delay Relay (49)
  • Voltage Control and Protection (38)
  • Water Controller (36)
  • Wireless Circuits (30)





Other Links

  • Privacy Policy
  • Cookie Policy
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap



People also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Stack Exchange
  • Linkedin



Recent Comments

  • Swagatam on 3 Laser Beam Controlled Circuits Explored
  • ken on 8X Overunity from Joule Thief – Proven Design
  • Kim on 3 Laser Beam Controlled Circuits Explored
  • Swagatam on Making an Adjustable Electromagnet Circuit
  • Swagatam on Make this DC CDI Circuit for Motorcycles

© 2025 · Swagatam Innovations