I have built the circuit as shown below. The goal is to power the Arduino by battery and maximise battery life by turning off power when it is not in use. There is no need for the Arduino to wake up periodically or anything like that. The only "wakeup" will be when the switch is closed.

The idea is that an external action (pressing S1) will power up the Arduino. The Arduino will do whatever it needs to do (e.g. report the action) and then power off.

The powering up of the Arduino on press of S1 works just fine.

The first thing that the Arduino will do is to raise D2 high. This also seems to work fine as the LED1 lights up.

However, when I release S1, power is immediately cutoff.

My expectation is that since D2 is high, this will keep the transistor (T2) turned on until such time as the Arduino "does whatever it needs to do" before taking D2 low.

For the purposes of testing, I rapidly blink the inbuilt LED for 3 seconds before taking D2 low. this achieves three things:

  1. I know that the Arduino has "booted up" and that D2 is HIGH (I can also see this on LED1)
  2. The rapid blinking shows me that the Arduino is powered up (which is useful to observe the failure case of D2 going low but for some reason this fails to cause the Arduino to power off).
  3. Gives me time to hold hold S2 closed long enough for the Arduino to "boot up" and allow me sufficient time to release S2 before the 3 second operation (rapid blinking of the builtin LED) completed.

However, as mentioned above the instant I release the switch S2, the Arduino's power is immediately cutoff.

I have tried removing the LED1 - to "force" all power from D2 through the transistor, but this does not seem to change anything.

Following is the circuit diagram. The purpose of the diode (D1) is to protect the Arduino's digital pins from the 9V, but allow the Arduino's D2 signal out to control the transistor. The capacitor C1 is intended to provide a bit of debounce for the switch.

After the circuit diagram is the test program.

Obviously I have no idea why this doesn't work. So my question is why does this not allow the Arduino to take control of it's power supply via the transistor and it's digital output on Pin 2 (with or without LED1)?

Arduino self controlling power supply circuit

Here is the test program. The comments should clarify the intention of the main parts of the program:


void setup() {
  // put your setup code here, to run once:

  digitalWrite(POWER_CONTROL_PIN, HIGH);      // Turn on the transistor to maintain the power flow.

  while (!Serial) {
  Serial.println("Arduino Controlled power switch - Ready");

// Rapidly blink the inbuilt LED to show that the Arduino is "alive"
void blinkLED(int duration) {
  digitalWrite(LED_BUILTIN, HIGH);
  delay (duration);
  digitalWrite(LED_BUILTIN, LOW);
  delay (duration);

void loop() {

  Serial.println("Operations mode - rapid blink");
  for (int i = 0; i < 10; i++) {

  Serial.println("Shutting down mode");
  digitalWrite(LED_BUILTIN, HIGH);            // Signal that we are about to shutdown by holding the inbuilt LED on for two seconds.
  delay (2000);
  digitalWrite(POWER_CONTROL_PIN, LOW);       // Turn off the transistor to terminate power flow.

  digitalWrite(LED_BUILTIN, LOW);             // We should never get here ('cos the power has been turned off), but just in case,
  delay (250);                                // repeat the rapid led blinking to show that we are still "alive".
  • 1
    \$\begingroup\$ Why not use the low-power sleep mode built into the Arduino library? You can wake on button press, do whatever you need to do, then go back to sleep. \$\endgroup\$
    – Ron Beyer
    Commented Mar 11, 2020 at 0:52
  • \$\begingroup\$ Mostly because I want to try to get this idea to work. But also because the low power sleep mode, from what I read, is not so low power in an Arduino. As I understand it, sleep mode only puts the Microcontroller to sleep. The USB controller and power regulator are still operating and consuming power. \$\endgroup\$
    – GMc
    Commented Mar 11, 2020 at 1:08
  • 1
    \$\begingroup\$ You need to use a PNP transistor (or P-MOS) to do high side switching. The voltage on the base is 0.6 volts higher than the emitter and the diode has the same voltage drop. In order for this circuit to work, the Arduino would need to output 1.4 volts higher than the supply. \$\endgroup\$
    – Oskar Skog
    Commented Aug 29, 2020 at 7:23

1 Answer 1


Update 24-March-2020. This circuit only works by luck. There is a better solution in my follow up question: Why does a bipolar transistor not work, but a MOSFET does

After much considered work (a.k.a. randomly trying stuff until it works), I've worked out that if I replace the transistor with a MOSFET I can achieve the desired result.

Following is the modified circuit. FWIW, the diode in the question diagram is incorrect, it is actually a 1N914 that I am using. So although the first diagram is not strictly correct, the only component I have changed is the transistor for the MOSFET.

Also, FWIW, I've triple checked the connection for the MOSFET.

Pin 1 (Gate) is connected to R1 Pin 2 (Drain) is connected to VCC Pin 3 (Source) is connected to VIN (Arduino)

I would have expected that Pin 2 and 3 should be reversed, but if I try that (i.e. 2->VIN and 3->VCC) then the Arduino is permanently on. I will post a separate question asking about why this circuit works but the transistor one does not.

Revised circuit with MOSFET in place of transistor

  • 1
    \$\begingroup\$ As it turns out, the above circuit only works by luck. For a better solution, have a look at my follow up question: Why does a bipolar transistor not work, but a MOSFET does \$\endgroup\$
    – GMc
    Commented Mar 24, 2020 at 1:41
  • \$\begingroup\$ Changing the capacitor to a 2.2uF Electrolytic capacitor will ensure the circuit always remains ON. To turn off the circuit, add another NMOS to the circuit whose collector is connected to the gate to IRF 540, and the source of this MOS is connected to the ground. Control this MOS from any of the digital pins. \$\endgroup\$ Commented May 9, 2021 at 8:26
  • \$\begingroup\$ This cannot work properly. The voltage delivered by diode D1 is never above Arduino VIN and so Q1 cannot stay on this way. The button discharges C1 and this keeps Q1 conducting. If port D2 is set to LOW the reverse leakage current of the diode probably can slowly charge C1 to turn Q1 off. \$\endgroup\$
    – Jens
    Commented Jan 20 at 2:28

Your Answer

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

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