Instructables
Picture of Soft Latch Power Switch (Ardweeny)
softLatchCircuit.png
Today I wanted to upload a design I created for a soft latch power switch.  It was used to power a Solarbotics Ardweeny, though you could use it for just about any microcontroller.  If your microcontroller requires something other than +5V input, you may need to change the linear voltage regulator used, but the rest of the circuit should work fine.  Everything here was powered from a single +9V battery.

For those who do not know what a soft latch power switch is, it allows a single button to perform three tasks - power on the microcontroller, act as an input to the microcontroller, and power off the microcontroller.  Additionally, the soft latch power switch allows the microcontroller to power itself off.  This is excellent for situations where a user may not power the device off, but you need to conserve battery.  If no input is received within a desired amount of time, the microcontroller simply powers itself down.

For this project you will need:
- 9V battery
- 9V battery leads
- P-Channel MOSFET (PN: STP12PF06)
- NPN Transistor (PN: 2N3904TFR)
- 2x Rectifier Diode (PN: 1N4002)
- 5V Linear Voltage Regulator (PN: L7805ABV)
- Momentary Switch
- 3x 100k resistors
- 0.10 uf Capacitor (PN: UKL1H0R1KDDANA)
- 0.33 uf Capacitor (PN: UKL1HR33KDDANA)
- Microcontroller (Arduino)
- Proto-board

Construction:  Connect everything on your proto-board as shown in the schematic.  Note that 'A0' and 'D0' connect to the microcontroller, as well as the +5V and ground (on the right of the schematic).  If desired, the +9V output on the top right can be connected to any additional circuits required.  Otherwise, only connect it to the voltage regulator.

Operation:  When the power is off and the switch is pressed, the P-FET is activated and +9V is supplied to the linear voltage regulator.  The regulator then supplies +5V to the microcontroller and it will turn on.  It is important that your software immediately sets pin 'A0' to a high output.  If done properly, the voltage on this pin will activate the NPN transistor and latch the power circuit on.  While powered on, the pin 'D0' can be setup and used as an input.  In my prototype, when the switch is momentarily pressed, the system responds by playing a beep.  If the switch is held down for at least 2 seconds, the microcontroller plays a longer beep and sets pin 'A0' to a low output.  This will release the latch, and the microcontroller will be powered off when the switch is released.  If the switch is not pressed for 30 seconds, the microcontroller will automatically shut down.

Below you will find a video of my prototype and some Arduino code.  In the video, everything is attached to a protoboard and you can see how it works.  As shown in the picture, however, it can all be soldered to a more permanent board in a nice and compact form.  I didn't have a lot of space in the device I put this in, so it worked out perfect.  The code provided should get you pretty well started.  Enjoy!
neskandari4 months ago

why do you need the diodes

You need the diodes for Arduino to be able to read the Button state.

Without the diodes it will read low when the button is not pressed because of the npn pulling low and it will read low again when the button is pressed so there will be no state change.

Thats what D2 is for. It will separate the Mosfet pulled low from the button. but why is is there a D1? It seems to be just incresing the input to the uC by 0.7V

greenrider3 months ago

The first 100K pullup will draw current in the off state via D0-->Arduino-->GND.

It can be easily fixed by connecting the 100K pullup to any point after the P-FET.

Maybe even to a 5v rail of the Arduino.

Overall a nice, simple circuit that works and has low parts count.

achand87 months ago

Can any P mosfet Be used? Anything to consider while choosing the mosfet? Like the Vgs?

https://www.sparkfun.com/products/12901 is a very low Vgs mosfet. It is a good choice if you are trying to make a low power device.

amidar7 months ago

Just wandering,how much this circuit draws in off state ?

jp_boardrides (author) 9 months ago

Both N-fets and P-fets should work fine, though you will need to change the circuit around a bit to ensure the correct voltages are applied to the gate.

Robo-T9 months ago

I have been trying to find a simple soft latch power switch for a while. Your build seems to fit the build, but I don't a P-MOSFET. Is it possible to use a PNP instead?

rveer110 months ago
Great ! I'm usign that in my next project. I'm not too sure about sending D0 as an input to my arduino, since the pullup is tied to 9v,better drop the pullup and let the internal pullup do the work.
Nice one - thanks for sharing.