• 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 / Mini Projects / Comparator Circuits using IC 741, IC 311, IC 339

Comparator Circuits using IC 741, IC 311, IC 339

Last Updated on January 31, 2020 by Swagatam 17 Comments

The basic function of a comparator circuit to compare two voltage levels at its input pins and produce an output to show which input voltage has higher potential than the other.

Table of Contents
  • Difference Between a Comparator and Op Amp
  • Using IC 741 as a Comparator
  • Using Specialized Comparator IC Units
  • Comparator Circuit using IC 311
  • How to Connect a Relay with a Comparator
  • Comparator Circuit using IC 339
  • Advantage of having a Floating Output in Comparator ICs

In this article we will elaborately learn how to correctly design comparator circuits using popular ICs like IC 741, IC 311 and IC LM339

Difference Between a Comparator and Op Amp

The IC 741 is an ideal example of a single op amp, and the IC LM311 can be considered a good example of a dedicated single comparator.

You will find both these units having an identical "triangle" shaped device symbol internally, which we normally recognize and use for drawing comparator circuits. However, the output response of these two forms of comparators may have a few major differences.

Although an op amp and a comparator both can be configured to compare differential signals at their input pins, the main differences between the two counterparts are:

  • In powered condition, the output of an op amp will be either positive or negative, depending on the input pin voltage levels, but can never be open. In contrast, a comparator output can be either open or grounded (negative), or floating.
  • An op amp output can work without any pull up or pull down resistors, but a comparator will always require an external pull-up or pull down resistor to enable the output stage to work normally.
  • An op amp can be used to build high gain amplifier circuits, a comparator cannot be used for such applications.
  • The output switching response of an op amp is usually slower compared to a comparator IC.

A classic comparator circuit design can be seen in the following figure:

warning message: electricity is dangerous, proceed with caution
comparator basic

Here, the output responds with a "high" digital signal, whenever the voltage at the non-inverting (+) input is higher than the inverting (-) input. Oppositely, the output into a turns low digital signal, whenever the noninverting input voltage is lower than the inverting input voltage.

comparator 1


Referring to the above figure above, we can see a standard connection of a comparator circuit having one input (the inverting input in this example) configured with a reference voltage, and the other input pin which is the noninverting input connected to an input signal voltage.

During the time Vin is held at lower voltage than the reference voltage of +2 V, the output stays low at around -10 V. If Vin is increased just above +2 V, the output instantly changes state, and turns high to around +10 V. This change of state at the output from -10 V to +10 V indicates that the Vin has become higher than the reference +2 V.

The main component inside any comparator is an op amp circuit, which set at a very high voltage gain. To study the working of a comparator accurately we can take the example of the IC 741, as shown below:

IC 741 output comparator waveform

Here we can see the inverting input pin2 (-) is referenced to ground, or a 0 V level. A sinusoidal signal is applied on pin3 which is the noninverting input of the op amp. This alternately varying sinusoidal signal causes the output to switch between high and low output states, as indicated on the right side of the image.

When the input Vin moves even a millivolt over the 0 V reference, the difference is amplified by the internal high gain op amp of the IC, causing the output to go high at the output positive saturation level. This condition is sustained for so long as Vin signal stays above the 0 V reference.

Now, as soon as the signal level drops a shade below the 0 V reference, the output is driven to its lower level of saturation. Again, this condition is maintained as long as the Vin input signal stays below the 0 V reference level.

The above explanation and the waveform presented in the image clearly indicates the digital response of the output for a linearly varying input signal.

For normal applications, the reference level doesn't have to be at 0 V, rather can be any positive level as per the requirement. And, in case required the reference can be also connected either to the positive or the negative supply lines, while the input signal is applied at the other input pin.

Using IC 741 as a Comparator

In the following example I have explained how to effectively use an op amp as a comparator

IC 741 comparator for operating an LED

In the figure we can see an op amp circuit working with a positive reference set at its inverting input pin (-). The output is attached with an LED.

Using the voltage divider network formula, we can calculate the refernce voltage value on the (-) input pin of the IC.

