I am running an ESP32 microcontroller with a Co2 sensor, a real time clock (RTC), and an SD card reader. I will be putting the microcontroller into deep sleep and waking it every hour. I want to switch off the power to the aforementioned components before the microcontroller goes into deep sleep and turn the components back on after the microcontroller wakes up. Can I use 1 BJT npn transistor to switch off power to all three components? I was also thinking of using three transistors with a common base signal... i.e. using just one GPIO pin to control three transistors. Thanks

enter image description here

  • \$\begingroup\$ Yes you can but it's a lot better to put a large FET in the positive supply rail and keep GND permanently connected. You also need to think about the loading of the devices on your still-powered I/O interfacing to these when the FET's off. \$\endgroup\$
    – TonyM
    Jul 7, 2019 at 12:10
  • 1
    \$\begingroup\$ YES If these sleeping loads are not interfaced to active devices at 0V and not using CMOS Otherwise NO, use PFET \$\endgroup\$ Jul 7, 2019 at 12:11
  • 1
    \$\begingroup\$ A 2N2222 isn't the best choice of transistor for this. I'd suggest a FET. \$\endgroup\$
    – Hearth
    Jul 7, 2019 at 13:18

1 Answer 1


As long as you don't ever need to turn one of them on while another remains off, this will work. However, be aware that the 2N2222 has a saturation voltage that may be high enough to cause problems if you want to interface these with un-switched devices. Because of that saturation voltage, "ground" for your switched devices will be about 100~300mV higher than your circuit ground, and this will be reflected in their output voltages and may cause problems if they get an input voltage of circuit ground (which to them is negative).

Also note that your 2N2222 will dissipate a significant amount of power if your switched peripherals draw too much current. Given what those peripherals are, it's unlikely that this will be a problem, but it's good to be aware of that anyway.

To overcome both of these problems, the following circuit can be used instead:


simulate this circuit – Schematic created using CircuitLab

The use of a FET instead of a BJT eliminates the problem of saturation voltage, as FETs act like (low-value) resistors when turned on. Switching the high side instead of the low side ensures that the switched components still share a ground with all the other things in the circuit, too.

Note: make sure that M1 is a logic-level FET. Some FETs require substantial drive voltages that you don't have available, but logic-level FETs work on just 5V logic.

Note 2: Since it's a PFET, the logic will be inverted. Apply 5V to its gate to turn off the devices, and apply 0V to turn them on.

Note 3: 3.3V is not enough to turn it fully off, so if you use 3.3V signals you should use a simple gate drive circuit. You may want a gate drive anyway, to help it turn on and off quickly and reliably without demanding too much current from the MCU's output.

  • \$\begingroup\$ He may also want to use a level shifter (gate driver) to be sure to properly turn the PFET off. This is absolutely necessary if the uC is powered by a different VDD, but I'd do it in any case (for high-side switches) \$\endgroup\$
    – michi7x7
    Jul 7, 2019 at 13:51
  • \$\begingroup\$ @michi7x7 I did note that in note 2, but it does fit a bit better as its own note, so it's note 3 now. \$\endgroup\$
    – Hearth
    Jul 7, 2019 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.