transistor output drive led and 5v pin together - Page 1
Forum section: electronics / beginners

author: cosminnci
author_rank: Regular Contributor
timestamp: January 28, 2014, 10:06:10 am
content: I use an LM741 as a photoresistor comparator and the output goes in an port expander, the way the led and the resistor are connected output voltage on high is 2.6v instead of 5v.normally I need it to pull low the pin and that is ok but does this 2.6v output when high affect the expander wich has a pullup to 5v?regards,Cosmin

author: zapta
author_rank: Super Contributor
timestamp: January 28, 2014, 08:01:19 pm
content: Schema?

author: cosminnci
author_rank: Regular Contributor
timestamp: January 30, 2014, 07:03:04 am
content: I uploaded the schema, forgot to attach it first time

author: papo
author_rank: Regular Contributor
timestamp: January 31, 2014, 12:43:26 pm
content: HelloSomething is weird with your circuit. To turn on the transistor, you need a base-emitter voltage of at least 0.7 V or so do drive it out of cutoff. I'm wondering how you manage to do that since even with 5 V at the OpAmp output you'll have something like 0.45 V at the center of the R6-R13-divider.This assumes infinite input impedance of the BJT (which it does not have, of course) and the ability of the 741 to hit the positive rail, which it can't do either. Violating these assumptions worsen the problem, though.So how is it possible to pull the output pin low? Is this a simulation or did you build this up? In any case, it looks like you are operating the circuit at the bare boundaries of what the components can do. I would consider replacing the OpAmp with something that can go closer to the rail, maybe a real comparator.Considering the expander problem, do you mean that the expander is open-drain and that a resistor ensures a high state when the input is floating? If so, that resistor would be in parallel with the LED and R1. I don't see a problem with that but I would investigate the 2.6 V issue.RegardsMatt

