Parts

LM358 vs LM393: which one for your threshold circuit, and what breaks when you swap them

By

The LM358 is a dual op amp. The LM393 is a dual comparator. They share the same pin order: outputs on 1 and 7, inputs on 2-3 and 5-6, ground on 4, supply on 8. Both run from a single supply and both accept inputs down to ground. That is why people mix them up, and why one often ends up in the other's socket.

They behave differently in four ways:

  • The LM358 drives its output high and low. The LM393 output can only pull down, so it needs a pull-up resistor to go high. That resistor can go to any voltage up to 36 V, so shifting a 5 V signal down to 3.3 V takes one resistor.
  • As a comparator the LM393 is faster. TI gives it a typical response of 1.3 µs. The LM358 slews at 0.3 V/µs, so a 3.5 V swing on a 5 V supply takes about 12 µs.
  • The LM358 amplifies, buffers and filters. TI says the LM393 "operates solely as a voltage comparator", so it cannot be an amplifier.
  • The LM393 runs from 2 V, the LM358 from 3 V. Both are rated to 30 V.

Rule of thumb: if the output only ever needs to be high or low, use the LM393 and fit the pull-up. If the output is an analog voltage (a gain stage, a buffer, a filter), use the LM358. An LM358 used as a comparator works for slow signals like a thermostat or a battery alarm. It is the wrong choice for anything that switches more often than a few thousand times a second.

Datasheet: Texas Instruments LM393B, LM2903B, LM193, LM293, LM393 and LM2903 Dual Comparators (SLCS005AH) (PDF)

Advertisement

Pinout by package

LM358P DIP-8 · TI1=OUT1 2=IN1- 3=IN1+ 4=V- 5=IN2+ 6=IN2- 7=OUT2 8=V+
top view, notch upLM358P18OUT1V+27IN1-OUT236IN1+IN2-45V-IN2+

Top view, notch up: pin 1 is top left. Two op amps; V− (or ground) on 4, V+ on 8.

Source: Texas Instruments LMx58, LM2904 Industry-Standard Dual Operational Amplifiers (SLOS068AB), p. 3 (Figure 4-1 and Table 4-1, 8-pin packages: OUT1 1, IN1− 2, IN1+ 3, V− 4, IN2+ 5, IN2− 6, OUT2 7, V+ 8)

LM393P DIP-8 · TI1=1OUT 2=1IN- 3=1IN+ 4=GND 5=2IN+ 6=2IN- 7=2OUT 8=VCC
top view, notch upLM393P181OUTVCC271IN-2OUT361IN+2IN-45GND2IN+

Top view, notch up. The same pin order as the LM358; the outputs on 1 and 7 can only pull down.

Source: Texas Instruments LM393B, LM2903B, LM193, LM293, LM393 and LM2903 Dual Comparators (SLCS005AH), p. 3 (Figure 4-1 and Table 4-1, D, DGK, JG, P, PS, DDF and PW packages: 1OUT 1, 1IN− 2, 1IN+ 3, GND 4, 2IN+ 5, 2IN− 6, 2OUT 7, VCC 8)

Same socket, different output

Both chips put the same signal on the same pin, so the boards look identical. The difference sits behind pins 1 and 7. The LM358 has two output transistors, one that pulls up and one that pulls down. The LM393 has only the bottom one: an NPN that sinks current when IN− is above IN+ and lets go otherwise.

LM358 / LM3931 OUT12 IN1−3 IN1+4 GND / V−8 VCC / V+7 OUT26 IN2−5 IN2+LM358: push-pullV+pin 1drivedrives highand lowLM393: open collectorto 3.3 V or 5 VRPULLUPpin 1pulls low;high only viathe resistor
Figure 1. The shared 8-pin order, and what sits behind pin 1 on each chip. The LM358 output drives both ways; the LM393 output pulls low and needs a resistor to reach the high level.

The logic sense is the same on both: the output goes low when IN− is above IN+. What changes is what "high" means. On the LM358 it is a driven voltage, at least 3.5 V on a 5 V supply. On the LM393 it is whatever the pull-up resistor connects to.

Side by side

