MyRoboPath
electronics15 min readUpdated 2026-03-14Intermediate

Op-Amp as a Comparator: Threshold Detection & Hysteresis

Make analog decisions: master Operational Amplifiers (Op-Amps) and dedicated comparators (LM393, LM358), threshold voltage references, open-collector outputs, and Schmitt trigger hysteresis.

MyRoboPath Engineering Lab
Peer-Reviewed Open-Source Hardware & Firmware Guide

Key Engineering Takeaways

  • A Voltage Comparator compares two input voltages (V_+ and V_-) and outputs a digital HIGH or LOW based on which is larger.
  • If Non-Inverting input (V_+) > Inverting input (V_-), Output saturates to positive power rail (HIGH).
  • If Non-Inverting input (V_+) < Inverting input (V_-), Output drops to ground / negative rail (LOW).
  • Noisy analog signals near the switching threshold cause rapid jitter/chatter; solved by adding Positive Feedback Hysteresis.
  • Dedicated comparators like the LM393 feature Open-Collector outputs requiring an external pull-up resistor, allowing safe level shifting between 3.3V and 12V systems.
Prerequisites
  • Voltage Dividers and Analog sensor basics
Required Hardware / Tools
  • LM393 Dual Comparator or LM358 Op-Amp
  • 10kΩ Potentiometer (Threshold)
  • LDR Photoresistor
  • 10kΩ Resistors
  • LED and Breadboard

What is a Voltage Comparator? The 1-Bit Decision Maker

A **Voltage Comparator** is an electronic circuit that answers a single binary question: > **"Is Voltage A greater than Voltage B?"** It has two analog inputs: 1. **Non-Inverting Input (V_+ / Pin +)** 2. **Inverting Input (V_- / Pin -)** 3. **Single Output (V_out)** Because an open-loop Op-Amp has near-infinite gain (A_OL > 100{,}000), even a tiny microvolt difference between inputs forces the output to snap immediately to either the positive power rail (V_CC) or ground (0V).
Voltage comparator schematic symbol
Figure 5.1: Voltage comparator schematic symbol showing Non-Inverting (+), Inverting (-), and Output.Visual Guide

Op-Amp Open-Loop Working: Inverting vs Non-Inverting Inputs

### The Golden Comparator Rules: **Formula:** V_+ > V_- → V_out = HIGH (+V_CC) **Formula:** V_+ < V_- → V_out = LOW (0 V / -V_EE) ### Building an Autonomous Line-Follower Light Trigger: - Connect a **Reference Voltage (V_ref = 2.5V)** from a trimpot to V_-. - Connect a **Line-Tracking Photodiode sensor voltage** to V_+. - When the robot moves over white tape (V_sensor = 3.8V > 2.5V), output instantly snaps HIGH to turn on steering motors!
Op amp comparator threshold detector circuit
Figure 5.2: Op-Amp threshold detector circuit with adjustable reference potentiometer.Visual Guide

Adding Positive Feedback Hysteresis (Schmitt Trigger)

When a slow-moving analog sensor voltage hovers right at the threshold (2.500V), electrical noise causes the comparator output to **oscillate wildly (chatter)** between HIGH and LOW dozens of times per second. ### The Solution: Positive Feedback Hysteresis By adding a feedback resistor (100 kΩ) from Output back to the Non-Inverting (V_+) pin, we create two separate switching thresholds: - **Upper Threshold (V_TH = 2.6V)**: Input must exceed 2.6V to turn ON. - **Lower Threshold (V_TL = 2.4V)**: Input must drop below 2.4V to turn OFF. This 200mV deadband (hysteresis) guarantees crisp, chatter-free switching!
Schmitt trigger comparator hysteresis curve
Figure 5.3: Comparator hysteresis transfer curve showing upper and lower switching thresholds.Visual Guide

Frequently Asked Questions

Why do dedicated comparators like the LM393 have open-collector outputs?

An open-collector output uses an internal NPN transistor whose collector is left floating. This allows you to pull the output up to any voltage (e.g., 3.3V for an ESP32 or 12V for a relay), regardless of the comparator’s own supply voltage.

Tags:#Op-Amp#Comparator#LM393#LM358#Hysteresis#Schmitt Trigger#Analog Electronics