author: cosminnci
author_rank: Regular Contributor
timestamp: January 31, 2014, 02:20:08 pm
content: Hello,thank you MattI tested several values, one that works is R6 = 5k6 and R13 = 1k2I use this with a photoresistor and a mcp23017 powered at 5 v with pullup enabled.when c1_out is not conected to the mcp it has 2.6V when I connect it to the mcp it has 5V (the mcp`s pullup)maybe calculating a propper voltager divider could solve the 2.6V issue?regards,Cosmin

author: papo
author_rank: Regular Contributor
timestamp: January 31, 2014, 04:14:42 pm
content: Quote from: cosminnci on January 31, 2014, 02:20:08 pmAh so with the 10k and 1k you have in your original schematic, it does not work? Just to clarify... since my initial guess was that this should not work. The updated values rise the level closer to the threshold voltage of the transistor but it's still pretty low.Quote from: cosminnci on January 31, 2014, 02:20:08 pmSo just to clarify even more, this is when the OpAmp output is low and the LED is off, right? You don't have any problems turning on that LED?Quote from: cosminnci on January 31, 2014, 02:20:08 pmYes but to do that, you have to know the output voltage of the OpAmp. The problem is that this is difficult to figure out; An ideal OpAmp can have any output voltage between whatever you supply to it. In your case that is between 0 V and 5 V. But a real OpAmp does not work like that. A real OpAmp needs some "head room" between the supply rails and the output voltage. Maybe your output voltage is constrained to the range of 1 V to 4 V or even worse. Not only does this depend on the OpAmp, but also on the load you are attaching to the output.That is unless you go for a rail to rail OpAmp, and even then, whether you can get close to the rail still depends on that load current. If you had an OpAmp that could go to 0.2 V and up to 3 V or whatever, you wouldn't even need that divider. At 0.2 V, your transistor is off and at 3 V, you can turn it on hard. You would still need a base resistor and maybe a pull-down but that's another story.That said, the 2.6 V could be just due to leakage. The LED is off when you measure the 2.6 V, right? Reading 5 V when you have the expander in place points towards that direction. Anyway, does it work the way it should? If so and it's not drawing excess current anywhere (which I don't see how it could) you're fine I guess. Personally though I would not feel comfortable as there is the possibility that this works because you are on the edge of some parameters, so I would investigate this further to make sure that this is rock solid also when temperature changes etc.Just out of curiosity, it would be interesting to measure the OpAmp output voltage and the base voltage of the transistor, both when the transistor is on and when it's off.HTH, regardsMatt

author: valentinc
author_rank: Regular Contributor
timestamp: February 01, 2014, 02:28:38 pm
content: I just quickly tried this circuit on a breadboard and works just fine... The output of the comparator goes very close to the supply rails (40-50mV below 5V and above 0V)...I also tried the same circuit with a TL072 op-amp, and had the same problem you had... The HIGH output was something around 3.5V and the LOW output around 1.4V...The comparator needs a pull-up resistor (R4) because the output is an open-collector configuration. Also note that because of this, the output of the comparator can only sink current, so only a PNP transistor can be used...In my opinion, you could use a better op-amp (which would get closer to the supply rails), but that would be more expensive than a simple comparator...

author: papo
author_rank: Regular Contributor
timestamp: February 01, 2014, 03:12:12 pm
content: Quote from: valentinc on February 01, 2014, 02:28:38 pmYep, that's what I meant. Looks much nicer than the original one. I would put a base resistor there, otherwise you are relying on the sinking capabilities of the comparator (or lack thereof, rather) to prevent excess currents. And within limits, you could still use an npn I think.RegardsMatt

author: papo
author_rank: Regular Contributor
timestamp: February 01, 2014, 03:28:07 pm
content: Actually, this will not work with the expander in place because your emitter does not go down to ground due to the collector resistor. I'm sorry for having missed that. How about something like the attached schematic?RegardsMattEdit: Of course you'd have to make sure to size the two resistors according to the current requirement through the diode, the 10k are just to get an impression. And this is assuming the open collector comparator as suggested by valentinc.

author: papo
author_rank: Regular Contributor
timestamp: February 01, 2014, 03:38:17 pm
content: Or even simpler, get rid of the base resistor and size open-collector pullup accordingly. If you use an NPN you can do that, as there is no base current when the comparator outputs low.

author: cosminnci
author_rank: Regular Contributor
timestamp: February 03, 2014, 12:21:32 pm
content: Hi Matt, Valentinthe transistor base voltage is 0.6v led on and 0.3v led offthe op amp output is 4.25v led on and 1.41 led offyes the 2.6v is when the led is off so it is current flowing trough the led and the resistor.what if I would drive the mcp directly from the opamp output? the voltage looks right but I need it fliped.regards,Cosmin

author: papo
author_rank: Regular Contributor
timestamp: February 03, 2014, 04:35:06 pm
content: HelloQuote from: cosminnci on February 03, 2014, 12:21:32 pmI tried to determine the base current but I think you are down to measurement noise here. That said, for sure your base current is very low.Quote from: cosminnci on February 03, 2014, 12:21:32 pmI'm really suspecting leakage here. Also, note that when you measure the collector voltage, you might pull down the collector a little bit with your meter.Quote from: cosminnci on February 03, 2014, 12:21:32 pmWould the mcp recognize the 1.41 volts as low? A brief look at the datasheet suggests this would not be the case (input low voltage = 0.2Vdd). Also I saw that you can disable the pullup if that's a concern for you. Can't you just invert the bit in software? In any case, you would run into exactly the same issues if you try to do the inversion with a BJT.Really, I would decide how reliable you want this to be. If it just works for you and you are not concerned about temperature effects and the circuit not working anylonger if you swap out the transistor or the OpAmp for a different device of the same model, go with what you have. My understanding is that it works fine at least when the 100k pullup in the MCP is on.If you are not happy with the circuit, investigate the comparator alternative.HTH, regardsMatt

author: cosminnci
author_rank: Regular Contributor
timestamp: February 04, 2014, 07:13:50 am
content: Hi Matt,yes it works fine, I inverted the state in the MCP and fed the opamp output into the mcp, this works ok too.I`m happy how it works for now.Thank you.regards,Cosmin

author: cosminnci
author_rank: Regular Contributor
timestamp: February 19, 2014, 12:56:27 pm
content: I have tested little more extensively the circuit and has some flaws.could someone recommend an circuit for detecting light from a photo resistor, and outputting ttl logic level for microcontroller.regards,Cosmin

author: papo
author_rank: Regular Contributor
timestamp: February 19, 2014, 01:15:29 pm
content: HiQuote from: cosminnci on February 19, 2014, 12:56:27 pmCan you tell us about the flaws? Because I used a similar circuit before and it wasn't that bad. The problem I was addressing though was to detect a specific light source and my measurement was affected by ambient light. So I ended up with pulsing the light source and adding a bandgap to the receiver but I don't have the impression that this is what you are trying to achieve.If you just want TTL, I don't see why the first half of the circuit (potentiometer, voltage divider with a fixed resistor/trimmer and the LDR, comparator) shouldn't do the job.RegardsMatt

author: cosminnci
author_rank: Regular Contributor
timestamp: February 20, 2014, 06:48:27 am
content: the project is an laser barrier wich is read by an mcp23017 and then a arduino.the laser does a good job and ambient light is not a problem, and the setup works at slow speed, but when I pass faster it skips somme.I boosted the i2c speed to 400Khz and still have these random misses.I believe maybe because the out is only 2.6v in High level and the mcp pullup pulls till 5v maybe the rise time could be a problem.but I would like to build a new version that works, input from photo resistor and output ttl level.regards,Cosmin