Need a simple current / draw detector to turn LED on - Page 1
Forum section: electronics / beginners

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 13, 2022, 07:05:42 am
content: I have a 9V battery and a 5V LDO going to an 8mA load. I would like a simple circuit to turn an LED on when the draw over a sense resistor at the LDO output is over 4mA. I’m only going to make a few of these on a 2 layer circuit board.But I’ve been having trouble with the comparator circuit reliably going down to a 4mA load detection.Any circuit pointers or examples to help me get started?

author: EPAIII
author_rank: Super Contributor
timestamp: September 13, 2022, 09:51:57 am
content: You don't say weather your sense resistor is in the high side or the ground side. Generally speaking most ICs will need around 0.7 V difference from one or the other of those two rails in order to detect the current. From Ohm's law, 0.004A (4 mA) and 0.7 V means a 175 Ohm resistor. I would try at least 200 Ohms to start. So, what size resistor are you using?But some more details on what you have tried and why would be helpful.Just a thought, but a Hall effect sensor may be a better route. For one thing, they are isolated so you don't need to worry about the Voltage levels as much. Here are some sensitive ones:https://www.mouser.com/c/sensors/magnetic-sensors/board-mount-hall-effect-magnetic-sensors/?operating%20point%20min%2Fmax=0.1%20mT%20to%201.5%20mT~~0.15%20mT%20to%200.65%20mT&rp=sensors%2Fmagnetic-sensors%2Fboard-mount-hall-effect-magnetic-sensors%7C~Operating%20Point%20Min%2FMaxnote: Sorry about the incorrect link. Too many open tabs. This is the one I meant.Each of them has a link to a datasheet which gives information about their use.Even though they are very sensitive, you are probably going to need to place them in a coil with multiple turns to build up the magnetic field to a usable level. There are magnetic field calculators on the web that make this somewhat easy.https://duckduckgo.com/?t=ffab&q=magnetic+field+in+coil+calculator&ia=web

author: Ian.M
author_rank: Super Contributor
timestamp: September 13, 2022, 10:21:40 am
content: Quote from: EPAIII on September 13, 2022, 09:51:57 amErrr.... either you fat-fingered that first link or have been smoking/eating/drinking the *really* good stuff, as Hex standoffs from McMaster-Carr have little to do with the topic!Also, there is absolutely no reason you cant sense down to a few tens of mV drop across the sense resistor or current shunt. Heck, I can do that with discretes! You only need 0.7V drop if you are using the shunt to produce Vbe for a simple BJT, which is about the cr@ppiest way to sense current as the threshold will vary with both temperature and load on the sensing BJT's collector.Given a dual OAMP that's common mode input range includes the rail the shunt is in, its as simple as using one half to amplify the voltage across the shunt to get several volts swing between min. and max. current, and the other as a comparator against a stabilized variable reference voltage (e.g. from a pot between a well regulated rail and ground) to set the detection threshold.

author: Terry Bites
author_rank: Super Contributor
timestamp: September 13, 2022, 10:33:17 am
content: A INA381A or similar all in one low cost solution.Compare price with the cost of an opamp and comparator etc.

author: magic
author_rank: Super Contributor
timestamp: September 13, 2022, 10:52:47 am
content: Simple? Well, yes.150~180Ω between battery positive and the LDO input.PNP emitter-base junction in parallel with the resistor. Current will start flowing here once about 4mA is exceeded by the LDO input and resistor voltage reaches 0.7V.To the PNP collector, connect your LED and a current limiting resistor down to ground.Problem solvedBut as Ian.M said, it's not super accurate and becomes more sensitive at higher temperature (or less when cold). You may see it turn on gradually as the threshold is approached and exceeded.Quote from: NaDobraNich on September 13, 2022, 07:05:42 amThere are thousands of different comparators with different requirements and different quirks and thousands of ways to screw up even a simplest circuit. You really need to post details of what you tried if you want help with that.

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 13, 2022, 09:10:37 pm
content: I didn’t mention high or low side. Either, doesn’t matter at all.As to a BJT and a .7V threshold, I mostly understand this, but not entirely. Mostly the way I would put a series resistor before the LDO.As to temp, it doesn’t matter. I have a 9V battery and am making more or less a test light for a special circuit. I’ll make a few and use them in a heated shop. As long as I could be sure the LED comes on over 4mA nothing else much matters.I like the INA381A part. That makes sense and it what I was trying to get with a single op amp. I think it would be looking at the 200 gain version and a moderate series resistor. But I also would need to read more on the datasheet. I do not yet understand if it would be better to sense at the 9V or at the 5V LDO or what resistors I would need.So I think I could use more information on the BJT while I look up the 381.

