ESP8266 Power Latch

A small circuit to latch the power on when using an ESP8266 in a "Dash Button" style application

Similar projects worth following
Using the ESP8266 (or any other small micro) in a "Dash Button". or doorbell style application usually requires that the device is in deep-sleep for the vast majority of the time. Another method is to use a couple of MOSFETs to have the ESP8266 control its own power, so that the device is actually off, rather than sleeping, when inactive. If the application really is used infrequently (and a doorbell is a good example of this), the batteries will effectively last for their normal "shelf life".

The "files" section (below) has a downloadable link for the example .ino file. The code is very simple and implementing it in plain C using the standard, or open, SDK shouldn't present any problems.

The are basically only three, very short, routines.

  • LatchOn()
  • LatchOff()
  • ChkAutoOff()

The names pretty much tell you all there is to know. When your ESP first receives power, the very first thing you call, even (especially!) before initiating the serial connection, is LatchOn(). This simply takes the designated GPIO pin high, switching on the 2N7000, which in turn switches on the AO3415, so when the user removes their finger from the "on" switch (a momentary contact push switch), the power is held on by the ESP8266 itself. The debug message is pretty much a waste of time, as the serial port isn't initialized yet. :-)

LatchOff() is called when your ESP8266 has finished whatever task it was assigned to do, or when the RUNT_MAX (runtime max) time limit is reached. I have mine set to three minutes with:-

#define RUNT_MAX	3 * 60 * 1000

The ChkAutoOff() routine is the one which takes care of that auto-off timeout and should be called each time through your main loop.

It would be relatively simple to implement a "busy" flag so that the runtime counter is reset to zero (inhibiting the auto-off function) if the ESP8266 is still actively running some critical task. In my case (a doorbell application), the ESP is pretty much done once it has passed off the bell-push information to the MQTT server, so it just sits there displaying a mini "mood light" LED colour fader until it hits RUNT_MAX.


Eagle board file for power-latch switch

board - 55.49 kB - 11/09/2016 at 01:20



Eagle schematic for auto-power latch

schematic - 303.31 kB - 08/08/2016 at 00:25



Skeleton .ino file containing very basic usage example

ino - 1.64 kB - 08/07/2016 at 00:38



Schematic of the ESP8266 latching power switch

Portable Network Graphics (PNG) - 93.06 kB - 08/06/2016 at 23:41


  • 1 × AO3415 P-Channel MOSFET
  • 1 × 2N7000 N-Channel MOSFET

  • PCB

    PuceBaboon11/09/2016 at 01:31 0 comments

    Since the prototype works without any issues, I went ahead and ordered a PCB from OSH-Park, to make it a little easier to knock a few more of these switches together. The board is 50mm long and 15mm high, so that it fits down the side of the battery box in the "dollar-store" LED light case that I'm using for these units. There are no mounting holes, as the board is so small and light that it can be held in place with double-sided tape or hot glue.

    Be warned that (as of early Nov 2016) I haven't received the first batch of boards yet, so it's untested, but the OSH-Park shared project order is here:-

  • Prototype

    PuceBaboon07/27/2016 at 05:58 0 comments

    This circuit was prototyped on a small offcut of stripboard, with the AO3415 (SOT23 device) soldered directly onto the track side and the other components (all through-hole) mounted normally on the top side.

    The AO3415 is the actual power switching device and has impressive specs for something so small (4A of continuous drain current?!?! I don't think the stripboard can handle that). The main reason for choosing a device from this family though, is the impressively low gate switching voltage. This means that it should work well down to the discharge point of the battery where the ESP8266 will no longer function.

    Then I went and spoiled it all by using a 2N7000 N-channel as a driver buffer. That's a little unfair to the (good ole' workhorse) 2N7000, as it's still a very decent MOSFET, but it will definitely stop working before the AO3415 when the battery gets low (so if you need equivalent low-voltage switching, choose one of the even-numbered devices from the AO341x family tree, like the AO3414). If, on the other hand, you have a junk box full of 2N7000's, just throw one in and live with it.

    The reason that buffer N-channel is there to begin with is that my battery-pack actually supplies a much greater voltage than 3v3 (when fresh) and there's a voltage regulator downstream from this power switch (a low quiescent current, Holtek 7333). That means that if the gate connection for the P-channel were made directly to the ESP8266, the voltage would exceed the max limit for the ESP GPIO pins when the device was off. The N-channel provides protection for the GPIO pin.

View all 2 project logs

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates