The problem: chatter
A comparator compares two voltages and switches its output depending on which is higher. That's how you'd turn a temperature sensor's voltage into "too hot", or a slowly changing signal into a clean digital edge. The trouble is noise. As a slow input approaches the threshold, every little wobble takes it across and back, and the output flips several times instead of once. A microcontroller counting edges would see several pulses, and a heater controlled this way would click its relay on and off.
The cure: hysteresis
A Schmitt trigger uses two thresholds instead of one. Once the input rises past the upper threshold and the output switches, the threshold drops to a lower value. The input now has to fall all the way below that before the output switches back. Noise smaller than the gap between the thresholds, the hysteresis, can't cause a false switch. Your central heating thermostat works the same way: it switches on below one temperature and off above a slightly higher one.
How the circuit does it
In this inverting Schmitt trigger, the signal goes to the comparator's inverting (−) input. The other input gets its threshold from a divider: R1 from a reference voltage, and R2 from the output. That's positive feedback. When the output is high (5 V), it pulls the threshold up a little. When it's low (0 V), it pulls it down. With a single 5 V supply and a rail-to-rail output:
upper = (Vref × R2 + 5 × R1) ÷ (R1 + R2) lower = Vref × R2 ÷ (R1 + R2) hysteresis = 5 × R1 ÷ (R1 + R2)
A small R1 compared with R2 gives a small hysteresis. The thresholds sit roughly either side of Vref, slightly below it because of the divider. Choose the hysteresis comfortably bigger than the peak-to-peak noise, but small enough that the real signal still crosses both thresholds.
Where you meet Schmitt triggers
- Logic chips such as the 74HC14, used to clean up slow or noisy edges.
- Most microcontroller input pins have a little built-in hysteresis.
- Thermostats, battery low-voltage cut-offs and twilight switches, often in software as two thresholds.
- Relaxation oscillators: a Schmitt trigger with an RC network makes a simple square wave generator, the same principle as the 555 timer.
How this simulation works
The comparator is ideal: it switches instantly at the exact threshold, and its output swings fully between 0 V and 5 V. The input is a slow 3 V peak-to-peak sine wave centred on 2.5 V, plus pseudo-random noise up to the level you set, recalculated the same way each time so the result is repeatable. Real comparators have a small offset, a propagation delay, and an output that may need a pull-up resistor (open-collector types). The datasheet shows how the formulas change for those.