What each chip is, and its supply and temperature limits, from the TI datasheets
ParameterLM358PDIP-8LM393PDIP-8
What it isdual operational amplifierdual voltage comparator
Supply, recommended VS3 to 30 V2 to 30 V
Supply, absolute maximum VS32 V36 V
Output stagepush-pull: drives high and lowopen collector: pulls low only, a pull-up sets the high level
ESD rating, human-body model±500 V (LM358B: ±2000 V)±2000 V
Operating temperature TA0 to 70 °C (LM2904: −40 to 125 °C)0 to 70 °C (LM2903: −40 to 125 °C)
Electrical characteristics at a 5 V supply and 25 °C unless the row says otherwise
ParameterLM358PDIP-8LM393PDIP-8
Output high, 5 V supply VOHat least 3.5 V (within 1.5 V of V+, load 2 kΩ or more)set by the pull-up rail, up to 36 V
Output low VOL5 typ / 20 max mV above V− (light load)130 typ / 400 max mV at 4 mA sink
Output currentsource 20 mA min, sink 10 mA min (15 V supply)sink 6 mA min at 1.5 V; 20 mA absolute max
Input range VICR0 V to V+ − 1.5 V at 25 °C (V+ − 2 V over 0 to 70 °C)0 V to VCC − 1.5 V at 25 °C (VCC − 2 V over 0 to 70 °C)
Input offset voltage VOS3 typ / 7 max mV at 25 °C; 9 mV max, 0 to 70 °C2 typ / 5 max mV at 25 °C; 9 mV max, 0 to 70 °C
Input bias current, 25 °C IB20 typ / 250 max nA (500 nA, 0 to 70 °C)25 typ / 250 max nA (400 nA, 0 to 70 °C)
Speed0.7 MHz gain bandwidth; 0.3 V/µs slew rate1.3 µs typ response (5 mV overdrive); 0.3 µs with a TTL-level step
Supply current, 5 V, no load IQ350 typ / 600 max µA per amplifier0.45 typ / 1 max mA for both comparators

The two speed rows measure different things, so don't compare 0.3 V/µs with 1.3 µs directly. Example 1 turns them into the same unit. The LM393 column is TI's original LM393, not the newer LM393B, which has its own tables in the same datasheet.

The swap trap: the pins match, the outputs don't

Because the pinouts line up, an LM393 fits an LM358 socket and the reverse. The circuit around it decides whether it works.

An LM393 in an LM358 circuit

  • Any amplifier, buffer or filter stops working. The LM393 has no linear output and no way to drive high.
  • An LM358 wired as a comparator with its load to ground (an LED from the output to ground, or a logic input with a pull-down) goes dark. The LM393 output never drives high on its own. Add a pull-up resistor from each output to the rail the load expects.
  • The logic sense stays the same. Both outputs go low when IN− is above IN+.

