Use a 2N 3904 Transistor to switch 12v with MCU?

Thread Starter

haukeg

Joined Dec 9, 2018
66
Hi, I am putting together a simple circuit to turn a fan on from an ESP8266 NodeMCU. I am providing 12v DC to a Buck Converter to drop to 5v for the MCU, but was hoping to have a simple gate for the 12v to fan using a 2N 3904 Transistor. Originally I was considering a Relay in place of the 2N 3904 Transistor, but felt like that was overkill at 12v? Any advice appreciate, thanks.
IMG_7920.JPG
 

Attachments

SamR

Joined Mar 19, 2019
1,825
Not sure what this is for but a few ideas. 5V voltage divider instead of the expense of a buck converter. 470kΩ sounds a bit high (5V/470kΩ is only 2.4 uA) and I would have the fan on the collector side of the xstr. YMMV
 

Thread Starter

haukeg

Joined Dec 9, 2018
66
Thanks @SamR - good idea on the divider over buck, suppose I was thinking efficiency but assume at 12v->5v might not burn off a ton of energy? Also, what amperage would you be targeting for the base on the Transistor? Thanks for the pointer on the collector side.
 

djsfantasi

Joined Apr 11, 2010
6,171
A 2N3904 is an NPN transistor and used commonly to switch the low side of a load. The emitter goes to ground, the collector goes to the negative side of the load. And the base is connected to the MCU signal with an appropriate base resistor calculated for the current drawn by the load.
Rb=(Vb-0.6)/(0.1xIfan)​
 

Thread Starter

haukeg

Joined Dec 9, 2018
66
One other consideration is voltage ripple, ESP’s can be temperamental with fluctuating voltage (one reason I though buck). Suppose a 7805 voltage regulator and some caps would work as well but again efficiency (and might need a heat sink).
 

djsfantasi

Joined Apr 11, 2010
6,171
One other consideration is voltage ripple, ESP’s can be temperamental with fluctuating voltage (one reason I though buck). Suppose a 7805 voltage regulator and some caps would work as well but again efficiency (and might need a heat sink).
You’re worrying about temperature caused ripple when nothing in the circuit will work even if you had ripple-free power?
 

Thread Starter

haukeg

Joined Dec 9, 2018
66
Not sure I follow - if you’re assuming I’m saying I have to have no ripple, I don’t I just want to keep it to a minimum. Also not sure what you meant with “temperature cause ripple?” Thanks.
 

djsfantasi

Joined Apr 11, 2010
6,171
Not sure I follow - if you’re assuming I’m saying I have to have no ripple, I don’t I just want to keep it to a minimum. Also not sure what you meant with “temperature cause ripple?” Thanks.
i am saying that your circuit will not work at all, so worrying about ripple is a waste of energy.

Look at post #4 for how your circuit must be wired.
 

SamR

Joined Mar 19, 2019
1,825
I was wondering about the ESP possibly needing a regulator and that is an easy one that should not need cap filtering. The regulator does the smoothing. IF the load is actually only100mA you may not need a heatsink.
 

djsfantasi

Joined Apr 11, 2010
6,171
I was wondering about the ESP possibly needing a regulator and that is an easy one that should not need cap filtering. The regulator does the smoothing. IF the load is actually only100mA you may not need a heatsink.
Good advise. I am not familiar with the ESP and the μC I use have the regulator built-in.

Assuming he gets the power situation resolved, the rest of the circuit won’t work. It would be better if he switches the fan on the low side with the 2N3904. Or chooses a PNP transistor to switch the high side and solves the problems inherent in that circuit.
 

Thread Starter

haukeg

Joined Dec 9, 2018
66
Ok, thanks for the tips. So I think I learned something I didn’t know before - use a PNP for switching high side and NPN for low end? Will take a look at the MOSFET options as well.
 

SamR

Joined Mar 19, 2019
1,825
The 2N3904 is a good general-purpose NPN BJT xstr @ 40V & 200mA but the 2N2222A is 40V & 800mA and is ~$1/100. The 2N7000 N channel MOSFET turns on with logic level voltage and can switch 60V & 500mA and costs ~$3/100. Good cheap general-purpose switching TO-92 cased transistors to have around. Not sure what the load is for the ESP but the TO-92 cased 78L05 5V regulator is good for 100mA and ~$1/100. A nice logic level 5V regulator to have handy and also comes in SOT-23 for surface mount.
 
what amperage would you be targeting for the base on the Transistor?
Simply read the datasheet for the 2N3904 or for any other transistor.
You want the transistor to be a saturated switch.
The datasheet shows how well it saturates when its base current is 0.1 times its collector current. So the base current should be 10mA. What is the output voltage of the ESP8266 when its output current is 10mA?

Then the base resistor value is the output voltage of the ESP66 minus the 0.9V base-emitter of the transistor (shown on a graph on the datasheet) divided by 10mA.
 
That chip runs on 3.3 volts...not 5, so make sure it has the onboard 3.3 regulator if you plan to power it with 5 volts.

Voltage dividers are not used to power devices...choose a 7805 TO220 regulator, your micro will thank you for it, considering it will have *enough to deal with driving a motor. (*RFI and other noise)

Do not use high side switching with a PNP the ESP8266 GPIO pins will not handle 5 volts let alone 11.7!

I would go with a 222 or 2N7000 instead of the 904.

The chip can sink or source 12mA on its GPIOs. (but you should check the data sheet of your exact model) So you need to calculate the base drive based on 3.3 not 5. (but again...check the data sheet)

And don't forget that emf suppression on the motor.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
5,213
A 2N3904 is an NPN transistor and used commonly to switch the low side of a load. The emitter goes to ground, the collector goes to the negative side of the load. And the base is connected to the MCU signal with an appropriate base resistor calculated for the current drawn by the load.
Rb=(Vb-0.6)/(0.1xIfan)​
This is what I would suggest as well. Try an MPSA13 darlington to simplify the base drive requirement.
 
Top