A comparator is an analog circuit that monitors two input voltages. One voltage is called the reference voltage (Vref) and the other is called the input voltage (Vin). When Vin rises above or falls below Vref, the output of the comparator changes states. Some circuits (like the 339) are designed specifically as comparators. Due to its very high open-loop gain, and OP-AMP without a feedback resistor can function as a comparator.
When Vin exceeds Vref, output switches from low to high.
When Vin exceeds Vref, output switches from high to low.
Build this simple circuit on a plastic breadboard to learn the basics of the comparator. R1 and R2 function as voltage dividers that supply a range of voltages to both 741 inputs. Q1 switches current to the led when the output of the 741 goes high. The circuit works like this: ASSUME R2 IS SET TO ITS CENTER POSITION TO GIVE Vref = 4.5 VOLTS (9V/2 = 4.5V). R1 THEN CONTROLS Vin.