An LM358 in an LM393 circuit

  • The pull-up resistor stays on the board. The LM358 can drive against it, so this mostly still works, but the output's high level is now set by the LM358 (at least 3.5 V on a 5 V supply), not by the pull-up rail.
  • If the LM393's pull-ups went to a different rail (for example a 5 V comparator feeding a 3.3 V microcontroller), the LM358 now drives its own high level into that pin. See example 2.
  • Two LM393 outputs tied together (a wired-AND, which TI's datasheet describes) become two LM358 outputs fighting each other. TI warns that an LM358 output shorted to the supply can overheat and fail. Don't tie LM358 outputs together.
  • Edges get about ten times slower. See example 1.
a. LM393, pull-up to 3.3 V5 Vpin 8−+LM3933.3 V10 kΩ3.3 VGPIOhigh = the 3.3 V pull-up railsafe for the GPIOb. LM358 fitted instead5 Vpin 8−+LM358no pull-up3.3 VGPIOhigh = at least 3.5 V, set by 5 Vabove the 3.3 V rail
Figure 2. The same 5 V board feeding a 3.3 V input. With the LM393 the high level is the 3.3 V pull-up rail. With an LM358 fitted, the high level comes from the chip: at least 3.5 V, with no upper limit in TI's table short of the 5 V rail.

Worked examples

1. How fast does the output switch?

You want a clean digital edge from a slowly moving sensor signal, on a 5 V supply.

  • LM358 used as a comparator: the output has to travel from near 0 V to at least 3.5 V. At the typical slew rate of 0.3 V/µs that takes 3.5 ÷ 0.3 = 11.7 µs, and the same again on the way down. That figure comes from a unity-gain test. TI does not say how fast the LM358 recovers when it runs open-loop and saturated, so treat 12 µs as a floor, not a promise.
  • LM393: TI gives 1.3 µs typical from the input step to the output crossing 1.4 V, with only 5 mV of overdrive. With a TTL-sized input step it is 0.3 µs. The rising edge also depends on the pull-up: TI gives the rise time as about RPULLUP × CL, so 4.7 kΩ and 15 pF give 71 ns.

Say you square up a 40 kHz signal (an example input; a 40 kHz ultrasonic receiver is a common hobby case). Each half-cycle lasts 12.5 µs. The LM358 needs about 11.7 µs just to move its output from one level to the other, so the "square" wave is mostly ramps. The LM393's 1.3 µs response fits easily. For a signal of a few hundred hertz, or a thermostat that switches once a minute, the LM358 is fast enough.

0 µs12.5 µs25 µs37.5 µs50 µsinput40 kHzLM35811.7 µs rampsLM3931.3 µs delaytypical figures; sketch, not a simulation
Figure 3. A 40 kHz input and the two outputs on one time axis, drawn from TI's typical figures: the LM358 ramps at 0.3 V/µs and needs 11.7 µs of each 12.5 µs half-cycle; the LM393 switches about 1.3 µs after each input edge. A sketch, not a simulation; the LM358's recovery from saturation is not specified.

2. A 5 V sensor stage feeding a 3.3 V microcontroller

The sensor and the comparator run from 5 V. The output goes to a GPIO pin on a 3.3 V board.

  • LM393 with a 10 kΩ pull-up to the 3.3 V rail: the output high is 3.3 V. TI's high-level leakage is 50 nA maximum, which drops 50 nA × 10 kΩ = 0.5 mV across the resistor. When the output is low it sinks 3.3 V ÷ 10 kΩ = 0.33 mA, well inside TI's 1 µA to 4 mA pull-up range, so the low level stays under the 400 mV that TI gives at 4 mA.
  • LM358 on the same 5 V supply: the output goes at least as high as 3.5 V with a 2 kΩ or lighter load, and TI gives no upper limit short of the rail. That is above the 3.3 V rail. Check your microcontroller's datasheet for its input limit, then either add a divider on the output or switch to the LM393.

The LM393 does this with one resistor, which is the main reason to pick a comparator over an op amp for a logic output.

3. An indicator LED

You want an LED that lights when the input crosses the threshold, on a 5 V supply. For this example take a red LED with a 2.0 V forward drop (read yours from its datasheet).

LM393: connect the LED and its resistor from 5 V down to the output. The LED lights when the output pulls low, which is when IN− is above IN+. Aim for 4 mA, the current at which TI gives the low-level output voltage (130 mV typical, 400 mV maximum):

  • Resistor: (5 − 2.0 − 0.4) ÷ 0.004 = 650 Ω. The next E24 value up is 680 Ω.
  • Current with 680 Ω: 3.82 mA worst case, about 4.22 mA typical.

In this connection the LED and its resistor are the only pull-up on that output. If the same output also feeds a logic input, add a pull-up resistor anyway, so the logic sees a defined high when the LED is off.

LM358: either connection works, because the output drives both ways. With the LED from the output to ground it lights while the output is high. TI gives the LM358's source current as at least 20 mA, but only at a 15 V supply. At 5 V the output high is lower, at least 3.5 V, so work the resistor out from 3.5 V, not 5 V: (3.5 − 2.0) ÷ 0.004 = 375 Ω, next E24 value 390 Ω. Measure the high level on your board if you need a precise current. The LED resistor calculator does the same sum for other LEDs.

a. LM393: LED from 5 V5 V680 ΩOUTlit while the output is low3.82 mA worst caseb. LM358: LED to groundOUT390 Ωlit while the output is highfrom 3.5 V, not 5 V
Figure 4. The LED connection for each chip on 5 V, with a 2.0 V LED: from the supply into the LM393 output through 680 Ω, and from the LM358 output to ground through 390 Ω.

4. A low-battery alarm for a 12 V battery

A 5 V regulator runs the circuit. You want the alarm to trip when a 12 V lead-acid battery falls to about 11.5 V. The battery numbers here are example inputs; take your own from the battery maker.

The input range sets the divider. On a 5 V supply both chips accept 0 V to 3.5 V at 25 °C, but only up to 3.0 V across 0 to 70 °C. Plan for 3.0 V. If the battery can reach 15 V while charging, the divider must keep 15 V under 3.0 V:

  • Battery divider 43 kΩ over 10 kΩ: ratio 10 ÷ 53 = 0.189. At 11.5 V the tap sits at 2.17 V; at 15 V it reaches 2.83 V. Both are inside the range.
  • Reference divider 13 kΩ over 10 kΩ from the 5 V rail: 5 × 10 ÷ 23 = 2.17 V. The alarm trips at 2.174 ÷ 0.189 = 11.52 V. The trip point moves with the 5 V rail, so it can be no better than the regulator's accuracy. The voltage divider calculator works out other ratios.

Accuracy, worst case over 0 to 70 °C, referred back to the battery:

  • Offset: both chips are 9 mV maximum. 9 mV ÷ 0.189 = 48 mV at the battery.
  • Bias current through the divider's 8.11 kΩ source resistance (43 kΩ in parallel with 10 kΩ): the LM393's 400 nA gives 3.2 mV, the LM358's 500 nA gives 4.1 mV. Both are small next to the offset.

So for a slow DC threshold like this the LM358 is as accurate as the LM393. Pick by the output you need: a pull-up to a logic rail favors the LM393; driving a buzzer transistor's base from a push-pull output favors the LM358. Either way, a battery voltage that drifts slowly through the threshold will make the output chatter. The LM393 page shows how to add hysteresis with one feedback resistor.

What if the divider had been 36 kΩ over 10 kΩ, putting 11.5 V at 2.50 V? At 14.4 V the tap reaches 3.13 V, just above the 3.0 V limit. TI's LM393 sheet says the output stays correct as long as one input is inside the range, and the 2.50 V reference is. The LM358 sheet makes no such statement, so on an LM358 keep both inputs inside the range.

5 V12 V battery +43 kΩ10 kΩtap13 kΩ10 kΩ−+LM39310 kΩOUTlow = battery low0.1 µFat pin 8tap 2.17 V at 11.5 V, 2.83 V at 15 V; reference 2.17 Vinput limit 3.0 V on a 5 V supply, 0 to 70 °C
Figure 5. Example 4 as an LM393 circuit. The reference goes to IN− and the battery tap to IN+, so the output pulls low when the battery drops below about 11.52 V. The divider keeps the tap at 2.83 V even with 15 V on the battery, under the 3.0 V input limit.

5. Current draw on a battery

Both chips idle on very little current, so the choice rarely matters for battery life. At 5 V with no load:

  • LM358: 350 µA typical, 600 µA maximum per amplifier, so 0.7 mA typical and 1.2 mA maximum for the pair.
  • LM393: 0.45 mA typical, 1 mA maximum for both comparators together.

The LM393's pull-up resistor draws current whenever the output is low: 5 V ÷ 10 kΩ = 0.5 mA per output. If the output sits low most of the time, that resistor costs more than the chip. Use a larger pull-up (100 kΩ draws 50 µA) when speed doesn't matter, since the rise time grows with RPULLUP × CL.

00.5 mA1 mALM358 pair0.7 mA typ, 1.2 mA maxLM393 pair0.45 mA typ, 1 mA max10 kΩ pull-up0.5 mA while low
Figure 6. Supply current at 5 V with no load, both halves of each chip, and the extra current of one 10 kΩ pull-up while its output is low. The bars are typical values; the black ticks are TI's maximums.

Worked example in numbers

LM358 edge on 5 V
11.7 µs
LM393 response, typ
1.3 µs
Alarm trip point
11.52 V
LED resistor, LM393
680 Ω

Swapping one for another

Pin order read with the flat face toward you, leads down, left to right
PartPinsVerdict
LM393 for an LM358same pinoutOnly where the LM358 is used as a comparator, and only with a pull-up on each output that has to go high. Amplifiers, buffers and filters stop working.Texas Instruments LM393B, LM2903B, LM193, LM293, LM393 and LM2903 Dual Comparators (SLCS005AH), p. 17
LM358 for an LM393same pinoutWorks for slow thresholds if no outputs are tied together and the next stage accepts the LM358 high level. Edges are about ten times slower.Texas Instruments LMx58, LM2904 Industry-Standard Dual Operational Amplifiers (SLOS068AB), p. 10; Texas Instruments LMx58, LM2904 Industry-Standard Dual Operational Amplifiers (SLOS068AB), p. 4
LM393B for an LM393same pinoutTI calls it a drop-in replacement. It runs from 2 to 36 V.Texas Instruments LM393B, LM2903B, LM193, LM293, LM393 and LM2903 Dual Comparators (SLCS005AH), p. 1
Advertisement

Which one fits your job

  • Choose the LM393 for threshold detectors with a logic output, level shifting to 3.3 V or up to 12 V, zero-crossing and pulse squaring, wired-AND alarm lines, and anything that must switch faster than about 10 µs.
  • Choose the LM358 for amplifiers, buffers, active filters, current-sense stages and integrators, and for slow comparators where you want one chip to do both a gain stage and a threshold. For other op amps, see LM358 vs 741 vs TL072.
  • To swap an LM358 comparator for an LM393, add a pull-up on each output that needs to go high, and check the output polarity your load expects.
  • To swap an LM393 for an LM358, check that the circuit doesn't tie outputs together, that the pull-up rail is the same as the supply (or that the next stage tolerates the LM358's high level), and that the slower edges are acceptable.
  • The newer TI B versions keep the same pins. TI says the LM393B is a drop-in replacement for the LM393; the LM358B is faster (1.2 MHz, 0.5 V/µs) and runs to 36 V.