author: ledtester
author_rank: Super Contributor
timestamp: September 13, 2022, 09:52:00 pm
content: Quote from: NaDobraNich on September 13, 2022, 09:10:37 pmConsider this circuit:The LDR represents your load and R1 is your sense resistor.When the current through the load is larger than about 0.7V/R1 the transistor will start to turn on and thus turn on the LED.For a 4 mA threshold you would choose R1 = 0.7V/4mA = 175 ohms.0.7V is a general value for bipolar transistors -- it might a little different for the transistor you decide to use. Also, as mentioned above, this value can change with temperature.This is an example of low-side sensing. For high-side sensing you would use a PNP transistor.Another consideration to bear in mind is that this approach can reduce the supply voltage to your load by up to 0.7V. That is, if your power supply is 9V the question is whether your circuit will work with a supply of 8.3V. Other schemes can impose a much smaller "burden voltage" on your circuit.Update:I've read your first post more carefully, and since you are using a linear regulator you could do this high-side sensing circuit:Current into the regulator is basically the same as output current from the regulator, and this way you don't have to worry about the burden voltage.

author: Benta
author_rank: Super Contributor
timestamp: September 13, 2022, 10:00:07 pm
content: Can you be certain that the max. load of the LDO is 8 mA (or at east less than 20 mA)?And how precise does the trigger point need to be?

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 13, 2022, 10:58:35 pm
content: LedTester, I’ll check that out. Thanks a ton, I already understand a little more looking at that. I have more experience with mosfets than BJT, but I’m at least getting the idea.Benta: No, I can’t guarantee. But I’ve never seen this circuit pull over 8mA, in theory if something was broken I suppose it could pull about 60mA worst case for a short time. Not precise at all. This is merely an indication light that the circuit is in contact, just for a human to see a green light. So anything over 4mA should do it. Technically o suppose over 1mA would work. 8mA is the nominal draw.

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 14, 2022, 05:55:15 am
content: Quote from: ledtester on September 13, 2022, 09:52:00 pmOk, I did the math on the values and it looks like ignoring LDO dropout, the most my LDO can possibly pull before the 9V is tapped out is 51mA. This is great, I will never need that.But I have a theory issue understanding what is going on here.- a PNP because I’m pulling or what a negative reference compared to the emitter.- the .7V is when the BJT will conduct or deplete or turn on or whatever you want to say- the 175ohm * 4mA is a .7V drop. I need that .7 difference to sink into the LDO and pull on the PNP base1. So is the idea that I have a PNP emitter that has 9V, and the LDO is pulling 8.3 now? Causing .7V difference between them on the base, which will turn it on? The more I draw, the more the difference will be?2. Does the LDO have 9V available in the high side PNP scenario? I still had to make at least .7V difference at 4mA with the 175 resistor. But once the resistor is conducting then am I making that .7 back from the PNP sink? Do I get to “add it back in” like that?3. What happens when I draw more than 50-some mA? I’ll be near a 9V difference. So what does my LDO “see” for voltage then? If the LDO is partially supplied by the PNP I get it, otherwise IDK.

author: magic
author_rank: Super Contributor
timestamp: September 14, 2022, 06:29:21 am
content: The point of putting the resistor before rather than after the LDO is that voltage dropped across the resistor doesn't get subtracted from the 5V seen by the load. It also means that LDO's internal current consumption is counted together with load current, but it's hopefully less than 1mA so not a big deal.The emitter-base junction of a PNP is simply an ordinary PN diode plus small internal parasitic resistance (mainly on the base side). Common 2N2907/PN2907 transistor is guaranteed to have less than 1.3V voltage drop with 15mA pulled from the base, so the LDO would see more than 7.7V when drawing 22mA (additional 7mA coming through the resistor). I think with 8mA you are likely to see more than 8V, so still some headroom is left for battery discharge.If the LDO is really low dropout and you care about current efficiency, a red or green LED (1.8V drop) could be simply installed in series with the LDO. An additional parallel resistor of 470Ω would allow the first 4mA to bypass the LED before it lights up. But this will stop working once the battery discharges to some 7V, while the PNP thing could work down to 6V with a good LDO maybe.That being said, a 9V battery at 7V is pretty much dead anyway, unless it's the 6 cell NiMH variant or 2 cell Li-ion. What sort of battery is going to power this circuit?

author: EPAIII
author_rank: Super Contributor
timestamp: September 14, 2022, 10:09:47 am
content: Thanks for pointing out the problem with the link. I have corrected it.The OP asked for a simple circuit and had apparently tried some with sensing resistors already. I was trying to point out where that MAY have gone wrong and suggest something else. Besides, his question was up for a while with zero answers so I gave it a shot. I and I am sure he/she are both grateful for your help. Always more than one way to skin a cat.Quote from: Ian.M on September 13, 2022, 10:21:40 am

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 14, 2022, 03:59:53 pm
content: Ah. Ok, I’m dumb but am coming around.The LDO is fed with the PNP body diode. But, there is a voltage shortage, which is made up through the resistor. So I don’t need to size the resistor for the whole load, just the .7V and ??mA or so that will be replacing the loss from the diode.Although I’m still a little unsure of what happens at a 50mA draw. I think maybe nothing special? At some point I assume I lose too much through the resistor to make up for the .7V PNP loss?I’m planning on using a store bought alkaline typical 9V. The button on this device will be pressed I’m guessing 2000 thousand of times, but only for .25-.5 seconds each time. At that 8mA draw. So, IDK, .278aH, and a fresh battery can do .600 or so? I’m not taking the drop on voltage into account, but I’m not sure it matters too much, I think by the time the LDO dropout is close the battery should be done?

