A basic comparator circuit diagram pits an input voltage ($V_{IN}$) against a reference voltage ($V_{REF}$), driving the output to the positive or negative supply rail based on which is higher. However, for any real-world signal with noise, an open-loop comparator will oscillate violently at the threshold. The definitive solution is the non-inverting comparator with hysteresis (Schmitt trigger). Using an LM393 dual comparator IC, a 4.7 kΩ pull-up resistor, and a 100 kΩ positive feedback resistor, you can create a clean digital transition with a built-in deadband that ignores millivolt-level noise.
In this guide, we will build a 5V logic-level threshold detector, calculate the exact resistor values for a 0.5V hysteresis window, and walk through the physical breadboard verification.
The Non-Inverting Hysteresis Topology (Node Labels & Behavior)
The topology relies on positive feedback to shift the reference threshold dynamically based on the current output state. We are using the TI LM393, a dual open-collector comparator that operates from 2V to 36V.
- $V_{CC}$ (Pin 8): 5.0V DC Supply
- GND (Pin 4): System Ground
- $V_{IN}$ (Pin 3 / IN+): Analog signal input via $R_{IN}$
- $V_{REF}$ (Pin 2 / IN-): Fixed reference voltage from a resistor divider
- $V_{OUT}$ (Pin 1): Open-collector output (requires $R_{PULL}$ to $V_{CC}$)
- $R_F$: Feedback resistor from $V_{OUT}$ to IN+
Because of the positive feedback through $R_F$, the circuit has two distinct trip points. The behavior table below maps the exact state transitions:
| Condition | $V_{IN}$ State | Output State (Pin 1) | Active Threshold at IN+ |
|---|---|---|---|
| Rising Input | $V_{IN} < V_{TH\_HIGH}$ | LOW (GND via internal FET) | N/A |
| Crossing High | $V_{IN} > V_{TH\_HIGH}$ | HIGH (Pulled to $V_{CC}$) | $V_{TH\_HIGH}$ |
| Falling Input | $V_{IN} > V_{TH\_LOW}$ | HIGH (Pulled to $V_{CC}$) | N/A |
| Crossing Low | $V_{IN} < V_{TH\_LOW}$ | LOW (GND via internal FET) | $V_{TH\_LOW}$ |
Design Walkthrough: Sizing Components for a 5V System
Let’s design a circuit that triggers a microcontroller interrupt when a sensor voltage crosses 2.5V, but we want a 0.5V hysteresis band to prevent false triggers from EMI. This means $V_{TH\_HIGH} = 2.75V$ and $V_{TH\_LOW} = 2.25V$.
Step 1: Set the Reference Voltage ($V_{REF}$)
We need 2.5V at the inverting input (Pin 2). Using a standard voltage divider from the 5V rail:
$R_1 = 10\text{ k}\Omega$ (connected to 5V)
$R_2 = 10\text{ k}\Omega$ (connected to GND)
$V_{REF} = 5V \times \frac{10k}{10k + 10k} = 2.5V$. Add a 100 nF ceramic capacitor across $R_2$ to filter high-frequency noise on the reference node.
Step 2: Calculate the Input and Feedback Resistors
The voltage at the non-inverting input (IN+) is determined by the superposition of $V_{IN}$ and $V_{OUT}$.
When the output is LOW (0V), the threshold is determined by $V_{IN}$ crossing 2.5V. To set $V_{TH\_HIGH} = 2.75V$, we use the voltage divider formula:
$V_{REF} = V_{TH\_HIGH} \times \frac{R_F}{R_{IN} + R_F}$
$2.5 = 2.75 \times \frac{R_F}{R_{IN} + R_F}$
If we choose $R_{IN} = 10\text{ k}\Omega$, solving for $R_F$ yields:
$R_F = 100\text{ k}\Omega$.
Step 3: Verify the Lower Threshold
When the output is HIGH (5V), $V_{OUT}$ pulls up on IN+. The input voltage must drop low enough to drag IN+ down to 2.5V.
$V_{TH\_LOW} = V_{REF} - (V_{CC} - V_{REF}) \times \frac{R_{IN}}{R_F}$
$V_{TH\_LOW} = 2.5 - (5 - 2.5) \times \frac{10k}{100k} = 2.5 - 0.25 = 2.25V$.
The math holds perfectly. The hysteresis band is exactly 0.5V.
Step 4: The Pull-Up Resistor
The LM393 has an open-collector output. It can sink current to ground, but it cannot source current to $V_{CC}$. You must include a pull-up resistor. A 4.7 kΩ resistor from Pin 1 to 5V provides a solid logic HIGH while limiting sink current to ~1 mA when the output pulls LOW.
Why Hysteresis Beats the Open-Loop Alternative
If you omit $R_F$ and tie IN+ directly to $V_{IN}$, you have an open-loop comparator. Here is why that fails in practice, as detailed in All About Circuits' guide on Schmitt triggers:
| Criterion | Open-Loop Comparator | Hysteresis (Schmitt Trigger) |
|---|---|---|
| Noise Immunity | None. 1 mV of noise causes output chatter. | High. Noise must exceed the 500 mV deadband. |
| Output Waveform | High-frequency oscillation at the threshold. | Clean, single digital edge. |
| Downstream Impact | Can burn out relay coils or overload MCU interrupt flags. | Safe for direct MCU GPIO or relay driving. |
| Component Count | Lower (no feedback resistor). | Higher (adds $R_F$ and $R_{IN}$). |
Failure Modes: What Breaks at the Extremes?
Understanding failure modes is critical when debugging a misbehaving PCB or breadboard. Here is what happens when specific elements fail open or short:
- $R_F$ (100 kΩ) Fails Open: Positive feedback is broken. The hysteresis band collapses to 0V. The circuit reverts to an open-loop comparator, and output chatter will immediately return if the input signal is noisy.
- $R_F$ (100 kΩ) Fails Short: IN+ is tied directly to the output pin. The circuit enters positive feedback runaway. The output will latch permanently HIGH or LOW depending on the exact microvolt offset at power-on, completely ignoring $V_{IN}$.
- $R_{PULL}$ (4.7 kΩ) Fails Open: The LM393 can still pull the output to ground (Logic LOW), but when the internal transistor turns off, the output pin floats. A microcontroller reading this pin will see random noise instead of a Logic HIGH.
- Input Common-Mode Violation: The LM393 datasheet specifies that the input voltage cannot exceed $V_{CC} - 1.5V$. On a 5V supply, if $V_{IN}$ exceeds 3.5V, the internal PNP input stage undergoes phase reversal or shuts off, causing the output to behave unpredictably even if $V_{IN}$ is technically higher than $V_{REF}$.
Step-by-Step Breadboard Testing Procedure
Do not trust your math until you verify it on the bench. Follow this sequence to validate the 2.25V / 2.75V thresholds.
- Seat the IC: Place the LM393 across the breadboard center trench. Connect Pin 8 to the 5V rail and Pin 4 to the GND rail.
- Wire the Reference: Insert two 10 kΩ resistors in series from 5V to GND. Connect the midpoint to Pin 2 (IN-). Measure Pin 2 with your multimeter; it must read 2.50V ± 0.05V.
- Wire the Output: Connect a 4.7 kΩ resistor from Pin 1 (OUT) to the 5V rail.
- Wire the Input Network: Connect a 10 kΩ resistor from your signal source (a 10 kΩ trimpot wiper) to Pin 3 (IN+). Connect the 100 kΩ feedback resistor ($R_F$) from Pin 1 to Pin 3.
- Initial State Check: Turn the trimpot fully toward GND ($V_{IN} = 0V$). Measure Pin 1. It should read ~0.1V (the LM393 saturation voltage). If it reads 5V, your feedback resistor is missing or the IC is damaged.
- Sweep High: Slowly turn the trimpot to increase $V_{IN}$. Watch your multimeter on Pin 1. Note the exact $V_{IN}$ voltage where Pin 1 snaps from 0.1V to 5.0V. It should be ~2.75V.
- Sweep Low: Slowly decrease $V_{IN}$. Note the voltage where Pin 1 drops back to 0.1V. It should be ~2.25V. The difference between your two measurements is your verified hysteresis band.
Frequently Asked Questions
How do I modify a comparator circuit diagram for 12V automotive signals?
The LM393 can handle up to 36V on its VCC pin, but automotive 12V systems experience load-dump spikes up to 40V. To adapt this diagram for a car: power the LM393 from a regulated 5V or 12V LDO. More importantly, scale your $R_1$ and $R_2$ divider to handle the 14.4V nominal alternator voltage, and place a 5.1V Zener diode (cathode to signal, anode to GND) on the IN+ pin to clamp transient spikes that exceed the IC's common-mode input limits.
Why does my LM393 comparator circuit diagram output stay low?
If Pin 1 measures near 0V regardless of the input voltage, the most common culprit is a missing or blown pull-up resistor. Because the LM393 features an open-collector output stage, it only contains an NPN transistor that pulls the pin to ground. It has no internal mechanism to pull the pin high to VCC. If you forget the 4.7 kΩ pull-up resistor, the output will simply float or read low depending on your multimeter's internal impedance.
Can I use an op-amp like the LM358 instead of a dedicated comparator IC?
You can, but it is not recommended for precision thresholding. While an LM358 can be wired identically, op-amps are designed to operate in closed-loop linear regions, not to saturate rapidly. The LM358 suffers from a slow slew rate (~0.3 V/µs), meaning its output edge will take microseconds to transition, which can cause logic errors in high-speed microcontrollers. Furthermore, many older op-amps exhibit "phase reversal" if the input voltage exceeds the common-mode range, causing the output to flip to the wrong rail unexpectedly. Always use a dedicated comparator like the LM393, TLV3201, or MAX902 for digital edge generation.