Vref = 10 k / 10 k + 10 k x +12 V = +6 V

Since this reference is associated with (-) pin of the IC, if the voltage Vin at the (+) input goes higher than this reference or becomes more positive than the reference, will force the output Vo to switch to its positive saturation level.

This will cause the LED to illuminate, indicating that Vin has become more positive than the reference level of +6 V.

Oppositely if the noninverting input (+) is configured as the reference pin and Vin applied to the inverting input (-) pin, the output will go low as soon as the Vin input goes below reference value, and vice versa.

This will instantly cause the LED to shut off.

Therefore, the LED can be made to switch ON or OFF for a given input signal, by appropriately wiring the inputs pin with the reference level and the input signal.

Using Specialized Comparator IC Units

Normally op amps work great as comparator circuits, but using a dedicated comparator IC works even better than an op amp for a comparator application.

Comparator ICs are specifically ideally designed for comparator function and show an improved response such as faster switching at the output between the positive and negative levels.

These ICs possess higher immunity to noise, and on many occasions the outputs can be directly used for driving a load.

I have explained about a couple of popular comparator ICs in detail, from the following discussion.

Comparator Circuit using IC 311

LM311 simplified schematic
IC 311 comparator pinout details

The figure above shows the internal layout and the pinout details of the comparator IC 311. The IC is designed to operate from a dual power supply also, in the range of +15 V and -15 V, which is a standard compatible level for all modern digital ICs.

The output stage inside the IC has a bipolar transistor, having floating collector and emitter terminals. This means that the output from this transistor can be configured can be configured in two different ways:

  1. By adding a pull-up resistor with the collector pin7 and grounding the emitter pin1, and subsequently using the collector as the output.
  2. By joining the collector with the positive line and using the emitter as the output.

The transistor output can be also used for driving a relay or a small load such as a lamp directly without any external buffer stage.

The IC also features a balance and a strobe input which can be gated with the output.

We'll discuss a few useful applications of this IC in the following sections:

LM311 internal layout with output connected with pull up resistor

The figure above shows how the IC 311 can be configured like a zero-crossing detector comparator to sense the input voltage, whenever it crosses the zero line.

The inverting input (-) of the 311 can be seen joined with the ground. During the period the input signal is at the positive level, the output transistor remains switched ON, which creates a low (-10 in this example) at the output (transistor collector).

As soon as the input signal goes negative or below 0 V, the transistor is turned OFF. This creates a positive +10V at the collector output of the IC. This allows us to know when the input signal is above the zero level and when it has dropped below the zero level.

The next figure below shows how IC 311 comparator can be used for making a strobed circuit.

In this comparator circuit example, the output pin7 will turn high when pin3 voltage level rises above pin2 reference. But this can happen only while pin6 strobe input pin is low or at 0 V.

LM311 as strobe comparator circuit

When a high TTL strobe is applied at the base of the transistor, pin6 becomes low, causing the IC output transistor to switch off, and thereby enabling pin7 to go high.

The output continues to be high as long as the TTL input is held high, regardless of the input signal condition at pin3.

However, if the TTL signal is applied in strobed form, then the output responds to the input signal at pin3. Put simply, the output remains locked at high, unless pin6 is strobed.

How to Connect a Relay with a Comparator

The next figure below shows how comparator 311 can be used directly to operate a relay.

LM311 as relay control comparator

Here, when the voltage level at input pin2 drops below 0 V, pin3 gets more positive than pin2. This causes the collector of the internal transistor to switch OFF, which switches ON the relay. The contacts of the relay could be wired with a heavier load for executing a desired switching action.

As long as the (+) input at pin2 stays below 0 V, the relay remains switched ON. Conversely, when a positive signal is available on pin2, the relay will remain switched OFF.

Comparator Circuit using IC 339

The IC 339, also popularly written as LM339, is a quad comparator IC. Meaning, it includes 4 separate voltage comparators whose inputs and outputs are appropriately terminated via the respective external pins of the IC package, as shown below.

LM339 pinout drawing

