What is the best button toggle circuit?

I have been looking for the best way to create a toggle circuit with a pushbutton.
I want to power an esp-cam and an oled that can draw up to 400 mA while operating normally at around 200 mA. I considered three options: using a mosfet, a two-transistor circuit, and a timer555.
The problem with a mosfet is that it still draws some current when turned off, and saving power is critical for my project. Timer555 can only pull up to 200 mA, so I am afraid it will not be enough. So, right now, I am thinking about using a two-transistor circuit, but it still feels a little too big because there are so many resistors, and I want to keep the circuit small. Perhaps a mosfet or something similar to the NDP6020 would be better? But, again, I do not want it to drain the battery while turned off. Or perhaps there are better options?
So, how would I go about making this circuit as small as possible (not on a PCB, but by soldering the components together) and drawing as little current as possible?

You could switch on the MCU and then use the pins to control the keep / switch off the circuit. Something like the circuits discussed in this thread:

The switch turns the MCU on. Then with GPIO2 you check when the button is pressed again and with GPIO1 you switch it off.
There are other variants in the thread. It shouldn't draw not much current when off.

It needs still a few components. To make it small the best is a PCB, it's very cheap and easy to do. Or pack everything very close in a perfboard, using also smd components.

How about something simple:
image
Replace the 9V battery with your power supply. SW1 will turn it on, the GPIO needs to be switched high to keep it on. Do that as one of the first things in setup().

FYI a MOSFET will have some leakage in the nano to pico amp range when off. They also do not require any current when turned on.

I once made this abomination:

It does work though, and it's nice and compact on a single-sided PCB:
image
The PCB is about 50x10mm.
You could replace the components with through-hole types and solder it together in whatever way you want; it'll work the same, but it'll be bigger of course.

I use this virtually daily to switch a USB-powered LED panel that doesn't have a power switch.

@gilshultz @anon27210439
I got my inspiration from this project: https://youtu.be/nbMfb0dIvYc?si=nL7QrRn5t62hD40m&t=261

The circuit below only uses one mosfet, and I was wondering if this was an option instead of using two as shown in your diagrams.
However, when I used it with the IRLZ44n, I encountered a few issues, such as it being in some strange way in between, providing only 1.5v even when the gate was pulled low.

Be wary of leakage currents. MOSFETs and diodes (including clamping diodes in IC's) aren't perfect binary devices. They have linear characteristics, too. I've ran into similar problems that traced down to tiny reverse leakage currents in BAT54 diodes combined with the high impedance of a MOSFET gate. In theory, the MOSFET shouldn't have switched on. In practice, it did, a little.

1 Like

That is an N channel mosfet, not suitable for your use, you need a P channel one, as the one showed in your cirecuit.

Ciao, Ale.

1 Like

You need to be careful when ordering the mosfet. There is an NDP6020, which is an N-channel mosfet, but the one you want is the NDP6020P, a P-channel mosfet. Which has been discontinued by the way.

Edit: The single-mosfet circuit you showed in post #5 won't work. GPIO pins have protection diodes, one of which connects the pin to Vcc. If too high voltage is applied to the pin, it is shunted to Vcc. But when power is off, Vcc will drift down to ground. That means you have the mosfet gate connected to ground through a diode, which will turn the mosfet back on, which is not what you want. Adding the second mosfet (or NPN transistor) means you have to apply a high voltage to turn on the main mosfet, which you can't do when the power is off.

1 Like

Hi,
I used a small relay to do something similar. The relay NO contact is in parallel with the "on" push-button (instead of an on/off switch). When the program starts, it's first job is to turn on the relay.
In my case, the relay was turned off after a minute with no activity.
RWK

1 Like

Expect weird results if you do not use the proper components. Your measurements are probably correct if the wrong parts were used. The two MOSFET circuit uses maybe a few nA when off. It will also give you the 3V3 you want for the processor.

Sorry, I do not know much about mosfets, so why is a N channel not suitable? For me, it makes sense because positive voltage would turn it on and ground would turn it off which is exactly what I want.

Which relay did you use? I want to keep a project as small as possible, so I was wondering if there were any tiny relays that would work for this.

Because to effectively use an N-channel MOSFET in this application, you'd have to lift the gate considerably above the supply voltage, necessitating an additional positive voltage rail, possibly generated using a boost converter. Evidently an inefficient approach.

You could search for "reed relay". However, I don't see how a relay would in any way be more convenient or superior to a MOSFET circuit here. Perhaps it's more intuitive. But electrically, it's no better and likely somewhat worse depending on how you look at it.

1 Like

Unfortunally, it's not so simple. What activate the mosfet is Vgs voltage, voltage between gate and source, and yes, N channel mosfet require this voltage to be positive, so higher than the one present on source. No problem when the source is on GND, as is usually used (low side switch).
The best circuit to use is the one in post #2, or at least the one in post #3, if you don't need to reuse the button. Relay can be used, but i'll require power to stay on (mosfet does not), and this can be a problem if you use a battery. If you have space problem, consider using a double mosfet, like IRF7319, so you can have both N and P channel mosfet in a small footprint.

Ciao, Ale.

1 Like

Hi,

The relay is a 5V Omron G5V-2, 2CO contacts (image). It can fit on a standard 16-pin DIP socket.
On my circuit (not Arduino), it's driven by an NPN transistor, whose base connects to an output of the processor.
You should check the relay's characteristics, to see if it can be driven direct from an Arduino output.

HTH

Richard

This is a good option to keep it small. You could put that IC on a SOP-8 adapter like this:
image

And with just a couple of resistors more you would have the circuit of post #3.
You could even solder some of the resistors directly on the adapter, depending on the pins. Or an adapter with more pins and smd resistors, everything on it.

1 Like

Why not buy a toggle push button.
Uses Zero current when off

1 Like

I was looking at those, but I also wanted the ability to turn off an esp from the code, as well as reusing the button as a gpio input.

Thank you for the explanation, so here is a quick sketch I did:

I tried to copy the circuit from post #2, but just to be sure decided to post it here.

@zhekich
Is the battery voltage 3.7V?
If yes, it won't work