I've made a simple measurement circuit and I wanted to make it work like that:

  1. user pushes a simple tactile switch and device turns on
  2. user can push the same button to measure again (and keep the turn off counter up)
  3. device turns off automatically by switching the whole circuit down

The MCU's power consumption is not the problem. there are a lot of other stuff and I wanted to turn the whole circuit off at once so the sleep modes are not considered here. here's the schematic I've used which seems to be problematic:


simulate this circuit – Schematic created using CircuitLab

The problem is, that the device turns on instantly, and stays on even when the output IO is pushed Hi. I read a value of about 4.3V on the gate of the mosfet. when I short the 47K resistor, the device turns off as expected so it seems the mosfet does not turn off completely. I've tried these values with no luck:

  • Changing R4 to 10K
  • Changing the diode to a 470R resistor. in this case device turns on and off rapidly
  • lowering R1 to 10K.

What is the problem? is it possible to make it work without adding another component?

thanx for the time and knowledge.

  • 3
    \$\begingroup\$ When the micro has no power, it will sink current into its GPIO pin - which has the same effect as closing SW1. Instead of connecting the GPIO directly to SW1, try using a NPN or NMOS driven by the GPIO and placed across the switch. \$\endgroup\$
    – brhans
    Aug 16, 2021 at 21:14
  • 1
    \$\begingroup\$ Do mind the drain to source leakage current when choosing a mosfet. \$\endgroup\$
    – dandavis
    Aug 16, 2021 at 23:42
  • \$\begingroup\$ Depending on "the circuit" it might be a strong pulldown, forming a voltage divider circuit+R4 vs R2. What is the idea behind R2? I would remove it completely. \$\endgroup\$
    – Sim Son
    Aug 17, 2021 at 1:22

1 Answer 1


When your device turns off, you still have a leakage path between the GPIOs and 5V IN. You need to block that somehow. Unfortunately it’s going to take some additional parts to do that.

Try this (simulate it here):

enter image description here

The additional nFETs isolate the CPU from leakage current when the power is off, while allowing the switch to be monitored when the power is on.

Here's how it works:

  • To power the system on, the user presses the power key. Q2 turns on, turning on Q1 and thus the power
  • user releases power key, gate pull-up Q4 gate latches the power on
  • Power key state monitored by Q3
  • After timeout, MCU powers the system down by pulling Q4 gate low

Maybe with some cleverness this could be simplified. Bear in mind that FETs are cheap, and this setup draws practically zero standby current.

MORE: Here's a version that uses bipolar transistors instead of nFETS (simulate it here):

enter image description here

The BJT's leak less than the nFETs so the off-state draw is reduced. Otherwise the principle of operation is the same.

  • \$\begingroup\$ Yes I simulated it and it seems the most robust approach. there is 1 mosfet for push-button turning on the main PMOS, one mosfet for push-button commanding MCU and one mosfet for MCU commanding the main PMOS. can I sue BJTs instead of these 3 mosfets? \$\endgroup\$ Aug 17, 2021 at 19:29
  • \$\begingroup\$ Yes, and I'll add this to my answer. It actually performs a bit better in terms of leakage. \$\endgroup\$ Aug 17, 2021 at 19:50
  • \$\begingroup\$ Hi. there is a problem, which happens when the MCU supply has a decoupling capacitor. this cap should be placed near it, but when the MCU powers the mosfet off with an IO, decoupling cap keeps the Q4 on and thus, the PMOS on and MCU stays on. any suggestions on that? simulation \$\endgroup\$ Sep 21, 2021 at 8:32
  • \$\begingroup\$ I added a diode in series with PMOS drain to prevent bulk cap discharging into Q4. but it didn't help. \$\endgroup\$ Sep 27, 2021 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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