Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use a comparator—not an op-amp—when the job is to detect whether a sensor voltage is above or below a threshold and switch a relay. The reliable circuit is a comparator with hysteresis, an external NPN transistor or logic-level N-MOSFET, a pull-up resistor where required, and a flyback diode across a DC relay coil.
An op-amp can work in a slow, non-critical circuit, but it may saturate slowly, produce unsuitable logic levels, or behave unpredictably near its input and output limits. Neither an op-amp nor a comparator should normally drive a relay coil directly.
The basic relay-control circuit
A threshold-controlled relay normally uses this signal chain:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesSensor or analog input
│
▼
Comparator with hysteresis
│
▼
Pull-up and base/gate resistor
│
▼
NPN transistor or N-MOSFET
│
▼
Relay coil with flyback protection
The relay contacts are a separate circuit. They may switch a different voltage and load from the low-voltage comparator circuit, so the coil wiring and contact-side wiring must be treated independently.
#1 Best Overall
- 5V Relay Module: Working Voltage: DC 5V; Maximum Load: AC 250V/10A, DC 30V/10A; Trigger Current of Opto-Isolator: 5mA
- Fault-Tolerant Design: Fault Tolerant Design, Even if the Control Line is Broken, the Relay will not Operate;All Interfaces of Relay can be Wired Out Through the Terminals Directly,Normally Open and Normally Closed
- Optocoupler Isolation:1 Channel Relay Board use Optocoupler Isolation that has Strong Driving Ability and Stable Performance ,The Isolation Circuit Prevent Damages to I / O Port by Relay Switch Current
- Jumper Design: The Relay Module has a Jumper That You Can Set Rather the Unit State Changes with High or Low Signal. Has Screw Terminals for Relay (NC,C,NO) and for Input; Coil +, Coil - and Trigger.
- Wide Application: DC 5V Relay Module Works Well with ARM /PIC /AVR /MCU/Raspberry/CNC Machine/ PS4 etc.
Op-amp versus comparator
A comparator is designed to answer a binary question:
VIN+ > VIN− → one output state
VIN+ < VIN− → the other output state
An op-amp is designed to operate with negative feedback in a linear region. It can be wired open-loop and used as a comparator, but that is a compromise rather than an equivalent replacement.
| Requirement | Comparator | Op-amp |
|---|---|---|
| Threshold detection | Purpose-built | Possible, but not ideal |
| Output | May be open-collector, open-drain, push-pull, or logic-specific | Analog output; may not reach either supply rail |
| Saturation recovery | Generally specified for switching use | May recover slowly after saturation |
| Hysteresis | Often straightforward to add | Possible, but input/output limitations matter |
| Signal conditioning | Limited | Better for amplification, filtering, and buffering |
| Best use | Clean switching decisions | Linear analog processing |
Analog Devices explains why an ordinary op-amp should not automatically be treated as a comparator, particularly when saturation recovery and switching behavior matter: op-amp and comparator application guidance.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse an op-amp before a comparator when a sensor needs amplification or filtering. Use an op-amp alone only when the circuit is slow, tolerant of uncertain switching behavior, and an existing device makes a separate comparator unnecessary.
A complete low-side relay driver
The comparator output should control a transistor or MOSFET rather than the coil:
+Vrelay ───── Relay coil ───── collector/drain
│
NPN transistor or N-MOSFET
│
Ground
NPN transistor version
Comparator output ── resistor ── base
Emitter ──────────────────────── ground
Collector ───────────────────── relay coil
For a relay coil current of 100 mA, a conservative forced beta of 10 requires approximately 10 mA of base current. With a 5 V drive and an estimated 0.7 V base-emitter drop:
Rank #2
- 5V Relay Module: Working Voltage: DC 5V; Maximum Load: AC 250V/10A, DC 30V/10A; Trigger Current of Opto-Isolator: 5mA
- Fault-Tolerant Design: Fault Tolerant Design, Even if the Control Line is Broken, the Relay will not Operate;All Interfaces of Relay can be Wired Out Through the Terminals Directly,Normally Open and Normally Closed
- Optocoupler Isolation:1 Channel Relay Board use Optocoupler Isolation that has Strong Driving Ability and Stable Performance ,The Isolation Circuit Prevent Damages to I / O Port by Relay Switch Current
- Jumper Design: The Relay Module has a Jumper That You Can Set Rather the Unit State Changes with High or Low Signal. Has Screw Terminals for Relay (NC,C,NO) and for Input; Coil +, Coil - and Trigger.
- Wide Application: DC 5V Relay Module Works Well with ARM /PIC /AVR /MCU/Raspberry/CNC Machine/ PS4 etc.
RB = (5 V − 0.7 V) / 0.010 A ≈ 430 Ω
A 470 Ω resistor may be a reasonable starting point, but check the comparator’s output-current and sink-current limits. Do not rely on a transistor’s optimistic small-signal gain when sizing base drive.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →N-MOSFET version
Comparator output ── gate resistor ── gate
Source ───────────────────────────── ground
Drain ────────────────────────────── relay coil
A MOSFET is often preferable for higher coil currents because its steady-state gate current is very low and its voltage drop can be small. Select a device whose RDS(on) is specified at the actual gate voltage. “Logic-level” does not automatically mean fully enhanced at 3.3 V.
Add a gate-to-ground pull-down, commonly in the 10 kΩ–100 kΩ range, so the relay remains off while the comparator is powering up. A small gate resistor, often tens to a few hundred ohms, can reduce ringing and limit peak gate current.
LM393 wiring: remember the pull-up
The standard LM393 is a dual comparator with an open-collector output. It pulls the output low but does not actively drive it high. Connect an external pull-up resistor:
+Vlogic ── Rpullup ──┬── comparator output
│
└── driver input
A starting range of 1 kΩ–100 kΩ is common, but the correct value depends on switching speed, input capacitance, noise, supply voltage, and power consumption. A lower value produces a stronger, faster rising edge but draws more current when the output is low. A higher value saves power but creates a slower, more noise-sensitive transition.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Do not assume every LM393 has identical specifications. The supply range, input common-mode range, output saturation, timing, temperature rating, and suffix-dependent limits vary by manufacturer and version. Check the exact datasheet, including the TI LM393B datasheet, before substituting parts. ST and onsemi also publish LM393-family devices with their own specifications: ST and onsemi.
Rank #3
- 【Relay module parameters】1 Channel Relay Module: Working voltage: 5V; Static Current: 4mA; Working current:65mA; Trigger Voltage:0-1.2V; Trigger Current: 2mA; Maximum load: AC 250V/10A, DC 30V/10A.
- 【High Quality:】The 5V relay module is made of high -quality electrical components and semiconductor elements. High structural strength, impact resistance, strong resistance to impact, small input -end drive current, can easily be connected to the computer terminal and various digital programming circuit interfaces. Electricity performance is excellent, safe and reliable, and long mechanical life.
- 【Relay module connection method】DC+: positive power supply (VCC); DC-: negative power supply (GND); IN: Signal input terminal; NO: normally open relay interface; COM: Common Interface Relays; NC: normally closed relay interface.
- 【High-Efficiency】The relay shell is made of ABS flame retardant plastic.The internal structure adopts high -efficiency spring structure with high life span. High mechanical strength, reliable and stable.
- 【Application】The 5V relay module can be used as the MCU development module and can be used as home appliance control; it is widely used in industrial automation, electric furnace heating, stage lighting control, copy machine, medical equipment, petrochemical equipment, CNC machine tools and other automated control areas.
Setting the switching threshold
A basic reference can be made with a resistor divider:
+V ── Rtop ──┬── Rbottom ── ground
│
VREF
The approximate reference voltage is:
VREF = VSUPPLY × RBOTTOM / (RTOP + RBOTTOM)
For a variable threshold, replace one resistor with a potentiometer. For better accuracy, use a voltage reference instead of relying on a supply rail that may vary with load or battery state.
Choose divider resistance with comparator input bias current and sensor source impedance in mind. Very high-value dividers save power but are more vulnerable to leakage, interference, and bias-current errors. Add supply bypassing close to the comparator and keep relay-current paths away from low-level sensor wiring.
Free tools Windows power users keep installed
One-click scans. No signup required.
Input polarity
To turn the relay on when the sensor voltage rises above the reference, connect:
Sensor → IN+
Reference → IN−
To turn the relay on when the sensor voltage falls below the reference, reverse the inputs:
Sensor → IN−
Reference → IN+
With an open-collector output, also account for the fact that the output’s low state is produced by sinking current through the pull-up. Verify the final polarity with a multimeter or LED before connecting the controlled load.
Rank #4
- It is 4 Channel Isolated 5V 10A Relay Module, each relay can individually switch on/off by an opto-isolated digital input, Standard interface can be directly connected with microcontrollers and be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM, DSP, etc., very convenient.
- Equipped with high-current relay, maximum load: AC250V 10A, 15A 125VAC, DC30V 10A; Trigger current of opto-isolator: 5mA.
- RELIABLE: Fault-tolerant design, even if the control line breaks, the relay will not move; With optical coupling isolation, triggering more reliable, more stable.
- EASY to INSTALL: Equipped with screwed terminal plate and fixed bolt holes(diameter: 3.1 mm) on both sides for easy installation.
- High/Low level trigger can be selected by jumper. Very versatile, you can reverse the input logic with the jumper.
Why hysteresis prevents relay chatter
A relay should not switch at exactly one threshold when the input is noisy or slowly changing. Without hysteresis, a signal hovering around 5.00 V could repeatedly turn the relay on at 5.01 V and off at 4.99 V.
Positive feedback creates two thresholds:
VIN > VON → relay turns on
VIN < VOFF → relay turns off
The difference between VON and VOFF is the hysteresis band. A clean signal may need only 10–50 mV. A noisy sensor may need 100–500 mV or more. Battery and environmental measurements often benefit from a wider band because they change slowly and do not need rapid switching.
The hysteresis resistor cannot be chosen universally. Its value depends on the sensor source resistance, reference-divider resistance, desired upper and lower thresholds, comparator input current, and feedback topology. A design that simply inserts a “10 kΩ” or “100 kΩ” resistor without those details is not generally reproducible.
TI’s comparator design guidance covers hysteresis, filtering, input capacitors, and power-down behavior. An input capacitor can interact with the positive-feedback network, so add filtering deliberately rather than placing a large capacitor across the sensor input by default.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Flyback protection for the coil
A DC relay coil is inductive. When its current is interrupted, the collapsing magnetic field produces a voltage spike that can damage the transistor and disturb or destroy the comparator or other electronics.
+Vrelay ────────┬──── Relay coil ────┬──── transistor
│ │
└────|<|────────────┘
diode
For a conventional DC coil, connect the diode directly across the coil: cathode to the positive coil terminal and anode to the transistor side. Select a diode with suitable forward-current and pulse ratings for the coil.
Best Value
- 2 Channel Relay Module Voltage : 5V; Normally Open Interfaces Maximum Load : AC 250V/10A, DC 30V/10A
- 2 Channel Relay Module 5V Comes with High-Current Relay,Trigger Current : 5mA
- 5V Relay Module is 2 Channel Isolated, Each Relay Can Individually Switch On/Off by An Opto-Isolated Digital Input
- Relay Module Designed With Fault-Tolerant , Even If The Control Line Breaks, The Relay Will Not Move; With Optical Coupling Isolation,Triggering More Reliable and Stable
- 2 Channel Module Equipped With Screwed Terminal Plate and Fixed Bolt Holes,Standard Interface Can Connect With Microcontrollers and be Controlled by a Wide Range of Microcontrollers
A plain diode gives excellent protection but slows relay release because it clamps the turn-off voltage to a low level. If fast release matters, use a zener-plus-diode arrangement, TVS clamp, or another suppression method that permits a higher reverse voltage. The transistor must be rated for the resulting voltage. Panasonic’s relay application guidance discusses transistor driving, suppression, hysteresis-related behavior, and release-time trade-offs.
Do not place an ordinary flyback diode across an AC relay coil. AC coils require an appropriate suppression strategy, such as an RC snubber or other correctly rated device.
Supply and input limits
Before building the circuit, verify:
- Comparator supply-voltage range
- Input common-mode range
- Maximum differential input voltage
- Output voltage and sink-current limits
- Sensor-output voltage range
- Relay coil voltage and current
- Transistor voltage and current ratings
- MOSFET
RDS(on)at the available gate voltage
Although TI lists the standard LM393 product family with a 2–36 V supply range, the exact suffix and manufacturer remain authoritative. A comparator rated for a 5 V supply may not be suitable for a 3.3 V design, and an input that reaches the supply rail may still violate the device’s common-mode range.
Troubleshooting
The relay does not energize
- Confirm the coil voltage and expected coil current.
- Check the transistor pinout; collector and emitter are not interchangeable.
- Check the MOSFET gate voltage and its
RDS(on)specification. - Verify that the LM393 has a pull-up resistor.
- Check comparator input polarity and common ground.
- Measure voltage across the coil and transistor when the relay should be on.
- Confirm that the comparator output is not overloaded.
The relay remains energized
- Inputs may be reversed.
- The open-collector output may have been misunderstood.
- The pull-up may be connected to the wrong rail.
- A MOSFET gate may be floating.
- The sensor may never cross the intended threshold.
- The relay coil pins may have been confused with its contact pins.
The relay chatters
Add or increase hysteresis, then inspect sensor noise, supply ripple, grounding, long unshielded wires, and electromagnetic coupling from the coil. Keep the relay driver physically away from the comparator input and decouple the comparator supply close to its pins.
The relay releases too slowly
A standard flyback diode is probably providing strong protection at the cost of slower release. Consider a correctly rated zener or TVS clamp and verify the transistor’s voltage rating.
The comparator oscillates or switches unpredictably
Check the reference stability, input common-mode range, source impedance, supply bypassing, PCB ground layout, hysteresis network, and capacitor placement. Slow input ramps and long sensor wires are especially likely to expose a marginal design.
Relay contacts and mains safety
A low-voltage comparator circuit does not make the relay’s contact-side load safe automatically. For mains or high-energy loads, check the relay’s AC and DC contact ratings, inrush-current rating, inductive-load derating, creepage, clearance, fusing, enclosure, earthing, and required isolation.
Recommended Free Tools
Use appropriate suppression on inductive AC loads, such as a correctly rated snubber or MOV. High-voltage wiring should follow local electrical requirements and be installed by a qualified person where required.
Alternatives
| Application | Suitable choice |
|---|---|
| Simple threshold switching | Comparator plus transistor or MOSFET |
| Sensor needs amplification first | Op-amp followed by comparator |
| Relay operates only within two limits | Window comparator |
| Already have a logic-level signal | Schmitt-trigger gate |
| Timed relay operation | Timer or monostable |
| Multiple thresholds, calibration, or logging | Microcontroller plus external driver |
| Silent or high-cycle switching | Solid-state relay or MOSFET switch |
A prebuilt relay module may be quicker, but modules differ in active-high or active-low behavior, pull-ups, isolation, coil voltage, and input requirements. A bare comparator and discrete driver provide more control and make the threshold, hysteresis, and protection visible and adjustable.
Quick Recap
Selection guide
| Choose this | When |
|---|---|
| Comparator | You need a reliable analog threshold decision. |
| Op-amp | You need linear amplification or filtering, or the switching is slow and non-critical. |
| LM393-family device | You want a familiar dual comparator with an open-collector output and can provide a pull-up. |
| Modern low-voltage comparator | You need 3.3 V operation, rail-to-rail inputs, low offset, low power, or faster switching. |
| NPN transistor | The relay current is modest and sufficient base current is available. |
| Logic-level N-MOSFET | The coil current is higher or low drive power is important. |
| Dedicated high-speed comparator | Timing or switching speed is critical. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

