

- ARDUINO USING PN2222 TRANSISTOR AS A SWITCH DRIVER
- ARDUINO USING PN2222 TRANSISTOR AS A SWITCH SERIES
This is easy to build on a breadboard, and is a good starting point for learning how both MOSfets and BJT's behave in your circuit.
ARDUINO USING PN2222 TRANSISTOR AS A SWITCH SERIES
a 1k potentiometer between 0V and 3V3, with a series resistor from the wiper. As an experiment, replace your uC with a potentiometer.

For beginners, I advise to do both, and then measure the differences between them, and learn from it how the MOSfet and BJT's behave. If you have a BJT, with an Hfe of 100 (which is still quite modest) then a 2mA base current is enough to drive a relay which needs 124mA and will saturate the transistor, and then the Collector-Emittor voltage will be at 200mV or lower. BJT's are current driven, and thus also need a resistor between the uC and the base of the BJT. A lot of MOSfets simply need more then 3V3 to open them. With a MOSfet you have to design in the Ugs. An added disadvantage of MOSfets is their sensitivity to ESD, especially when working with breadboards or before it is soldered on a PCB. With a MOS fet it's also generally advised to use a resistor between it, and the uC, just as precaution so the FET does not kill the uC too if it ever gets damaged. MOS fet's generally need a pulldown to GND to prevent floating, for example during reset of the uC, and some have floating outputs in this state. Both an NPN and PNP transistor is also not needed, unless you have some imporant reason for wanting to switch the 24V rails instead of the GND rails. It really does not matter much for this application whether you use a MOSfet, a BJT or even a darlington. It can improve the turn-off time, if the circuit is driven from a signle ended input, but in this case the MCU output has a push-pull output, which will connect R2 to 0V, when it's low. I B = 0.003A V = 3.3V V B = 0.7V R2 = (V-V B)/I B = (3.3-0.7)/0.003 = 2.6/0.008 = 866 2⁄ 3 Ω 820R is the nearest E12 value, but even if you increased it to 1k, nearest E3 value, the lower base current wouldn't be a problem: 2.6mA will still turn it on hard enough, to power the relay. I'd aim for a base current of around 3mA, or so. In reality, it won't drop 1V, more like 0.1V. The relay is powered off 24V, so 1V of voltage drop won't be a big deal and the data sheet gives the worst case. The BC337 has a minimum gain of 100, at 100mA and 60 at 300mA, when the voltage drop across the collector and emitter is only 1V. Your MCU would have to output 12.5mA, in this case, but I consider that to be excessive. The general rule of thumb is select R B so I B = I C/10. Use the plain old BC337, in the option A circuit. Why did you select the BD139 and BD140? They're way overkill.

If you choose or need to use a mosfet, a good non-smd part is the FQP30N06L and a schematic would be:
ARDUINO USING PN2222 TRANSISTOR AS A SWITCH DRIVER
R4 not really required but 10K will keep any stray noise from possibly causing turn on when the driver pin floats, that is when neither high or low. Closest 5% value would be 180 ohms, 1%, 200 ohms. To solve for R1: 3W / 24V = 0.125 amps relay coil current 0.125 * 10% = 0.0125A Q1 base current If your drive voltage is 3.3V, subtract 0.7 for the base to emitter voltage drop. Resistor values are easy to calculate with ohms law once you know that to operate as as a switch, you want about 10% of the collector current to flow in the base. While current gain occurs, it’s not linear, it is operating as a switch and you always want the transistor to saturate, otherwise it will burn up if allowed to operate in its linear region as an amplifier. It inverts the signal, provides no benefit and just adds cost and complexity. If you do have an AVR processor running at 3.3 volts, here is an answer to the question in you post: A: R1 = 200 ohm (180 ohm okay too), R4 not critical at 10K. A mosfet is voltage controlled, not current and while it needs a bit of current at turn on, once on, it need virtually no current to remain on. Why? Because you need about 10 milliamperes to drive a bipolar transistor for that relay. Since your saying it’s 3.3 volts, it’s probably an ARM based part so there you’ll need to use a Mosfet. But, if you have anything other than an AVR based processor, you will typically not have enough pin output current to drive your specific load. Transistors will work with the typical AtMega328 based Uno, Nano and Mega.
