Comparators are devices that compare two voltages or currents and outputs a digital signal indicating which is larger. It has two analog input terminals and one binary digital output. The output value of the comparator indicates which of the inputs is greater or lesser. A comparator compares the two inputs applied to it and produces the comparison as the output.

Uses

These devices are often used to check whether an input has reached a predetermined value. In most cases, a comparator is implemented using a dedicated comparator IC, but op-amps may be used as an alternative.

Comparator diagrams and op-amp diagrams use the same symbols. They consist of specialized high-gain differential amplifiers. They are commonly used in devices that measure and digitize analog signals, such as successive-approximation ADCs and relaxation oscillators. Comparators are used to sense when an arbitrary varying input signal reaches the reference level or a defined threshold level. Such devices can be designed using various components like diodes, transistors, and op-amps. They can be found in many electronic devices to drive logic circuits.

Determining when temperature rises above a certain threshold is important for many applications. A comparator can be used with a thermistor to detect when a certain temperature rises above a threshold. 

Looking closely at the symbol of comparators, you will recognize it as the Operational Amplifier (Op-Amp) symbol. However, the two cannot be deemed the same. An op-amp operates on the analog input. It can amplify or attenuate this input and carry out mathematical operations such as addition, subtraction, integration, and differentiation.

Because of their wide range of uses, op-amps are encountered in most electric circuits. An op-amp is designed to accept the analog signals and yield the analog signal, whereas a comparator will only give output as a digital signal. Although an ordinary op-amp could be used as comparators, these cannot be used directly in voltage comparator circuits. Op-amps and comparators may seem interchangeable based on their symbols and pinouts, but they are not the same.

Inverting Comparator

An inverting comparator is an op-amp-based comparator in which the reference voltage is applied to its non-inverting terminal, and the input voltage is applied to its inverting terminal. This comparator is called an inverting comparator because the input voltage, which has to be compared, is applied to the inverting terminal of the op-amp.

The operation of an inverting comparator is straightforward. It produces one of the two values and  at the output based on the values of its input voltage and the reference voltage .  The circuit diagram of an inverting comparator is shown in the following figure.

Non-Inverting Comparator

A non-inverting comparator is an op-amp-based comparator in which the reference voltage is applied to its inverting terminal. The input voltage, on the other hand, is applied to its non-inverting terminal. This op-amp-based comparator is called a non-inverting comparator because the input voltage that has to be compared is applied to the non-inverting terminal of the op-amp. The circuit diagram of a non-inverting comparator is shown in the following figure.

LM324 (IC)

The LM324 operational amplifier IC can work as a comparator. This IC has four independent operational amplifiers on a single chip. This is a low-power quad operational amplifier and has high stability and bandwidth designed to operate on a single power supply over a wide range of voltages. The quad amplifier can operate at supply voltages as low as 3.0 V or as high as 3.2 V with quiescent currents about one-fifth of those associated with the MC174. The common-mode input range includes the negative supply, eliminating the necessity for external biasing components in many applications. The output voltage range also includes the negative power supply voltage. The LM324 comparator circuit consists of sensor voltage, reference voltage, Vcc, ground, and output pins.

A single power source can operate an LM324 but it can also use two power supplies. The terminals or the pins used are pins 4 and 11. The power supplies will make all four op-amps operational.

For the first op-amp, the inverting input is applied at pin 2 and the non-inverting at pin 3. The output of the first op-amp is obtained at pin 1.

For the second op-amp, the inverting input is applied at pin 6, and the non-inverting at pin 5. The output of the second op-amp is obtained at pin 7.

For the third op-amp, the inverting input is applied at pin 9 and the non-inverting at pin 10. The output of the third op-amp is obtained at pin 8.

Lastly, for the fourth op-amp, the inverting input is applied at pin 13 and the non-inverting at pin 12. The output of the fourth op-amp is obtained at pin 14.

Sample Schematic using a Comparator (DARK Detector)