Just like any other comparator, each comparator block has a couple of inputs, and one output. When the IC is powered by applying voltage across the Vcc, and ground supply pins, it powers all the comparators together. So even if a single comparator is used, all the other 3 would be consuming some power.

All the comparator have exactly identical characteristics, therefore we can analyze any one of these to learn the basic comparator function.

LM339 comparator pin configuration

When a positive differential input is applied across the input terminals, meaning when the difference between the applied signals is positive, it turns the output transistor OFF. This causes the output to show an open circuit, or a floating open.

When the differential input is negative, meaning when the difference between the applied signals at the input pins is negative, it turns ON the output transistor of the comparator, which causes the output pin of the comparator to turn negative, or at V- potential.

Referring to the figure above, we can understand that when the non-inverting (+) input of the IC is used as the reference pin, a voltage lower than this reference at the inverting input pin (-) will result in the output of the comparator to become open. On the other hand, if the (-) is used as the reference pin, a voltage level at the (+) input higher than the reference will cause the output to turn negative or at V-

In order to learn how the IC 339 works like a comparator, the following example shows the IC as a zero crossing detector.

LM339 comparator switching waveform

The moment the input signal rises above 0 V, the output is turned high at V+ level. The output is turned OFF at V- only while the input is held below 0 V.

As explained previously, the reference level does not need to be 0 V, it can be changed to any other desired level. Additionally, you can also use the other input pin (+) as the reference pin, and the (-) input pin as the signal input pin for accepting the varying input signal.

Advantage of having a Floating Output in Comparator ICs

As discussed in the previous explanations, comparators output is switched through BJT which have an open collector as the output. This gives the advantage of connecting the outputs of two comparators from the IC 339 directly just like an OR gate.

A nice example of a window comparator circuit can be seen below. Here two IC 339 comparators blocks are configured with a single common input signal, and the outputs are joined like OR gate.

LM339 as window comparator

The output of the respective comparators go low whenever the input signal crosses either the lower set threshold or the upper set threshold, thus enabling the user to know when the signal is out of the set window level.

A window comparator can be used for useful applications such as high low voltage protector circuit, and solar tracker circuit etc.

Conclusion

From the above explanations, I have explained that:

Comparators are basically units having two complementing inputs, and one responsive output. The output turns high or low when the voltage level on one of the inputs goes higher or lower than the other input, depending upon which input is used as the reference or at a fixed voltage level.

Although an op amp can be also used like a comparator, specialized comparator ICs are better designed to work like comparators.

Dedicated comparator ICs like LM311, LM339 are specially designed for comparator application, with faster response and a flexible high current output capability.

If you have any related questions, please feel free to ask them through the comment box below.

You'll also like:

  • 1.  10 Step Relay Selector Switch Circuit Diagram
  • 2.  How to Understand and Use IC 4093 NAND Gates, PinOuts
  • 3.  Simple FET Circuits and Projects
  • 4.  Diwali, Christmas 220V Lamp Chaser Circuit
  • 5.  LM10 Op Amp Application Circuits – Works with 1.1 V
  • 6.  12 Simple IC 4093 Circuits and Projects Explained

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « How Transformers Work
Next Post: Bidirectional Switch »

Reader Interactions

