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'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?
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.
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.
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.