I have a portable project where I want to take care about batteries getting discharged.

Usually I just put a switch at the very beginning of my circuit that completely cuts off the electricity when switched off. The problem with this approach is that if you forget to switch it off your batteries will discharge.

So I was thinking about an approach that after some inactivity time cuts off the circuit (I want to completely cut off the electricity to minimize power consumption, so I'm not interested in sleeping modes or similar approaches).

So my approach consist in changing a switch for a regular push button that enables the circuit when pushed, and then one of the arduino pins is used to lock the transistor until a function times out and the pin gets to a low voltage (see image)

In the arduino code I can just test a simple program that keeps the circuit closed for 10 seconds and then switches it off.

setup() {

loop() {

For the transistor part I'm not sure what to use. I was thinking about using an motor driver L298 (which should work and also accepts some load for other electronics that I might have in the project)

However this looks like something that should already exist (either in a shield or maybe integrated in some Arduino variant).

Does anybody have experience with such an approach or a suggestion on any standalone transistor that would also do the job?

Any help is appreciated :)

.enter image description here

  • Search "transistor latch circuits" for a lot of articles about them including how-to. From there you can decide whether to build or buy.
    – JRobert
    Mar 9, 2017 at 12:41
  • from the look of it, most n-chan mosfets would work as expected. i would add a diode to the left "rail"
    – dandavis
    Mar 9, 2017 at 21:08

2 Answers 2


Here is a mock-up of what I usually do.


simulate this circuit – Schematic created using CircuitLab

Keep in mind that the resistors are just an example value: you'll have to make some calculations.

Now, M1 is a PMOS, while M2 is an NMOS. Both MOSFETs should be able to turn on and off with the voltages you can supply them (so look at their Vgs curves). Moreover the M1 mos will be the one where all the supply current will run, so you'll have to choose it wisely. The M2 mos will only have to supply a small current, so the smallest one is fine. Beware that if the Vin voltage is greater than the maximum Vgs voltage of M1 you'll have to add a resistor between M1 gate and M2 drain to form a voltage divider with R1.

The R4 and D1 are used if you want to detect a SW1 push (for instance to turn off the device). If you don't need this feature, remove them both.

The circuit works this way: when you push the button, a voltage (for instance 5V - 0.6V of D1) will come to the arduino Vcc. The arduino then should immediately bring up the pin. This will turn on M2, which in turn switches on the M1 transistor, thus bypassing the switch. When you remove it, the arduino stays powered.

When the arduino decides that it should turn off (either because you pressed the button again, or because it timed out, or who knows) it executes two instructions: one to pull down the pin and the other is while(1). This prevents it to continue executing the program. The M2 transistor shuts down, the M1 gate floats to Vin and so it shuts down too.

You can find the transistor as discrete componetns (sometimes also in the same SOIC-8 package. Usually I use big pMOS (e.g. IRF9310 in SOIC8) and smaller nMOS (usually in SOT-23 case). I do this because I can easily solder them also on perfboards (SOIC8 single transistors have a lot of redundancy for pins, while SOT-23 ones can be mounted easily on 3 pads).


If you would like an out-of-the-box solution, the Pololu Pushbutton Power Switch is a lovely piece of hardware that lets the device turn itself off :)

Update: Adafruit also released a "Low Power Timer Breakout" that allows a device to be turned on automatically from 1s-2hr intervals, and then disable the power supply from the device once each run is done.

If you need less often than 2 hr intervals, you could increment a number in EEPROM in setup() each run and immediately re-enter sleep if the number doesn't match your desired value.

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.