Comments

  1. Joe Gabriel says

    May 30, 2024 at 1:17 pm

    Sir… I want to build a circuit, where a decreasing signal is fed, only at one point it suddenly increases and after reaching a peak it decreases, using an op-amp i want to detect the positive slope that is occurring, and to light up an LED or a relay switch, when the voltage as reached its peak, and i have to display the value of the peak. Can you guide me in creating this circuit, if possible can share circuit diagram, component values, any form guidance will really be helpful

    Reply
    • Swagatam says

      May 30, 2024 at 4:53 pm

      Hi Joe, I think you can try the following idea:

      " rel="ugc">comment image

      Reply
      • Joe Gabriel says

        May 30, 2024 at 5:10 pm

        sir….any other circuit involving a differentiator and comparator which drives the relay switch

        Reply
        • Swagatam says

          May 30, 2024 at 5:33 pm

          If you connect a transistor relay driver stage at the output of the opamp, you can operate a relay at the collector side of the transistor.

          Reply
  2. jamal says

    January 16, 2023 at 1:00 pm

    I want to get the circuit which can be connected in series with the feeder (DC Load). it compare the input current and output current to load and if there is difference between input and output current it glow the led which means the circuit has another path of current.

    Reply
    • Swagatam says

      January 16, 2023 at 5:04 pm

      You can modify the following comparator circuit to suit your needs:

      " rel="ugc">comment image

      Reply
  3. Carlos says

    April 14, 2022 at 3:40 am

    Hello sir Swagatam good afternoon, my name is Carlos and I am interested in a circuit. I need a circuit what active a relay with mv.. For example 45 to 100mv and with lm358 can you do it? . Thanks a lot.

    Reply
    • Swagatam says

      April 14, 2022 at 1:18 pm

      Hi Carlos, you just have use any op amp like 741, attach a 10K preset to its pin#2, and apply the mV signal to pin#3. Preset outer pins will connect with the DC supply lines, and the center pin of the preset will connect with the pin#2 of the IC. Next, apply 100mV positive signal to pin#3, adjust the preset until the output is triggered high.

      Reply
  4. Fredstev says

    December 9, 2021 at 4:06 pm

    Thank you for this article sir… It’s been very helpful… You are really amazing..

    Reply
    • Swagatam says

      December 9, 2021 at 7:28 pm

      Thank you Fredstev, glad you liked it!

      Reply
  5. Phi Dung says

    August 8, 2021 at 12:36 pm

    Great article, now I understand a lot more about the comparator IC

    Reply
    • Swagatam says

      August 8, 2021 at 7:42 pm

      Thank you for your feedback, glad it helped you to understand the subject!

      Reply
  6. Peter Sanford says

    December 7, 2020 at 10:59 am

    Thank you for that circuit! It is much simpler than I did myself (and will probably work better!) I assume the hysteresis occurs by the feedback from pin 6 to pin 3 through the diode. Is the “turn off” level set as a voltage divider between the 10K resister on the base of BC547 and the variable 10K tied to pin 3? Thanks again. I will write you when I get a circuit built and checked.

    Reply
    • Swagatam says

      December 7, 2020 at 3:25 pm

      You are welcome, yes the hysteresis level is controlled by the 10k feedback preset between pin6 and pin3 of the op amp, and this preset also sets the lower voltage turn ON threshold at which the op amp output reverts to the original situation.

      The turn OFF threshold is adjusted by the other 10k preset associated with the pin2 of the op amp

      Reply
  7. Peter Sanford says

    December 6, 2020 at 7:26 am

    I need a simple comparitor circuit to “latch” a fan on when the reference voltage rises above some set value. It is for a CO2 controller for an exhaust fan in a small church I belong to. The CO2 level signal is 0 to +5 V. but varies somewhat irregularly, maybe +-0.1volts, as the air flows over the sensor element. Once the CO2 level is once triggered it needs to keep the fan on until a lower voltage is sensed at which time it must turn the fan back off. Both upper and lower trigger levels need to be set by potentiometers. My circuit used a mechanical relay which changed the turn off trigger level once fired. My circuit worked OK , but not being an electronic engineer it failed after a short period. I’m not sure what failed. It oscillated, causing the exhaust fan to start and stop quickly. Are you interested in helping me?

    Reply
    • Swagatam says

      December 6, 2020 at 1:43 pm

      You can try the following concept, you may have to tweak a few of the parameters according to your specific implementation, and results:

      comment image" alt="op amp latch comparator with hysteresis" />

      Reply
  8. Agnelo Mascarenhas says

    July 11, 2019 at 1:39 am

    Op Amp need compensation under certain conditions – capacitive loads, near unity gain. A simple pole is often builtin which results in 90 degree phase margin and a sluggish large signal response.

    Reply

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




Subscribe to New Circuits

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (83)
  • Datasheets and Components (104)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (101)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)




  • 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
  • Quora
  • Stack Exchange
  • Linkedin



  • © 2025 · Swagatam Innovations