Electronic – How to switch power of microcontroller by button

microcontrollerswitches

I have a microcontroller device with battery power. Currently I toggle power by simple on/off switch. I want to toggle power by one pushbutton with minimal modification of the schematic (and microcontroller program probably) and with no consumption when device is off. How can I do it?

ADDED. I know following trick:

enter image description here

Here at start microcontroller sets PB3 to high and thus hold power for device. But this is not a solution for my problem, because I need also to off the device by pressing S1.

ADDED. Can I exclude VT2 from circuit (i.e. microcontroller drive base of VT1 directly)?

Best Answer

Based on the circuit you provide, you could just add a diode in series right after the switch (S1) (cathode connected to the switch) and them you could use an input to detect if the switch was pressed again, if so, turn off PB3.
Modification required

The zener diode protects the PIC input from the voltage coming from the power supply.