Tips and checks

  • Keep inputs from going more than 0.3 V below ground. TI warns that the LM393's output can then be wrong and excess input current can flow.
  • Bypass the supply at pin 8. TI's LM358 sheet asks for a 0.1 µF ceramic close to the pin; the LM393 sheet asks for a bypass capacitor and warns against running output traces parallel to the inverting inputs.
  • The LM393's output can be shorted to ground indefinitely. A short to the supply can destroy either chip.
  • The LM358 is rated for ±500 V human-body ESD, the LM393 for ±2000 V. Handle the LM358 with more care.

What we'd do

For any output that only has to be high or low we'd fit an LM393 with a 10 kΩ pull-up to the rail the next stage runs on. We'd keep the LM358 for gain stages and filters, and use its spare half as a comparator only when the signal is slow and the output can sit at the LM358's own high level.

Questions people ask

Can I use an LM358 as a comparator?

Yes, for slow signals. It works open-loop, drives both high and low, and its offset is as good as the LM393's for DC thresholds. Its 0.3 V/µs slew rate means about 12 µs per edge on a 5 V supply, so it is too slow for signals above a few kilohertz.

Can I use an LM393 as an op amp?

No. TI says it operates only as a voltage comparator. Its output can only pull down, so it cannot hold a linear output voltage.

