Component guide · Intermediate · 3 min read
Comparators
LM393 and LM339 Explained
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
A comparator compares two voltages and switches its output depending on which is higher. The LM393 has two comparators and the LM339 four; both run from a single 2 to 36 V supply and have open-collector outputs that need a pull-up resistor. They are the chip on most sensor modules with a sensitivity trimmer. Add hysteresis with a feedback resistor so the output switches cleanly instead of chattering.
Key specs at a glance
- LM393
- Dual comparator, DIP-8 or SOIC-8
- LM339
- Quad comparator, DIP-14 or SOIC-14
- Supply
- 2 to 36 V single supply (or ±1 to ±18 V)
- Output
- Open collector: pulls LOW, needs a pull-up (e.g. 10 kΩ)
- Input range
- Includes ground, up to about VCC − 1.5 V
- Response time
- About 1.3 µs (LM393)
How it works
If the voltage at the non-inverting input (+) is higher than at the inverting input (−), the output transistor turns off and the pull-up pulls the output HIGH. If (−) is higher, the output transistor turns on and pulls it LOW.
A typical sensor module puts the sensor (such as an LDR in a divider) on one input and a trimmer potentiometer on the other. Turning the trimmer moves the switching point. Because the output is open collector, you can pull it up to 3.3 V even when the chip runs at 5 V, which conveniently matches an ESP32.
Adding hysteresis
When the input changes slowly or is noisy, a plain comparator flickers on and off around the threshold. Positive feedback fixes this: connect a large resistor (for example 1 MΩ) from the output to the + input, with a smaller resistor (10 kΩ) from the reference to the + input. Now the switching point moves slightly after each change, giving a gap between on and off thresholds of roughly VCC × 10k ÷ 1M, about 50 mV at 5 V. Increase the gap with a smaller feedback resistor.
A window comparator uses two comparators with outputs tied together to signal when a voltage is outside a range, for example a battery too low or too high.
Comparator or op-amp?
An op-amp can act as a comparator, but it is designed for linear feedback circuits: it is slower when its output saturates, and its output may not reach the rails. A comparator is designed to switch: faster, with a logic-friendly open-collector output. Use a comparator for thresholds and an op-amp for amplifying. Tie unused comparator inputs to ground so they do not oscillate.
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Forgetting the pull-up on the open-collector output.
- No hysteresis on a slow or noisy input.
- Feeding an input above VCC − 1.5 V and getting wrong results.
- Leaving unused comparators with floating inputs.
- Using an op-amp where a fast clean switch is needed.
Frequently asked questions
Why does my LM393 output never go HIGH?
It needs a pull-up resistor; the output can only pull LOW.
What is the difference between LM393 and LM339?
The LM393 has two comparators in an 8-pin package; the LM339 has four in a 14-pin package.
Can an LM393 work with 3.3 V boards?
Yes. Run it from 3.3 or 5 V and pull the output up to 3.3 V.
Why does my comparator output flicker?
The input is close to the threshold and noisy. Add hysteresis with positive feedback.
Can I use an op-amp instead of a comparator?
Sometimes, for slow signals, but comparators switch faster and give cleaner logic outputs.
Parts for this guide
Calculators
Terms in this guide
Keep learning
Sources
- Texas Instruments LM393 and LM339 datasheets
- Texas Instruments comparator with hysteresis reference design
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