author: ledtester
author_rank: Super Contributor
timestamp: September 14, 2022, 05:14:16 pm
content: The voltage across the emitter-base junction of the PNP is essentially limited to 0.7V.This means the current through the sense resistor is limited to 4mA. At 50 mA, 4mA will go through the resistor and 46mA through the emitter-base junction.However, this is just a first approximation. Here is a simulation of the circuit in ltspice with a 2n3906:The current sink is programmed to sink T milliamps at time T milliseconds.As you can see, the current through the resistor (blue trace) continues to rise but at a slower rate. At 50ms the split is about 10mA to 40mA.

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 14, 2022, 09:36:42 pm
content: I tried to simulate this and for the life of me I can’t seem to get it to not power the LED. I tried a current sink instead of a resistive load, same results.Any ideas on what I’m almost certainly goofing up?(I realize the picture is probsbly showing as expected, but as I lower the current at R3/load, the diode always has 8-9mA depending on which part I have selected)

author: Benta
author_rank: Super Contributor
timestamp: September 14, 2022, 09:45:45 pm
content: You need to select the right LDO, like LM2936.The 7805 will pull 5...10 mA all by itself. I think @ledtester just used it as a placeholder for a quick schematic.You need to do a bit of work yourself, don't expect ready-for-production designs.

author: ledtester
author_rank: Super Contributor
timestamp: September 14, 2022, 11:31:50 pm
content: Here's a Falstad simulation using a LM317:https://tinyurl.com/2mypfo3k(also attached the .txt file for this circuit below)You can adjust the load using the slider on the right ("Resistance").The LM317 itself draws 5.4mA so I made the sense resistor only 50R. The LED will turn on when the pot is set to around 500R or less.

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 15, 2022, 04:08:33 am
content: Ha, that’s something that would have taken me a long time to realize. The LDO takes current, yep, I get it.Thanks everyone!

author: Benta
author_rank: Super Contributor
timestamp: September 15, 2022, 10:06:14 am
content: Which is why I suggested LM2936.

author: magic
author_rank: Super Contributor
timestamp: September 16, 2022, 07:19:23 am
content: Quote from: NaDobraNich on September 14, 2022, 03:59:53 pmMost current flows through the base and the base may go 1~2V below battery voltage mainly due to internal resistance of the transistor. But it doesn't matter what happens because as far as we know, it can only occur when the powered circuit is damaged somehow.Quote from: NaDobraNich on September 14, 2022, 03:59:53 pmThat's between 500 and 1000 seconds of operation, so 4000~8000mAs, or about 1~2mAh. More than the capacity of a 9V alkaline battery.This is a very useful site for everything having to do with batteries:https://lygte-info.dk/review/batteries9V/Common9Vcomparator.phpIt appears that I was wrong, and you actually gain 20% battery life by discharging down to 6V rather than 7V. It's not clear how much is gained from going further to 5.2V or whatever the LDO minimum would be.7805 (or LM317) is not an LDO (low dropout) regulator. It requires the input to be at least 7V or so. LDO means low input-output difference.And 7805 is quite a power hog, indeed.

author: Vovk_Z
author_rank: Super Contributor
timestamp: September 16, 2022, 02:17:27 pm
content: If there isn't accuracy requirements and there is some voltage headroom, why you can't use just a 470-1000 R shunt resistor and a bright LED (with some R) in parallel to this shunt?

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 17, 2022, 01:49:48 am
content: Quote from: Vovk_Z on September 16, 2022, 02:17:27 pmI don’t quite understand what you mean. Can you circuit sim or otherwise draw it?Remember I need the LDO no matter what for 5V.

author: magic
author_rank: Super Contributor
timestamp: September 17, 2022, 04:28:22 am
content: This has been suggested before, but it stops working when the battery is at ~7V.Simply connect the 5V regulator's input to the battery through an LED.Add 470Ω in parallel with the LED so that 4mA flows through the resistor before 2V develops across the LED and lights it up.The LED should be red or green, blue has too much forward voltage drop (about 3V).It should be easier to test IRL than to simulate

author: NaDobraNich
author_rank: Regular Contributor
timestamp: September 18, 2022, 04:05:01 pm
content: Oh, duh obviously. Just changing the body diode for a led. I get it.PNPs are cheap. But yea practically speaking it might be all the same since the 9V is more or less dead at 7V and the voltage should crash around there anyhow.I’m not sure if it’s wrong, but it has helped me understand the circuit by considering the resistor sort of a pull-up.