Why does my LM393 output stay low or read 0 V?

Usually there is no pull-up resistor. The output is open collector and only pulls down. Add a resistor from the output to the logic rail. TI's design range is 1 µA to 4 mA of pull-up current; 10 kΩ to 5 V (0.5 mA) is a common choice.

Are the LM358 and LM393 pin-compatible?

The pin order is the same in the 8-pin packages: outputs on pins 1 and 7, inputs on 2-3 and 5-6, ground on 4, supply on 8. The output stages are different, so the circuit around the chip has to suit the one you fit.

Which is more accurate for a voltage threshold?

About the same. Over 0 to 70 °C both have a maximum input offset of 9 mV, and both have 250 nA maximum input bias current at 25 °C.

Where to go next

Each chip has its own page with packages, ratings and an application circuit: LM358 and LM393 (which also covers hysteresis and the quad LM339). The comparator lesson explains thresholds and hysteresis from the inside, and op-amp limitations covers slew rate and input range. If you are building a timer rather than a threshold, the NE555 is the part to read next.

Advertisement

One email a month from the bench

New circuits, lessons, part guides and calculators, on the first Sunday of each month.

We'll send one email to confirm. Every email has a one-click unsubscribe. Privacy policy

Used in these lessons

Lessons that go deeper

Datasheets this page was checked against

Makers revise datasheets. If the copy you download has a newer revision and a number here disagrees with it, the datasheet wins, and we would like to hear about it.