• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

  • +1000 Circuits
  • Hobby Circuits
  • Basic Circuits
  • Learn Arduino
  • Logic IC Pinouts
  • Disclaimer
You are here: Home / Electronics Tutorial / How to Use an Op amp as a Comparator Circuit

How to Use an Op amp as a Comparator Circuit

Last Updated on March 1, 2021 by Swagatam 34 Comments

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.

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

SHARING IS CARING!



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

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

You'll also like:

  • 1.  Simple Circuits using IC 7400 NAND Gates
  • 2.  How to Make Adjustable Current Limiter Circuits
  • 3.  Buck Boost Circuit Using IC 555
  • 4.  How to Repair Mosquito Swatter Bats
  • 5.  P-Channel MOSFET in H-Bridge Applications
  • 6.  USB Isolator Diagram and Working

Please Subscribe (Only if you are Genuinely Interested in our Newsletters)


 

Reader Interactions

Comments

    Your Comments are too Valuable! But please see that they are related to the above article, and are not off-topic! Cancel reply

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

  1. Search Related Posts for Commenting

  2. Seun says

    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

      Hi Seun,

      You can try the following concept:

      twin battery difference tester circuit

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

      Reply
      • Seun says

        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

          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
      • Seun says

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

        Reply
        • Swagatam says

          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.

          op amp preset control for battery difference detection

          Reply
          • Seun says

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

            Reply
            • Swagatam says

              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.

  3. Pekka Ritamaki says

    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

      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
  4. Klaas says

    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
    • Swagatam says

      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
    • Klaas says

      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

        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
  5. David Culver says

    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

      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
  6. tinuke says

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

    Reply
    • Swag says

      for what? what are you trying to accomplish?

      Reply
      • tinuke says

        To calculate the appropriate resistor for battery monitor using lm324

        Reply
        • Swag says

          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
  7. Badrikedar jadhav says

    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

      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
  8. Umang Agarwal says

    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

      you can try the concept explained in the above article.

      Reply
  9. Janesh Joshi says

    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.

    Reply
    • Swagatam says

      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

      Reply
    • Swagatam says

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

      Reply
    • Janesh Joshi says

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

      Reply
    • Swagatam says

      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

      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

      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
  10. Sravya Sekhar says

    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?

    Reply
    • Swagatam says

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

      https://homemade-circuits.com/2012/01/how-to-make-light-activated-day-night.html

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

      Reply
  11. Swagatam says

    good evening…the image is not opening.

    Reply



Primary Sidebar

Electronic Projects Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (51)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (93)
  • 741 IC Circuits (18)
  • Amplifiers (49)
  • Arduino Engineering Projects (82)
  • Audio Projects (84)
  • Battery Chargers (76)
  • Car and Motorcycle (88)
  • Datasheets (45)
  • Decorative Lighting (Diwali, Christmas) (32)
  • DIY LED Projects (82)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (99)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Games (2)
  • GSM Projects (9)
  • Health Related (17)
  • Heater Controllers (24)
  • Home Electrical Circuits (98)
  • Incubator Related (6)
  • Industrial Electronics (27)
  • Infrared (IR) (39)
  • Inverter Circuits (94)
  • Laser Projects (10)
  • LM317/LM338 (21)
  • LM3915 IC (24)
  • Meters and Testers (55)
  • Mini Projects (153)
  • Motor Controller (65)
  • MPPT (7)
  • Oscillator Circuits (15)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (65)
  • Radio Circuits (9)
  • Remote Control (46)
  • Security and Alarm (56)
  • Sensors and Detectors (116)
  • SG3525 IC (5)
  • Simple Circuits (72)
  • SMPS (29)
  • Solar Controllers (60)
  • Timer and Delay Relay (51)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (39)
  • Ultrasonic Projects (12)
  • Water Level Controller (46)

Follow Homemade Circuits

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora

Feeds

Post RSS
Comment RSS

Circuit Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Privacy Policy
  • About Us
  • Contact
  • Disclaimer
  • Videos – Circuit Test Results

© 2021 · Swagatam Innovations