How do I keep the arduino turned on "in software"?

My goal is to make a circuit that would power on with a push button, and then stay on until some task is complete. I came up with this design using a BJT:

The idea is that the arduino/attiny would set HIGH its pin 2 which would keep the transistor conducting. Then after some time setting LOW pin 2 would turn off everything, until somebody pushes the button and turns on everything again.

Except that it doesn't work... as soon as the button is released everything powers off.

I found this old discussion on the same subject, which has a solution, but using one or two MOSFETs: [SOLVED] Turn on Uno by hardware (button), turn off by software (via MOSFET) - Microcontrollers - Arduino Forum

I'd prefer to avoid MOSFETs for the moment in favour of BJTs. But anyway, I fail to understand why the first diagram does not work. Can somebody shed some light?

Except that it doesn't work..

No, well it is the wrong circuit.

You need a PNP transistor and you need a resistor in the base circuit.

Why would you not just use "sleep" on the Tiny?

I probably could use sleep, but I think it could be simpler to handle that hardware side (without having to write interrupts, disable timers, etc) and anyway, I'm interested in understanding why this isn't working.

Also I don't understand why I should be using a PNP... can you expand? Wouldn't a PNP basically keep current flowing forever unless actively stopped (consuming power)?

Using "sleep" makes a lot more sense - the whole point of microcontrollers is to simplify the hardware.

A PNP alone will not work either (will it, Mike?) - you need a PNP on the positive side to do the switching and an NPN on the negative to control it. But then you waste current in the base drive to the PNP.

And in any case you are losing at least a little voltage in the transistor - why would you want to lose efficiency?

You can use just a PNP because the supply is the same as the output voltage of the micro. You have to take the base higher than 0.7V of the supply voltage to the chip which you do with a pair of resistors.

I don't follow.

Diagram?

There are always these... that basically do what you want.

Simple PNP-NPN circuit should do it also.

Only need one transistor. While the maximum output from the ATtiny will be 5 - 0.75 = 4.25V then the potential divider circuit will keep the PNP transistor off.

Power Hold.jpg

What if the battery is 6V, or 9V? Parasititic leakage thru the input clamp diode may power the device and/or break it with excess voltage,, or break the diodes.

CrossRoads:
Simple PNP-NPN circuit should do it also.

hum... you put 5V on Emitter-Base of the PNP one when you close S1 , and almost 5V as long as NPN is "ON" -
I'm not sure it will last very long :wink:

Course, my original design has no safeguard against excess voltage the PNP if the load was a '328P or similar chip by itself.

If the NPN is On ,the PNP base is pulled low, 0.5V to 0.7V.

FYI
Dave's stuff is interesting.
This is not exactly what is requested but could be modified.

.

Course, my original design has no safeguard against excess voltage the PNP if the load was a '328P or similar chip by itself.

If the NPN is On ,the PNP base is pulled low, 0.5V to 0.7V.

That's not about that.... there is no resistor to limit the base current of the PNP transistor, it will likely blow very quickly

Ok, missed that. Hate creating stuff in powerpoint.

:wink:

What if the battery is 6V, or 9V?

But it isn't going off the OP's schematic. The design is a working version of the original circuit.

Can't tell what the original battery voltage is, perhaps 3 or 4.5V.

CrossRoads:
Can't tell what the original battery voltage is, perhaps 3 or 4.5V.

You don't have to know, it is driving an ATtiny so it can't be over 5.5V.