Comparison

LM358 vs LM393

Same pins, different jobs: op amp versus comparator.

The LM358 and LM393 are among the most common analog chips in hobby projects and on sensor modules. Both contain two devices in an 8-pin package, run from a single supply of up to about 30 V and share the same pinout: pin 1 output A, 2 and 3 the inputs of channel A, 4 ground (V−), 5 and 6 the inputs of channel B, 7 output B and 8 the supply (V+). Visually and on the board they are therefore interchangeable.

Functionally they are not. The LM358 is an operational amplifier, suited for amplifiers, filters and voltage followers. Its output drives actively in both directions but does not quite reach the supply voltage. The LM393 is a comparator: it compares two voltages and switches quickly and cleanly. Its output is an open collector that can only pull to ground and needs a pull-up resistor. Without that resistor the LM393 output stays floating. The other way round, an LM358 can be abused as a simple comparator, but it switches more slowly and without the clean levels of a real comparator. That is why many light sensor and soil moisture modules with a digital output use the LM393.

The table confirms the identical pinout from the pinout data.

Not pin-compatible

Same pin positions, but a different function (e.g. NAND vs AND gate, comparator vs op-amp): not a replacement.

Overview from the pinout data

PropertyLM358 Low-Power Dual Operational AmplifierLM393 Dual Differential Comparator
ManufacturerTexas Instruments / ON SemiTexas Instruments / ON Semi
TypeChipChip
Compared pinoutDIP-8 Top ViewDIP-8 Top View
Pins88
Supply pinsV+V+
Ground pins11
Interfaces––

Pin by pin

8 of 8 pins have the same function at the same position.

PinLM358 Low-Power Dual Operational AmplifierLM393 Dual Differential Comparator
1OUT AOUT Asame
2INA-INA-same
3INA+INA+same
4V-V-same
5INB+INB+same
6INB-INB-same
7OUT BOUT Bsame
8V+V+same

Verdict

Use the LM358 to amplify and filter analog signals. To switch at a threshold, for example for light, temperature or moisture sensors with a digital output, the LM393 with a pull-up resistor is the right choice.