Switching on a secondary MCU with an Arduino (transistor selection)

Perhaps off-topic… but I wanted to draw on the HW experience of the community!

I want to use an Arduino to drive 2 devices, switching them both on simultaneously, to later do some timing measurements. The measured devices (RP2040 mcu) will draw max ~100mA in total at 5V.

I’m planning on adding a resistor (100K?) and transistor (/MOSFET?) to a GPIO pin. (The only related thread was for driving a rumble motor).


  • What common transistor will give me the fastest switching? (Anything in microseconds?)
  • Is there anything else to be wary of?

Cheers :smiley:

You can use either a bipolar transistor or a MOSFET.

Will the Arduino (the GPIO output voltage) be 5V or 3.3V? If it’s a 3.3V Arduino you will likely need a “logic level” MOSFET, with a low gate threshold voltage. Otherwise, most MOSFETs will switch on with a 5V gate voltage.

If you want a through-hole MOSFET, the 2N7000 is common. It should handle 100mA and has turn on times in the low nanosecond range. However, it may not work well with a 3.3V gate voltage.

Common through-hole bipolar transistors are the 2N2222A or 2N3904.

Microsecond switching times are not fast for a transistor.

The above transistors switch the low side (ground) of the device they’re controlling. Make sure that is acceptable for you.

1 Like

Thanks for your guidance.
I was overthinking and worrying based on some bad web info (forums mentioning ms switching times!)… I should have just read some datasheets :slight_smile:

I’m using an old Arduino Leonardo (Spec: digital i/o pins operates at 5V, maximum 40 mA in/out).

Current choice 2N7000 MOSFET:

  • 7-10ns switch on, 200-300mA supply. Gate Threshold 3.0V max (for saturation - handles ~20V)
  • A gate protection resistor is not required and slows switching (device acts like a capacitor; virtually no current). Can use 50– 220Ω if paranoid.
  • Some horror stories of being very ESD sensitive! Note: handle with care and buy from a reputable source.

(More info ~ long video here, nice blog on properties here).

2N2222 BJT: 30ns switch on, max 150 mA, Gate Base Threshold max 10V.
2N3904 BJT: 35ns switch on, max 200 mA, Gate Base Threshold max 60V(?).
(The later two I may already have kicking about… so will possibly use).

1 Like

A BJT (Bipolar Junction Transistor) doesn’t have a gate. They are controlled by the base. BJTs are current amplifiers (not voltage as a FET is). To saturate one (switch it fully on) you have to feed at least enough current into the base, proportional to the gain (Hfe).

For instance, the 2N2222A can have a gain as low as 35 in some instances. To have 100mA flow from collector to emitter, you would need to put 100mA÷35=2.86mA into the base. However, to be safe it’s better to have a fair bit more than that, so maybe 5mA.

If the base is being driven by an output at a fixed voltage you need to put a resistor in series with the base to limit the current to what’s desired (5mA). To calculate the resistor value, you subtract the base-emitter saturation voltage (Vbe(sat)) from the input voltage then use ohms law. Maximum Vbe(sat) is 1.2V and the output of a GPIO might be 4.5V, so
This is worst case, so you may end up feeding up to about 7mA but this is not a problem other than wasting some power.

To decide whether to use a MOSFET or a BJT you have to consider:

  • The collector-emitter saturation voltage (Vce(sat)) of a BJT versus the drain-source on resistance (Rds(on)) of a MOSFET for how it affects the actual voltage that the load receives and the power that the transistor has to dissipate.
  • The “wasted” power that the GPIO pin has to provide to the base for a BJT versus essentially no power for the gate of a MOSFET. (Note that you have to make sure that the GPIO is actually capable of providing the required base current.)
1 Like

Thanks for these clarifying points. Appreciate it :+1:

1 Like

In general if you also want to connect gpio between the main controller and a slave controller you generally don’t want to switch the sub with a low side transistor as the gpio can leak enough current to do weird things like partially power the second chip even when the transistor is off unless you are careful to set all io to high impedance (inputs with pullups disabled). It’s good practice to either switch the supply rail and have everything common ground or just pull the sub chip to reset if the reset quiescent current is acceptable.

Thanks @sjm4306.

Presumably not an issue with a voltage ‘switched’ device like the 2N7000?

Intuitively it does feel wrong switching the ground… but I’m planning common +5V (from USB) and a transistor on the secondary mcu’s ground (also common). Surely an open circuit is an open circuit? :person_shrugging:

That’s a neat idea! I need to check whether the board breaks out some reset for the RP2040…? Also need to consider how it will affect the peripherals on the unit :thinking:

The issue has nothing to do with the switching device, it’s leakage current basically backflowing though connected gpio pins depending on configuration to the second chip’s power pin inside the chip. So you have to be careful when designing what connects to the slave chip to cut off any leakage current sources.

Sometimes, just like I said you’ll have to analyze exactly how you want to connect everything in your circuit. If you have a rough schematic or block diagram that’d help to spot any potential issues early on. Sorry if my suggestions sound kinda cryptic, but without knowing more about what you intend to do I can’t really say anything specific other than general design tips.

Sorry for the crudity of the model, I didn’t have the time to paint it or draw to scale (jk). Anyway this situation is what I’m talking about, it’s possible to intend to turn off the slave chip but if you forget to make sure all other gpio pins connected to the slave don’t have current paths to ground then the rp2040 could not be fully off, could be still powered enough, or in some other weird state besides totally off.

Thanks for taking the time to illustrate the problem. I see; makes sense. I can imagine also have a floating ground between devices may not be good.

To take your point about the GPIO pins to the extreme, I’d need to electrically isolate between the Arduino input pins and 2x RP2040 devices’ output pins. Something like an optoisolator… just seems like overkill…?

What exactly will be your setup? Are any gpio connected between the main chip and the rp2040 besides the one controlling the low side transistor? Is the rp2040 connected to anything else? If so, how/in which configuration? Depending on the answers to these questions this may not require anything at all, may require software workarounds, or additional hardware.

1 Like

If the master (Leonardo) that’s controlling power to the slave (RP2040) is only used to power it on and off then there’s no problem.

If the master has other inputs or outputs connected to the slave to monitor or control the slave then you just have to be a little careful.

Any pins on the master that connect to the slave should be set as inputs (without the pullup enabled) while the slave is powered down. After the slave has been powered up by the master, you then set the pins as required. Before powering down the slave, the pins on the master should again be set as inputs.

Another thing you can do, if you’re just sending digital signals back and/or forth, is put a fairly high value resistor between each output and corresponding input. Because the inputs themselves have a high impedance, the inline resistor shouldn’t affect the signals but will protect any inputs from excessive current. If you use a 100kohm resistor, the maximum current that could be forced into a pin (at 5V) would be 50μA, which is highly unlikely to cause any damage.

One thing you should consider is that the Leonardo’s GPIO outputs will be 5V, whereas the RP2040 operates at 3.3V and its inputs can’t tolerate anything above that. Therefore, any output on the master that is to be received on an input on the slave should have appropriate 5V to 3.3V level shifting circuitry.

1 Like

However, because the Leonardo will power up with all GPIO pins configured as inputs, thus one won’t drive the gate of a MOSFET until reconfigured as an output, it’s a good idea to put a pulldown resistor between the gate and ground to make sure the MOSFET is turned of when the GPIO pin controlling it is an input.

The resistor can be quite high; 100kohm or even up to 1Mohm should work.

1 Like

@MLXXXp @sjm4306 - thanks for all the feedback. May be a little while before I can dig in to this.