LM339 window comparator
Two LM339 comparators with their open-collector outputs wired together light one LED whenever a knob leaves the window from 1.67 V to 3.33 V. There is no microcontroller in it: the simulator solves the 7 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The parts retail for about $6.10. On Mokxi they're free.
How it works
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// An LM339 window comparator: one LED lights when the knob is outside 1.67 V
// to 3.33 V.
//
// Three 10 k resistors from 5 V to ground make 3.33 V and 1.67 V. Two of the
// LM339's four comparators watch the knob:
//
// comparator 1: knob on 1IN- (pin 6), 3.33 V on 1IN+ (pin 7). Its output
// pulls down while the knob is above 3.33 V.
// comparator 2: knob on 2IN+ (pin 5), 1.67 V on 2IN- (pin 4). Its output
// pulls down while the knob is below 1.67 V.
//
// The two outputs, 1OUT (pin 1) and 2OUT (pin 2), are wired together. That
// is only allowed because they are open collector: each can only pull down,
// so either one pulling down pulls the pair down, and neither fights the
// other. One LED and a 470 ohm resistor from 5 V into the pair is their
// pull-up and their lamp: it lights while either output pulls down, outside
// the window, and goes out inside it.
//
// Two op-amp outputs wired together like this would fight, one driving high
// while the other drives low. That is the difference.
//
// The LM339's pinout is its own: outputs on pins 1, 2, 13 and 14, VCC on
// pin 3, GND on pin 12. Comparators 3 and 4 are not used.
Parts list
9 parts, plus the jumper wires. They retail for about $6.10; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × Potentiometer
- 1 × LM339 quad comparator
- 3 × Resistor, 10k Ω
- 1 × Resistor, 470 Ω
- 1 × LED, red
How it is wired
7 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- 5 V: Potentiometer pin 1; LM339 quad comparator pin VCC; Resistor, 10k Ω (1) pin 1; LED, red pin A
- Ground: Potentiometer pin 3; LM339 quad comparator pin GND; Resistor, 10k Ω (3) pin 2
- Potentiometer pin 2; LM339 quad comparator pin 2IN+; LM339 quad comparator pin 1IN-
- LM339 quad comparator pin 1OUT; LM339 quad comparator pin 2OUT; Resistor, 470 Ω pin 2
- LM339 quad comparator pin 2IN-; Resistor, 10k Ω (2) pin 2; Resistor, 10k Ω (3) pin 1
- LM339 quad comparator pin 1IN+; Resistor, 10k Ω (1) pin 2; Resistor, 10k Ω (2) pin 1
- Resistor, 470 Ω pin 1; LED, red pin C
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.