How do I make an LED light up using a comparator? - Page 1
Forum section: electronics / beginners

author: renzoms
author_rank: Regular Contributor
timestamp: October 21, 2019, 11:37:45 pm
content: This is my circuit that lights up an LED for less than 4 seconds of volts using 4V. How do I make the LED light up? TLC372 comparator

author: james_s
author_rank: Super Contributor
timestamp: October 21, 2019, 11:41:12 pm
content: Many comparators have an open collector output, in which case you need to connect the LED (through the required resistor) from 5V to the output of the comparator. When the comparator triggers it will pull the output low and light the LED.

author: renzoms
author_rank: Regular Contributor
timestamp: October 21, 2019, 11:44:01 pm
content: I tried 5V to the current limiting resistor and (anode and cathode of the) LED, in series, then the output of the comparator the LED to ground. Didn't work

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 21, 2019, 11:46:29 pm
content: +in is grounded. Connect it to the other side of C1.Tim

author: renzoms
author_rank: Regular Contributor
timestamp: October 21, 2019, 11:50:42 pm
content: Greatness. Still doesn't work.

author: james_s
author_rank: Super Contributor
timestamp: October 21, 2019, 11:53:49 pm
content: Quote from: renzoms on October 21, 2019, 11:44:01 pmWhat do you mean? Don't connect the LED to ground, connect it to the output of the comparator. Nothing can control it if it's connected directly to ground.It would help to share a complete schematic of how you have it wired up

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:07:09 am
content: Tried these. This is what you meant, no?

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:07:53 am
content: In your schematic, option 1) is the correct way to do it. Comparator output > currentlimit resistor > LED anode--LED cathode > ground .Your schematic should work fine. When power is applied, the capacitor charges very fast through the resistor and the LED should come on. When power is removed the capacitor discharges through the other resistor to ground and when enough charge is drained off the LED should go out. If it works backwards, then your inputs should be swapped around. If the time is too short, use a larger (higher ohm) resistor across the capacitor. The greater this resistance the longer it will take for the charge on the cap to bleed down. Doesn't TAOE use a 6 Megohm resistor here?

author: james_s
author_rank: Super Contributor
timestamp: October 22, 2019, 12:11:01 am
content: How can you expect any of those options besides the first to work? All of the others have the output of the comparator connected directly to +5V or ground, that's like connecting a tractor directly to an immovable object and expecting it to move. You never connect an output directly to a voltage source or ground, ever. It's entirely possible that this has damaged the comparator as it will have resulted in a direct short.Even the first one can't work if the comparator has an open-collector output because such an output can only pull down toward ground, it cannot push up toward the supply voltage.

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:13:30 am
content: Well itt would have been damaged, or not damaged, if I connected it all of these ways, no? There's not a dice in there, rolling, and breaking the IC if it rolls a 6.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:14:48 am
content: Looks like the noninverting input (3) is connected to the ground side of the RC instead of the top side? Sure won't work right that way.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:16:25 am
content: What's the value of the R5 resistor?

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:17:46 am
content: That doesn't sound right, to me. The IC has two inputs and one output on each side, both work the same, as far as I know. And as far as I know, there isn't difference in the sides where the GND pin is and the Vcc pin is.

author: james_s
author_rank: Super Contributor
timestamp: October 22, 2019, 12:18:23 am
content: Quote from: renzoms on October 22, 2019, 12:13:30 amThere kind of is actually. Some ICs are very tolerant of abuse like having their outputs shorted to ground or supply rails, some can tolerate it for a while but may eventually fail, others will let the magic smoke out instantly if this happens. I don't recall seeing mention of the particular IC being used but it's still worth connecting it correctly in order to find out.Let us know what IC it is, also study the datasheet, make sure you understand how it works. It will say whether the output is open collector or not and it will list absolute maximum parameters.

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:20:04 am
content: It is a TLC372CP and someone told me The outputs are n-channel open-drain configuration

author: james_s
author_rank: Super Contributor
timestamp: October 22, 2019, 12:23:12 am
content: Search engines are your friend.https://www.ti.com/lit/gpn/tlc372Open-drain is the MOSFET equivalent to open collector, this means that the output can only pull in one direction, down toward ground. So you must connect the LED to +5V through a resistor, and connect the free end to the output of the comparator. When the comparator triggers, the output will become ground, prior to that it is floating (open circuit).

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:24:52 am
content: The LED is ON when I turn on the 5V power supply. When the capacitor is connected to 5V, it turns OFF.When the capacitor is discharging the LED remains off for ~4 seconds, and then turns back ON.(the opposite of what I want is happening)

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:26:59 am
content: Quote from: renzoms on October 22, 2019, 12:17:46 amThere is only one GND and one Vcc pin for the whole chip, powering both comparators. The inverting and noninverting inputs to the two comparators have nothing to do with the chip's power. You are using one comparator of the pair. Your schematic is correct but your breadboard is incorrectly wired because the noninverting input to the comparator you are using is grounded. It must be moved to the high side of the RC pair in order for it to see the voltage on the capacitor.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:28:02 am
content: Quote from: renzoms on October 22, 2019, 12:24:52 amIs that before or after you corrected the breadboard error?If after:So swap the connections to the inverting and noninverting inputs!!! Put the wire that goes to Pin 3 into Pin 2 instead, and the wire that goes to Pin 2 into Pin 3 instead.

