MMBT3904 NPN Transistor Circuit Help Needed - Page 1
Forum section: electronics / beginners

author: 2XL
author_rank: Newbie
timestamp: February 14, 2024, 02:50:21 am
content: Hi. I'm using the attached circuit that a friend designed for me years ago. The tag "micro_pin_in" is going to an ESP32 GPIO input pin. J4 is connected to a current sensing relay and closes when there is current detected.I more or less understand how Q2 works ( Collector Current = Base Current * Beta), and how R2, R4, and R8 work in the circuit to set the currents. I *think* R6 is there to pull down the base when J4 is open, thus giving a solid pulldown so that the micro pin is guaranteed to see 3.3v when j4 is open.My questions:1. What is the purpose if R10? Do I really even need it?2. If I need it, could I change R10 from 10K to 12K with no real impact to the function of the circuit? I think that would just mean that the micro pin would get a little less current, but would that still be enough to drive the ESP input pin?Thank you!

author: ArdWar
author_rank: Frequent Contributor
timestamp: February 14, 2024, 03:39:58 am
content: Quote from: 2XL on February 14, 2024, 02:50:21 amMCU I/O pin protection, at best.It also protect the MCU if you inadvertently program the pin as digital output. Some MCU I/O also behave unexpectedly under brownout condition.Quote from: 2XL on February 14, 2024, 02:50:21 amNot reallyQuote from: 2XL on February 14, 2024, 02:50:21 amR10 value isn't critical at all. In fact none of the resistors are critical. You can pick any (reasonable) value for all of those resistors. Just make sure that R6 / (R2+R4) divider is enough to turn on the BJT, and R8 to be large enough not to outright short your 3V3Quote from: 2XL on February 14, 2024, 02:50:21 amYes, but no need to worry too much about it. Modern logic circuits have very low input bias current in the order of nanoamps (i.e. tens of megaohm input impedance at worst).There are of course some additional consideration for analog signals or high speed signals or maybe noisy environment immunity. But for low speed digital signal it isn't that demanding. Just don't put something like a megaohms there.

author: Terry Bites
author_rank: Super Contributor
timestamp: February 15, 2024, 09:24:05 am
content: First off you don't need the transistor at all. Use the relay contact to pull the io line to ground. The series resistor and diodes protect the io from over and reverse voltages. If you have a long line to the relay add a bit of RFI protection as shown. Check that the wetting current through the relay is adequate to keep the contacts clean. That's 3.3/R1 . One mA or so is usually enough for a small relay.I think R10 isn't necessary and its and if realy needed it's value isn't critical either. The micro input will have protection diodes on chip. These diodes will only handle a small fault current. Often 10-20mA as an absolute maximum. So long as R10 is large enough to keep within the ic's limits it'll be ok. If the 3V3 comes from the micro you only need to protect the transistor from adverse voltages on the relay lines. A Zener at the base will keep the nastys at bay.As it is, you could increase R4 and R6 to 100k and it will would work fine. This transistor has a minimum current gain of 80 @1mA so there would be more than enough base current to switch a 10k pull-up. Unless you buy junk grade fake MMBT3904's it would work reliably with a pull-up as low as 1k. A simple rearangement of components simplfies the circuit. The suggested configuration has better noise immunity will switch more quickly than the original circuit. With this open collector circuit you'd need a very unlikely chain of failures on the relay side to damage the micro.

author: Ian.M
author_rank: Super Contributor
timestamp: February 15, 2024, 10:27:38 am
content: R10 protects the input if the programmer is an idiot! If you accidentally set the pin as an output it prevents Q2 shorting it to ground. Whether or not any part of the circuit is necessary vs two input resistors (or a potential divider and an input resistor) + clamping between the resistors to prevent the input going (much) outside the rails is a different matter.

author: magic
author_rank: Super Contributor
timestamp: February 15, 2024, 05:40:01 pm
content: You could remove R6 and make all others 12k or whatever you like (though maybe not less than 1k).