Enhanced mode Mosfet to connect Reset to button when in Deep Sleep

I have an ESP8266 Wemos D1 board with Pin D2 in a Pullup mode connected to a button that is connected to grd when it is pressed. The button is normally used while the ESP8266 board is active. But after the ESP8266 is inactive for a while I want to put the board into deepsleep with no timeout. Right before it is put it into deepsleep it should connect the RST pin to the button circuit so that the next time the button is pressed it will wake up the board. The first command of setup would then be to disconnect the button from the RST pin.

I have some Enhancement Mode MOSFETs(IRFZ44NPBF). It is normally open but I need more of a normally closed switch. But depletion mode MOSFETs need negative voltage. Is there a way to design a circuit with a few more resistors or other components to make the Enhancement mode MOSFET work as I need it to. Or is there a better component to be able to make the connection when the board is off but disconnect it when the board turns on. As I am just controlling gnd I don't need something that is rated for high voltage obviously. Also, the board is running on battery so it would be best if it does not consume a lot of power especially during deepsleep mode.

Thanks for any input.

Do post a schematic of what you intend to do.

Here is my attempt at a schematic. I don't do much hardware stuff so this is a bit of a stretch for me. But hopefully this helps convey what I am trying to do.

The MOSFET is between GND and reset, the switch won't do anything useful to send a reset signal. It may work if you connect it between D2 and RST.

Yep. I think that was a flawed schematic. Here is one that I think makes more sense.

However, I still have the problem of how to have the MOSFET be closed(connecting rst to the button) when I don't have power and disconnecting when D5 is high.

This should work (pull-up resistor R1 should be present on the WeMOS board already):


Just about any small signal n-MOSFET or NPN transistor will do here. In case of using an NPN transistor increase the value of R2 to 10k and R3 to 100k.


I have some Enhancement Mode MOSFETs(IRFZ44NPBF).

Those are not logic level. They are power MOSFETs.

It is normally open but I need more of a normally closed switch. But depletion mode MOSFETs need negative voltage.

enhancement mode turn on when there's a voltage, off when there isn't. Depletion are the opposite.
The actually polarity of the voltage depends on whether p-channel or n-channel, as well as whether

Depletion mode is rare these days. Some sort of logic using CMOS logic chips might be the way to
go as these take only nanoamps when static - they can be permanently powered up. A single signal-level
NPN transistor or n-channel FET can be the switching device for the reset pin to ground - no need to
disconnect it as its high impedance till active. All you need to do is control whether the button drives
it or not using some combinatorial logic I think.

I don't think you need a transistor at all. Unlike Arduino board processors, the ESP8266 automatically does a reset when it wakes up from sleep. So I think if you can enable a wakeup interrupt on D2 just before going to sleep, that should do the reset when you push the button. Take a look at Ralph Bacon's video on this subject:

Edit: Ok, my memory failed me on this one. It appears you do indeed have to connect something to the reset pin to make it work.

I think this would work.

R1 is probably on the board already, or internal.

D5 would be brought high when you want the button to be connected to the Reset pin. If it's low, there would be no connection because there would be no base current. Actually, you could eliminate R2, and make D5 Input-Pullup to turn on the connection, or Input or Output-Low to turn it off. You just wouldn't want it to ever be Output-High because that would be a dead short when the button is pushed.

D2 is the input pin for normal use of the button in active mode. And R3 could just be the internal pullup resistor.

So I think it would work with just the transistor, and no added resistors. And it would draw no current except while the button is pressed, so from that point of view would be as good as a mosfet.

A potential problem is that when the reset takes effect, D5 will immediately go tri-state, which means reset will go back high. I don't know if there's any requirement to hold reset low for a time after the reset process begins. I don't think there should be, but the 8266 is a bit strange, so you would have to test it.

@wvmarle - Thanks for that diagram. I will try that this afternoon and see how it goes.
@ShermanP - I like the idea of a transistor. I will have to try it. Do you think the input pullup state will remain connected when the ESP8266 is in deepsleep mode? I will give it a try with a PN2222.

