push button switch for powering Arduino or ESP8266

I was thinking of making a quick push button wifi board. Push a button, it turns on, sends a message over wifi and shuts off completely. No power loss in sleep mode.

My idea is the push button connects GND to Arduino or ESP8266. Then in the arduino code during the setup() an NPN transistor is used to connect GND. When I release the button, the switch is disengaged, then the code will run and at the end of the code it will digitalWrite(X, LOW); and shut off the NPN, thus closing all GND to the ESP8266 or Arduino.

Is this a viable solution?


Any idea's on making a system that is ALWAYS OFF but on just temporarily(Pushbutton pressed) to run code then shut off again?


You can start with something like this one : latching-high-side-toggle-switch-circuit-press-on-hold-off.png, Push Button ON-OFF Soft Latch Circuits, Battery Powered Touch Toggle ON OFF Switch, Momentary Button MOSFET Power Switch for Microcontrollers and modify the shut off part using digital pin to interact with the lower (N-channel) mosfet.

Cheers, Ale.

What I am noticing is that when I disconnect GND, all the pins go HIGH for some reason...

What I am noticing is that when I disconnect GND, all the pins go HIGH for some reason...

Because if you disconnect ground, there obviously is no LOW. Ground = LOW.

You have discovered why on/ off switches are not connected in the ground line, always in the (positive) supply line.

You need a circuit such as ilguargua described, at least the part with the "high-side" FET which is switched in turn by the "low-side" FET.

You do not need the other complications in that other than the resistors to turn the FETs off.

And the device specified works only at a minimum of 5V, it may be more practical to use (bipolar - common) transistors instead with the PNP performing the "high-side" switching and a NPN connected to the control pin of the MCU (each transistor having a resistor in series with its base). Your pushbutton can conveniently connect across the NPN collector to ground.

Here it is! (Not my diagram - Gargled it!)

The 100k resistors are probably not necessary.

On paper this process looked like it would work, but when I tested it, it didnt work.

So if the rule of thumb is, GND disconnected, pins are high:

Ard GND | P(from PNP) | GND

P(from NPN) | Pin 4(HIGH) | Pin 2 (HIGH)

So basically when the switch is not pushed, PIN 4 and 2 are HIGH. the PNP does nothing. Then when the switch connects the GND, the circuit turns on, and I just need to make sure I put Pin2 High and Pin4 low. When I did this it didn't work for some reason. I then tested, when I connect the pin directly to the P on the NPN, I don't get the full 3v coming across GND, only 2.5v. The esp8255 can only output 15mA on the pin.

when I disconnect the pin I get the full 3v. Is there something I am doing wrong?

The PNP transistor being used is 2907A.
The NPN transitor being used is 222a.
3V circuit.

FYI, I don't know which resistors to use, so I have been using everything that I have and no dice.

Either you are using the circuit I last posted (with the 10k resistors; the 100k resistors can be anything higher), or all bets are off. I have explained that you do not switch the ground line.

Your reference to two different pins is confused. Only one pin needed to control it, which must be pulled HIGH as soon as it starts, and LOW when you need to turn off.

I think I may of found an issue. The ESP8266 can go up to 500mA spurts and averages 250mA, and I am actually using a 3904 NPN transistor. The datasheet says the current collector capabilities is 200mA and emotter is 40V. Can I still use these NPN and PNP transistors or do I need a different set?

So I followed the schematic you linked, not connecting power to ESP8266, I get 3.3v, the push button switch works, when I connect it to ESP8266 the voltage drops to 1V.

You need a transistor rated for the 500 mA impulse.

You also need a 100 µF capacitor across the ESP8266 supply terminals to help absorb these surges and I realised in the meantime that the resistor (R2) feeding the base of the PNP transistor will need to be more like 330 Ohms in order for the transistor to switch anything near that current. That is an extra drain on the battery while the circuit is running but is pretty much unavoidable.

Okay, do you have any recommendations off the top of your head on transistors rated for that high? NPN and PNP of course.

Also, the drain while its active is not a worry too much. I am make a wifi button, when you press it, it will send a quick wifi notification and shut down for good, so it wont take too much power long term.

the 100uf cap, does it need to be polarized?

Thanks for your help by the way.

Also, there is a lot of leakage current right now, I dont have the switch enabled and VCC is unplugged but I am drawing 94.5uA....

I traced the leakage current. When I remove the 10K resistor from the "High to run" pin to the NPN it drops.

Because you had that point connected to something that was running from a separate VCC. If it is connected to the device that is supplied by VCC, then there will be no voltage there when switched off. That is the whole point of the circuit.

Good morning, sorry for not completely understanding but this is what I have connected to everything.

Battery GND connected to GND on chip

V_Battery conneted to VCC on Battery

V_OUT connected to VCC on chip

HIGH to RUN connected to any output pin.

I am going to buy different npn/pnp transistors:NPN: MMBT2222ALT1G /PNP: MMBT2907ALT1G, I could have a bad transistor.

Another silly question but what wattage resistors should I be using for this? 1/4, 1/8, or 1/16?

Battery GND connected to GND on chip
V_Battery conneted to VCC on Battery
V_OUT connected to VCC on chip
HIGH to RUN connected to any output pin.

That is how it should be.

OK, so if you had a 330 Ohm resistor connected across the whole 5 V supply, then the power dissipated would be 5 x 5 / 330 W. I calculate that as 0.075 W, so that is the maximum you could possibly expect and even a 1/10 W resistor (which I think is what the little chip resistors are) would be quite adequate.

I am using a 3V circuit (coin cell). What about amperage, that doesn't play any part in this?

I am using a 3V circuit (coin cell). What about amperage, that doesn't play any part in this?

You are using a coin cell to power everything?
That will just plain not work.
Internal resistance of, say, a CR2032 is about 25 ohms at the levels you'd need to drive just the ESP. It is just plain not capable of supplying the 200mA needed to drive the radio.

You might want to look at this: http://interactive-matter.eu/blog/2009/08/29/driving-circuits-from-a-cr2032-lithium-coin-cell/