Comparator chips: LM393, LM339 and LM311

The LM393, LM339 and LM311 comparator chips, in their DIP packages with their datasheet pinouts and open-collector outputs.

The LM393 has two comparators (DIP-8, also sold as the LM2903), the LM339 four (DIP-14, also the LM2901) and the LM311 one fast comparator with a strobe (DIP-8). Aliases: LM393N, LM2903, LM339N, LM2901, LM311N, voltage comparator.

A comparator answers one question: which of its two inputs is higher? It is the chip on every sensor module with a blue trimmer: the modules for the flame, rain, MQ-2, TCRT5000 and KY-038 sensors are each an LM393 with a sensor on it. These are the bare chips.

The output needs a pull-up

None of these chips can drive its output high. The output is an open collector: a transistor that either pulls the pin down to ground or lets go of it completely.

  • IN+ above IN-: the transistor is off, and the pin is pulled up by whatever resistor you put on it.
  • IN+ below IN-: the transistor is on and pulls the pin to about 0.15 V.

So every output needs a pull-up resistor, usually 10 k, from the output to the supply of whatever reads it: 5 V for an Uno, 3.3 V for an ESP32 or a Pico. That is the point of an open collector: the chip can run on 5 V or 12 V and still hand a 3.3 V board a 3.3 V high. Without a pull-up the low still works and the high is not there at all: the pin floats, an Arduino reads noise, and a meter in the simulator shows nothing on it. An Arduino input with INPUT_PULLUP is a pull-up too (about 35 k), which is enough for a pin to read.

An LED from the supply through a resistor into the output lights while the output is low, which is the other common way to use one.

Pinouts

Pin LM393 LM311
1 1OUT EMIT (emitter, usually to ground)
2 1IN- IN+
3 1IN+ IN-
4 GND VCC-
5 2IN+ BAL (balance)
6 2IN- STRB (balance and strobe)
7 2OUT COL (the output, open collector)
8 VCC VCC+

The LM393 has the LM358's pinout. The LM339 does not have the LM324's: its outputs are pins 1, 2, 13 and 14 and its supply is on pins 3 and 12.

Pin LM339 Pin LM339
1 1OUT 8 3IN-
2 2OUT 9 3IN+
3 VCC 10 4IN-
4 2IN- 11 4IN+
5 2IN+ 12 GND
6 1IN- 13 4OUT
7 1IN+ 14 3OUT

The numbers

From TI's data sheets, typical at 25 °C:

Chip supply output low response time
LM393, LM339 2 V to 36 V 150 mV at 4 mA 1.3 µs
LM311 3.5 V to 30 V 0.23 V at 8 mA 165 ns

The low is a resistance (37.5 Ω on the LM393 and LM339, 29 Ω on the LM311), so a pull-up that sinks more current sits a little higher: a 1 k pull-up from 5 V reads 0.18 V. The response time is a delay from the crossing to the pin. Below its minimum supply a chip lets go of its outputs.

The LM311

Its output transistor has both ends on pins. COL (pin 7) is the output and pulls down to EMIT (pin 1). Wire EMIT to ground, even when the chip runs on a split supply such as ±12 V: then it compares signals below ground and still hands a board a 0 V low. Pulling STRB (pin 6) low, with a transistor to ground as TI's sheet draws it, turns the output off whatever the inputs say. The simulator reads STRB as a voltage: held more than 3 V below VCC+ it strobes. Left open or tied to VCC+ it does nothing.

Properties

offset is the input offset voltage in millivolts, added to IN+ of every comparator in the package, and zero unless you set it. A real LM393's is a few millivolts either way, which moves its switching point by that much.

While it runs

Each output lead and its label light while that output is released (IN+ above IN-), which is a high once a pull-up is on it.

What the model gets right

The switching point, the open collector (a high that only exists with a pull-up, to whatever voltage the pull-up goes to), the resistive low, the response delay, the minimum supply, the LM311's emitter and strobe, and real hysteresis when you add a feedback resistor from the output to IN+.

What it does not model

There is no sink-current limit: a real LM393 output gives out at about 16 mA, so an LED wired straight from 5 V into an output with no resistor is dim on the bench and bright here. Put the resistor in. There is no common-mode input range: a real LM393's inputs only work up to 1.5 V under VCC (the output is still right if one of them is inside it), and here they work anywhere. A slow input sitting exactly on the threshold of a real comparator with no feedback chatters; here it switches once. The LM311's BAL pin and the balance use of STRB (an offset trimmer between them) are not connected, so use offset. The LM311's emitter is the reference its collector pulls to, not an output of its own: an emitter-follower circuit is not modeled.

Common mistakes

No pull-up: the output reads low fine and never reads high. A pull-up to 5 V on a comparator that feeds a 3.3 V board: pull up to 3.3 V instead. Expecting the LM339 to have the LM324's pinout. Leaving the LM311's EMIT pin unconnected: then its output has nothing to pull down to.

See it in action

LM393 night light with a ULN2003A, LM311 zero-cross detector into an Arduino and LM339 window comparator are in the gallery at /templates, and /learn/uln2003-darlington-driver walks through them.