author: james_s
author_rank: Super Contributor
timestamp: October 22, 2019, 12:28:10 am
content: Swap the + and - input pins of the comparator, this will reverse the action.It sounds like you do not really understand how a comparator works, it will save you time to grasp the basics from the beginning, study the datasheet, it contains all the information you need.

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:30:35 am
content: This is what I have. I believe it's correct.

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:33:47 am
content: Ok, well if you don't mind helping me here is what I think about this comparator. The + terminal is higher than the - terminal for 4 seconds => the output is "high" for 4s == the output is shorted to ground for 4s.So the output being at "high" for 4s in this case is open circuited? (because the LED is ON, then OFF for 4s, then ON after testing.)I've connected the + terminal at 4V at fully charged capacitor, and the - terminal at .1V.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:35:21 am
content: Quote from: james_s on October 22, 2019, 12:23:12 amThanks, I missed that. So option 1) in the top schematic won't work after all. But he's got the LED lighting up so he must have that part wired correctly anyhow as open drain. +4v rail > resistor > LED anode -- LED cathode > Pin 1 , right?

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:38:11 am
content: 5V rail > resistor > LED cathode - anode > Pin 1

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:40:47 am
content: Quote from: renzoms on October 22, 2019, 12:30:35 amYes, that's right.When the output goes HIGH, no current can flow because the LED+resistor are also at that same voltage (or the output is simply open). So the LED turns on when the output goes LOW. So you have to swap the inverting and noninverting inputs until you get the behaviour you are looking for. There are only two choices!

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 12:42:43 am
content: Quote from: renzoms on October 22, 2019, 12:38:11 amShouldn't the anode be on the + 5v side?

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 12:55:42 am
content: You are correct. I mixed up the names

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 01:02:17 am
content: Got it to work although the timing is not accurate. Not looking into it rn.If my + voltage is higher than my reference voltage at - then output at Pin 1 should be High, so for this n channel open drain output, that means??When the reference voltage, -, is higher than the voltage at the + terminal, the output at Pin 1 should be Low, so for this n channel open drain that means???

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 01:21:37 am
content: The timing is about over 4 seconds but it is calculated at 3.7s....

author: Audioguru again
author_rank: Regular Contributor
timestamp: October 22, 2019, 01:31:33 am
content: Quote from: renzoms on October 22, 2019, 12:38:11 amNo, you have the polarity of the LED connected backwards. The LED anode must have its current-limiting resistor connected to +5V and the LED cathode gets pulled to ground by the comparator output pin 1.

author: Audioguru again
author_rank: Regular Contributor
timestamp: October 22, 2019, 01:35:17 am
content: Quote from: alsetalokin4017 on October 22, 2019, 12:40:47 amNo, the output of this comparator never goes high, instead it floats disconnected or it goes low. The LED does not light when its cathode is disconnected from ground.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 01:45:39 am
content: Quote from: renzoms on October 22, 2019, 01:02:17 amIt means Pin 1 is floating when HIGH, that is, not connected to anything inside the chip. (you could connect it externally to bias it to some other level but for your application it is just disconnected.)QuoteIt means Pin 1 is connected to Ground inside the chip. Look at the "internal schematic" of the chip in the data sheet. When Pin 1 is LOW it is really low: grounded.Quote from: Audioguru again on October 22, 2019, 01:35:17 amYes, that is right. Although the two states of a digital output are called High and Low, in this case High means "not connected internally", while Low means "grounded". Sorry for my confusion, I wasn't looking at the right data sheet.I have the circuit working on my bench using 1/4 of a LM339 quad comparator with open collector output, otherwise with same values as the schematic in the OP.Since the capacitor is being charged through a 22 k resistor, it takes a finite time to charge fully. So the length of time the output LED is ON varies a bit, depending on how fully charged the cap was when you took your finger off the button.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 01:50:16 am
content: Quote from: renzoms on October 22, 2019, 01:21:37 amComponent tolerances, capacitor charge level. The actual value of a capacitor can be different from the nominal value. Ditto resistors.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2019, 01:53:19 am
content: If you need some more exact timing... and even just for fun and learning ... you could substitute a 50k potentiometer for the fixed voltage divider made of the 10k and 47k resistors.

author: renzoms
author_rank: Regular Contributor
timestamp: October 22, 2019, 02:16:40 am
content: Quote from: Audioguru again on October 22, 2019, 01:35:17 amThanks, easy to understand!Quote from: alsetalokin4017 on October 22, 2019, 01:45:39 amLol.Quote from: alsetalokin4017 on October 22, 2019, 01:50:16 amThanks that is comforting!Quote from: alsetalokin4017 on October 22, 2019, 01:53:19 amWill do tomorrow! Good idea! Sounds fun.