I would be surprised if going to sleep changed anything on the GPIO ports. But when the reset button is pressed I suspect all the port pins will go into input mode, with no pullup resistors.


  • I tried your schematic but for some reason I could not get it to work. But I could not really get the mosfet to respond at all so I was probably doing something wrong. The transistor method is almost working so I am going to pursue that for now but I may come back to the mosfet if needed.

@ShermanP - This method almost works. It works great if the board is on. I can change D5 from input to input_pullup and it switches the button from normal mode to board reset. However, as soon as the board goes to sleep the button does nothing. I tried installing a manual Pullup resistor from D5 to 3v3 but then as expected no matter what the board just resets when the button is pressed but it does reset the board after deep sleep. I have included my current schematic which is just using the internal resistors and no extra resistors. Any idea what I should try next. I like using just a little transistor and it is close as it works when the board is on. But maybe when the power is cut the board is losing the input_pullup value. I am really not sure. Is there a way to have the transistor need power to connect the button but then when power is cut revert to connecting to reset. Any ideas are appreciated.

Maybe your MOSFET is not logic level, or if it is maybe it is still almost fully closed at -3.3V VGS. A regular NPN transistor should work as well indeed.

It appears the state of the GPIO pins isn't maintained during deep sleep. So you would need an external pullup resistor on D5. To enable the button to reset the processor, you would set D5 to Input. To disable reset from the button, you would set D5 to Output, Low.

I found some vague references to GPIO registers that could be set to make GPIOs retain their state during sleep, but found nothing specific on where the registers are or how they work.

@ShermanP - You are correct. I used an external pullup resistor on D5 and it works with the Output Low. So I think I am all set.

I did some research on the GPIO registers and I found an example for GPIO14 which happens to be D5. So I am going to try and see if I can get that to work as it would be a very elegant solution to not have to add any external resistors. I will report back if I can get it to work.

Thanks for all of your help everyone.

Yes, I breadboarded it using a 2N4401, and found that a 100K pullup resistor worked fine. A 220K did not.

One thing to be careful about is the deep sleep current draw if you use the software solution you found. The pullup resistor solution won't use any current during sleep, only when in active mode (33uA for a 100K pulled up to 3.3V). If the software solution turns on the entire GPIO electronics, it may draw a lot of current in sleep mode. But I'll be interested to see what you come up with on that.

Edit: In my previous post I said setting D2 to Input would enable the reset function. I meant D5, and have corrected it in that post. So set D5 to Input to enable the button to reset, or to Output Low it disable it. Actually, in deep sleep D5 is automatically floating, so your code doesn't have to do anything but bring it Low when your code starts up.

Thanks for trying that out. I was using a 10k resistor and it was working fine. Would a 100k resister or a 10k resistor use more voltage when the ESP is on? Is there a reason to use a 100k resistor over a 10k? I have never measured current draw with my multimeter before so I am going to have to set that up next :slight_smile:

When you're in active mode, D5 will ground the bottom of the pullup resistor, and current will flow through it. A 3.3V drop across a 100K resistor will sink 33uA of current. A 10K resistor will sink 10 times as much - 330uA. In sleep mode, D5 will be floating, so that current will flow through the transistor when you push the button. The upper limit for the resistor is determined by the amount of current the transistor needs to sink to reset the device, which will depend on the base current provided by the pullup resistor, the transistor's gain, and the value of whatever pullup resistor is on the Reset line. Basically, you want the largest resistor that still works reliably.

Thanks. I will go with a 100k resistor. I researched the software register and though the manual mentions it - in practice It does not seem to actually work. So going with the external pullup. Thanks so much for all your help everyone.

So I created the circuit and I am using a lot more power in deep sleep then I expected. Part of the problem is that I have a 64 pixel NeoPixel array attached that even when not showing anything draws 20mA but the rest of my circuits is still drawing 13mA for the esp8266, a voltage divider battery measurement connected to A0, the transistor and a low quiescent LDO(MCP1700-330E). I was hoping to be in the uA area when in sleep so it looks like I probably need to disconnect all the power completely and then have the button turn it back on. So I was wondering if there was a circuit that could completely cut the power until the button is pressed. Once the button is pressed the controller would activate something on a pin like D5 to have the button go back to its normal usage on D2 until it came time to go to sleep. Maybe there is a way to still do it with the transistor but it seems like I might need something else.
Thanks for any input.