4
\$\begingroup\$

I came into Electronics through Arduino, so pardon me if my knowledge about non-Arduino circuits is somewhat silly. I am preparing a small electronics project for my school with LDRs to detect light levels. With, an Arduino I could easily detect light levels and when they go down a threshold, I turn on a relay.

But, I wanted to make this without an Arduino, so I though of using an LM339 Comparator. I connected pin 3 of IC to Vcc and pin 12 to Ground. Pin 4 has an input lower than the input on pin 5 which receives input from Vcc. Lastly, I had the output 1 from pin 2 connected to an LED.

This circuit is only to test the comparator. If it works I am going to change the reference voltage and in place of the LED place a transistor. Here is a quick circuit Diagram I created:enter image description here

But, the LED does not glow. Even if I switch the inupts, the LED does not glow. I tested this in circuits.io, the online simulator. It works perfect there. But, the problem persists on the breadboard.

How do I get the LED to glow in my circuit on the bench?

UPDATE: I just got the LED glowing with the help of Raj, but how can I connect the base of a transistor in place of the LED.

\$\endgroup\$
  • 6
    \$\begingroup\$ 1) ALWAYS use a series resistor when using a LED, in case of doubt use 1 k ohm. 2) The LM339 cannot supply current, it can only sink it. So place the LED + resistor between Vcc and the output, swap the inputs (as now the LED will be on when the output is LOW) and the LED will light up. \$\endgroup\$ – Bimpelrekkie Jan 31 '17 at 15:30
  • 1
    \$\begingroup\$ You should also be aware of the common-mode input range of the LM339, which is zero to Vcc - 2V. If both inputs are above this range, the output will be low regardless of which is higher \$\endgroup\$ – user28910 Jan 31 '17 at 15:51
  • 1
    \$\begingroup\$ It sounds the online simulator isn't very good, to be honest. \$\endgroup\$ – Dietrich Epp Jan 31 '17 at 20:34
8
\$\begingroup\$

LM339 comparator output is open collector mean you can make the led glow by connecting the anode to vcc and cathode to the output pin.

please note:

add a series resistor to the LED or else the LED will make a short to the open collector output transistor of the LM339

simple comparator

\$\endgroup\$
  • \$\begingroup\$ Hah, beat me to it! You need a resistor between Vcc and the output. (5 k ohm traditional?) \$\endgroup\$ – George Herold Jan 31 '17 at 15:29
  • \$\begingroup\$ Can you also tell me how I can connect the output to base of a NPN transistor ? That's what I plan on doing later. \$\endgroup\$ – Delta_Shadow Feb 1 '17 at 4:59
  • \$\begingroup\$ I had updated the circuit, the comparator has a internal NPN transistor, with collector connected to output, it can sink current around 10 - 15 ma check the data sheet of your device \$\endgroup\$ – Raj Feb 1 '17 at 5:17
  • \$\begingroup\$ Thanks Raj, the circuit works perfectly ! Chose this as the correct answer. Thanks ! \$\endgroup\$ – Delta_Shadow Feb 1 '17 at 7:34
  • \$\begingroup\$ Hey, your updated circuit looks to be malfunctioning. The LED keeps on glowing. Can you tell me whats wrong ? \$\endgroup\$ – Delta_Shadow Feb 4 '17 at 15:34
3
\$\begingroup\$

The LM339 has open-collector outputs, which means that they can sink current but not source it.

In order to see any changes in the output state, you'll have to connect your LED (WITH a current-limiting resistor!) between the positive supply and the output.

\$\endgroup\$
  • \$\begingroup\$ Is there any other comaparator which does not use an open-collector at the output. Like LM397, or LM393 ? \$\endgroup\$ – Delta_Shadow Feb 1 '17 at 5:03
  • \$\begingroup\$ @Delta_Shadow, Comparators traditionally use open collector style outputs, if you want bipolar drive select a suitable OP-Amp instead. Remember the commonmode input and output limits. \$\endgroup\$ – KalleMP Feb 1 '17 at 5:56
1
\$\begingroup\$

LM339 has open collector outputs. The load must be against the + supply voltage. LM339 can't push out the +, it only sinks current. You're lucky, because the led needs a series resistor to keep the current safely low.

The following link has several circuits, also some with LM339.

http://www.bristolwatch.com/ele2/comparator.htm

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.