Hi! I'm trying to incorporate a soft latch switch circuit into an existing circuit such that when a button is pressed, the circuit is completed and powers on an ATtiny84 (and some other components), however, when pressed again, will disconnect the circuit, thus powering off the devices. I also want the ATtiny84 to disconnect the circuit after a certain duration. I've searched for a while and have found this circuit (not mine):
However, I'm not too sure if any modifications need to be made so that I can include it. And if so, what would I need to change; moreover, how might I be able to disconnect the circuit with the ATtiny84? I was thinking of sending out a HIGH signal to the conjunction consisting of the R4, R5, and R6 resistors but I'm not too sure if that's ideal.
Hi! Thanks for providing the circuit but is there a link to some article or video that explains this particular circuit (I'm a little rusty with the circuit stuff)? Moreover, does this circuit only work with MOSFETs rather than BJTs (the space I'm working with is somewhat cramped)? Thanks in advance! : )
pushing the button forced the gate of the P-fet to ground through the diode,
and turns the P-fet on, powering the Arduino.
enabling pull up on the pin in setup() sets the pin HIGH,
and turns the N-fet on, thus keeping the P-fet on.
pushing the button can be detected by the Arduino, which can then turn the fets off by making the pin an input. The Arduino can also do that on it's own.
The circuit is designed for fets, which can be smd.
Bjt would make the circuit more complicated.
Leo..
If you can live with 0.1-1 μA leakage current you can use the power down sleep of the ATtiny, having it switch off power to the rest of the circuitry. That'd be the simplest solution.
As has been shown, instead of the button directly powering down the circuit, it's easier to make the button as an input to the processor after power up. Then when it's pressed, the processor detects that, and then shuts down the power itself - just as it would after a time interval with no button press.
I haven't really thought it through, but this circuit might work using bipolar transistors:
Edit: No, the circuit below won't work. The GPIO would always read low, even when the button isn't pressed, because it will be about 0.6V. You would need to use two GPIO's, one as input, and one as output.
The base resistor of the PNP would depend on how much current you need to supply to the circuit, and the DC gain of the transistor. The 100R base resistor of the NPN isn't really needed, but is there as a safety measure in case the GPIO might ever be configured as OUTPUT, HIGH, which would cause a near-dead short. But it will have no effect on base current in series with an internal pullup of about 30K.
The disadvantage of the bipolar circuit is the combined base current of the two transistors while the circuit is powered up, as compared to the much smaller current drawn by the mosfets' pullup and pulldown resistors. And you will probably have more voltage drop across the PNP than you would have across a P-channel mosfet.
Hi! Thanks for the suggestion; however, this particular approach won't work since my program is written in a way in which it can't detect input every so often (unless I make my program work in parallel which just complicates things). Are there any alternatives that simply use BJTs like the circuit above? Many thanks! : )
EDIT: I just found out that Arduino has interrupts and I'm not sure if you guys were referring to that functionality on the Arduino but I'm definitely gonna check it out and see if it fits my needs! : )
That doesn't make sense. Almost all programs do things in parallel.
And reading a digital input only takes microseconds.
Time to share the full story with us.
Leo..
Hi! After some thought and a few more research, I have an idea of how I can make this work but I do have some questions. First, what's with this diode-looking symbol (I'm still relatively new to circuits so I do apologize for some of these basic confusions):
What type of PNP and NPN transistors would I need to use for this circuit, can any be used or does it depend on my application (5V 2A is powering my circuit)?
I noticed that the V+ (coming from the PNP) is connected to the Vin of the Arduino in your diagram, is it necessary to connect it here? I've heard some people that it's much better to use the 5V pin and just wanted to know whether or not this is ideal or so.
You mean my first circuit? I don't understand. The problem with my first circuit is that with the internal pullup resistor enabled, the NPN would be turned on, but at the GPIO pin the voltage would be the B/E drop - 0.6V or so. That would keep the power on, but there would be no way to detect that the button has been pressed - since the pin is already low without it being pressed.
Those diode-looking symbols indicate, uh, diodes. Something like a 1N4148.
The NPN could be almost anything, but a 2N3904 or 2N2222 should work fine. The PNP choice will depend on how much current your circuit will be drawing. What components will your circuit include?
If your incoming power is 5V, then yes, you would power an Arduino at its 5V pin. But if you're using a bare ATTiny84, that would just be 5V at the Vcc pin.
Got it, but is there a reason for them? I've seen various soft-latching circuits, and some don't seem to use diodes so I just want to know their purpose of them here. I assume it's just to make the current flow in one direction for protection or so?
I'm using 5V 2A which is coming out of a voltage regulator, the components consist of the following:
ATtiny84 (5V)
DFPlayer Mini (5V)
Microphone sound sensor (5V)
3V DC Motor (with a buck converter to lower the voltage to 3V)
I'll try out a 2N2222 since I've used some in past projects.
Oh yeah, you're right, haha, but I guess it's good to know in case I use an Uno or so in the future.
If you use PWM you don't need the buck converter for that motor.
A duty cycle of 3/5 = 60% is the equivalent of running it at 3V, with the potential advantage of better start-up torque for the motor. The current is limited by the inductance of the motor coil. You may need to set the PWM frequency to >20kHz to have no audible hum, though.
It is so that the constant HIGH from the output pin on the microprocessor being used to turn on the transistor, and thus the p-channel MOSFET does not appear as LOW at the input on the microprocessor.
This is so you can use the same pushbutton as an input. Ppl like to use it like a normal pushbutton after it serves as a power on signal.
A common trick is to use it normally, but watch for a long press and use that to initiate whatever you want to do before releasing the output line being used to maintain the power on condition.
I'm still a little confused about this, so is it used to isolate the latching effect? Moreover, based on the diagram, it appears that diodes are facing toward each other, so how is it that the Arduino is able to detect that the button is pushed if the diode (that comes from the input pin) is directed towards the button leg? Thanks in advance! : )
The input pin is internally pulled high by the INPUT_PULLUP pin mode. So it reads HIGH. When you press the button, it connects the cathodes of both diodes to ground, which
pulls the input line down, so it would read LOW
pulls the gate on the p-channel MOSFET down
except… the gate on the p-channel MOSFET is already being pulled down by the other transistor or MOSFET, so it makes no difference. The p-channel never knows and just continues to conduct and supply power.
When the circuit is off waiting to be turned on, it is the pushbutton signal that switches on the other transistor. Then immediately the processor places a HIGH on the base (or gate) of the other transistor, taking over for the pushbutton, which if the released will not matter, lower will,continue to flow.
Sry, that's alotta words. I guess it's so familiar to me it is hard to 'splain.
In essence the two diodes form a logic gate. Either input being LOW can make the output LOW.
An AND gate.
See
for some old old school logic circuitry. Still comes in handy.