EXTREME POWER SAVING (0µA) with Microcontroller External Wake Up: Latching Power Circuit

In this tutorial, we’ll show you how to build an Auto Power Off circuit (Latching Power Circuit) on a custom PCB, which is extremely useful to save power in your electronics projects.

EXTREME POWER SAVING 0µA with Microcontroller External Wake Up: Latching Power Circuit

An Auto Power Off Circuit or also called Latching Power Circuit allows you to cut off power completely when a microcontroller is not executing any task, which is great to make batteries last longer in your electronics projects.

Watch the Video Tutorial

You can watch the video tutorial or continue reading for the complete project instructions.

Resources

You can find all the resources needed to build this project in the links below (or you can visit the GitHub project):

Auto Power Off PCB

We wrote a guide some time ago about assembling the latching power circuit on a breadboard, but it’s more practical to have it on a dedicated PCB (shown in the following figure) if you plan to use it in multiple projects.

Auto Power Off Circuit Latching Power Circuit PCB

The PCB we’ll build is very versatile and it can be used with an ESP32, ESP32-CAM, ESP8266, Arduino or any other microcontroller.

ESP32, ESP32-CAM, ESP8266, Arduino or any other microcontroller

You can power it with a battery, rechargeable batteries + solar panels, or any voltage source.

Li-Ion Lithium LiPo batteries

It can be turned on by different triggers for example from a pushbutton press, motion detected by a PIR sensor, a magnetic reed switch, or any other digital sensor.

pushbutton motion detected by a PIR sensor magnetic reed switch or any other digital sensor

Auto Power Off vs Deep Sleep

This project has nothing to do with deep sleep, because with the auto power off circuit, your microcontroller doesn’t consume power when it’s not executing any task.

In deep sleep mode there is much less power consumption than the active mode. However, there is power consumption because your microcontroller is being powered on (with some of its peripherals shut down). Learn more about deep sleep.

JLCPCB Sponsorship

This project was sponsored by JLCPCB. JLCPCB is one of the most popular PCB brands, with more than 700,000 customers worldwide. It’s specialized in quick PCB prototype and small batch production.

JLCPCB how to order PCBs

You can order a minimum of 5 PCBs for just $2 + shipping which will vary depending on your country.

If you want to turn your breadboard circuits into real boards, you just need to upload the gerber files to order high quality PCBs for a low price. We’ll show you how to do this later in this tutorial.

How the Auto Power Off PCB Works

Let’s take a quick look on how the auto power off PCB works without going into much detail about the circuitry, because we have a dedicated guide explaining how it works. You can read it here: Latching Power Switch Circuit (Auto Power Off Circuit) for ESP32, ESP8266, Arduino.

Quick reminder: the auto power off circuit cuts off the power completely. So, there’s no power consumption when the microcontroller is not running any task. Whereas in deep sleep mode, there is always some sort of power consumption because your microcontroller is powered on with some of its peripherals shut down.

Here’s how the auto power off PCB works:

How the Auto Power Off PCB Works

You send a HIGH signal to the TRIGGER pin (1). When you send a HIGH signal through this pin, the microcontroller will turn on, but only for a few microseconds (2).

The trigger to get power to your microcontroller can be a pushbutton, a reed switch, a PIR motion sensor, or any other digital sensor.

How the Auto Power Off PCB Works remain on

To keep your microcontroller powered on, you need to send a HIGH signal from one of its GPIOs to the LATCH pin (labeled as IN) (3).

As long as the LATCH PIN is set to HIGH you’ll keep your board powered (4). So, you can execute any task during that time (5). To power this circuit, you can use a battery or any voltage source (battery + solar panels).

Keep in mind that the voltage on the input side, it’s the same on the output side. If you want to power your ESP32 or ESP8266 with a lithium battery (which outputs approximately 4.2V when fully charged), you need a voltage regulator circuit. This subject was already covered in the following tutorials:

How the Auto Power Off PCB Works turn off

When you’re done with that task, you can cut the power by sending a LOW signal to the LATCH PIN (6). Because the Microcontroller is completely powered off, it is not consuming any power (7).

Designing the PCB

To design the circuit and PCB, we used EasyEDA which is a browser based software to design PCBs.

Designing the Circuit and PCB with EasyEDA

If you want to customize your PCB, you just need to upload the following files:

Or you can simply download the Gerber files that I’ve used and order the final PCBs yourself.

In my opinion, the most important step when creating a PCB is to first ensure your circuit actually works on a breadboard or stripboard before designing the circuit.

Auto Power Off Latching Power Circuit Breadboard Design

Creating the circuit works like in any other circuit software tool, you place some components and you wire them together. When you’re happy with your circuit and pins usage, make sure you assign each component to a footprint.

Auto Power Off Latching Power Circuit Schematic Design

Having the parts assigned, you can start placing each component and when you’re happy with the layout, make all the connections and route your PCB.

Auto Power Off Latching Power Circuit PCB Design

Once you’re done, save your project and generate the Gerber files.

Auto Power Off Latching Power Circuit Order PCBs Export Gerber Files

This software allows you to automatically order your PCBs from JLCPCB. Alternatively, you can also follow the next steps to order the exact PCBs we’ve built.

Ordering the PCBs

You can order the PCBs easily, even if you don’t know how to design them (you just need to use our files).

1. Download the Gerber Files – click here to download the Gerber files.

2. Go to JLCPCB.com and click the “QUOTE NOW” button.

Auto Power Off Latching Power Circuit How to Order PCBs

3. After a few seconds, you should see a “Success” message at the bottom. You can check the Gerber Viewer Link to see if everything went as expected.

Auto Power Off Latching Power Circuit Gerber viewer

4. You can order 5 PCBs of any color for just $ 2 + shipping (approximately $6 to Portugal). When you’re happy with your order you can click the SAVE TO CART button to complete the purchase.

Auto Power Off Latching Power Circuit How to Order PCBs final price

Parts Required

Parts Required For Auto Power Off Circuit PCB

To build your PCB and follow this tutorial, you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

I’ve ordered the PCB components from LCSC, but you can order them from any other electronics store.

SMD Components Parts For Auto Power Off Circuit PCB

Unboxing the PCBs

In 4 business days, I’ve received the PCBs at my office.

Unboxing Auto Power Off Circuit PCB

As usual, everything comes very well packaged and the PCBs are really high quality, specially the silkscreen. 

Auto Power Off Circuit PCBs

Soldering the PCBs

The next step is soldering the components to the PCB. Although these are SMD components I didn’t find them difficult to solder. The resistors used are the 1206 package. I recommend starting by soldering the smallest components and leave the headers to the end.

Auto Power Off Circuit Soldering PCBs

To solder the PCBs, I’ve used the TS80 soldering iron. The TS80 soldering iron is the TS100 successor. I have a review about the TS100 soldering iron. I didn’t have time yet to write a review about the TS80, but it’s by far the best portable soldering iron I’ve used.

TS80 Soldering Iron

Recommended reading: Best Soldering Irons for Beginners

Assembling the circuit

To test the board, we connected a PIR motion sensor to the trigger pin and applied 3.3V from a power supply. We connected the LATCH pin to GPIO 5 of the ESP32. We also connected the pin marked as LED to GPIO 4 for testing purposes.

You can follow the next schematic diagram:

Latching Power Circuit ESP32 Connected Triggered By PIR Motion Sensor

You can use a similar circuit for other microcontrollers, we’re using an ESP32.

You can use any other trigger like pushbutton, reed switch, or digital sensors with a threshold like smoke sensor, sound sensor, soil moisture sensor, rain sensor, etc…

Pushbutton PIR motion sensor magnetic reed switch or digital sensor

Uploading the Code

To test the circuit, you can upload a sample code that keeps your board powered on for 10 seconds after a trigger signal.

The following code is compatible with ESP32, ESP8266 and Arduino.

/*********
  Author: Rui Santos

  Complete project details at https://RandomNerdTutorials.com/power-saving-latching-circuit/

  Permission is hereby granted, free of charge, to any person obtaining 
  a copy of this software and associated documentation files.

  The above copyright notice + link to project page and this permission 
  notice shall be included in all copies or substantial portions of the Software.
*********/

// Define power latch pin for ESP32 (GPIO 5) / ESP8266 (GPIO 5) / Arduino (Digital 5)
const int powerLatch = 5;
const int led = 4;

void setup() {
  // Define pin as an OUTPUT
  pinMode(powerLatch, OUTPUT); 
  pinMode(led, OUTPUT);
  
  // Keeps the circuit on
  digitalWrite(powerLatch, HIGH);
  
  // Turn ON an LED connected to GPIO 4
  // (after the powerLatch pin is set to LOW, your board powers off and it also turns off this LED automatically)
  digitalWrite(led, HIGH);

  // ADD YOUR TASK HERE (HTTP REQUEST, MQTT Message, Datalogger, etc)
  
  // Waits for 10 seconds
  delay(10000);
  
  // Turns the power latch circuit off
  digitalWrite(powerLatch, LOW);
}

void loop() {
  
}

View raw code

How the code works

Start by defining the powerLatch pin. We’re using GPIO 5, but you can use any other pin.

const int powerLatch = 5;

For testing purposes we’ll turn on an LED connected to GPIO 4. In this case, it’s the on-board LED of the auto power off PCB.

const int led = 4;
Latching Power Circuit ESP32 Project Demonstration LED on

In the setup(), define the powerLatch and led pins as outputs.

pinMode(powerLatch, OUTPUT);
pinMode(led, OUTPUT);

Next, set the powerLatch pin to HIGH. When we set it to HIGH, we ensure that there is power coming to feed the microcontroller.

digitalWrite(powerLatch, HIGH);

Turn ON the LED connected to GPIO 4 (after the powerLatch pin is set to LOW, your board powers off and it also turns off this LED automatically)

digitalWrite(led, HIGH);

Next, for demonstration purposes we keep the LED on for ten seconds.

delay(10000);

After that, we set the powerLatch pin to LOW. When it is set to LOW, the power is cut off, and the microcontroller turns off.

digitalWrite(powerLatch, LOW);

Add the task you want to perform after setting the powerLatch pin to HIGH and before setting it to LOW.

Your task can be making an HTTP request, publish an MQTT Message, datalogging, etc…

Demonstration

Finally let’s test this setup, and see it in action.

When motion is detected, the PIR motion sensor sends a HIGH signal, and there’s power coming to the ESP32 that can be confirmed by the LED remaining lit.

Latching Power Circuit with ESP32 PIR Sensor Detects Motion

When the ESP32 is on, the whole circuit consumes about 65 mA.

Latching Power Circuit with ESP32 Powered On measurement

After 10 seconds, the ESP32 turns off. If we measure the power consumption, you can see that the ESP32 is not consuming any power. It’s completely powered off.

Latching Power Circuit with ESP32 Powered Off measurement

This would work exactly the same for an ESP8266, Arduino, STM32 or any other microcontroller.

The PIR motion sensor consumes very little power, about 14 uA. So, even with a small battery it would last years. But if you’re using a pushbutton or a reed switch, these don’t consume any power.

Latching Power Circuit with ESP32 PIR Motion Sensor Consumption

Wrapping Up

[Update] the assembled PCB giveaway ended and the winners are: Ion Gheorghe, Domenico Carvetta, and Jan Pieter Duhen.

We hope you’ve found this project useful and you can modify it for your own needs. To learn more about the latching power circuit or to build the breadboard version, you can read the following tutorial:

How to power the Auto Power Off Circuit PCB:

More projects with PCBs:

Thanks for reading.


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

77 thoughts on “EXTREME POWER SAVING (0µA) with Microcontroller External Wake Up: Latching Power Circuit”

      • Congratulations for being second to second new knowledge, I would like the PCB to use in a LoRa Wan project with ESP32 in large fields where energy does not reach. thanks Rui.

        Felicitaciones por estar aportando segundo a segundo conocimientos nuevos, me gustaria la PCB para usar en un proyecto LoRa Wan con ESP32 en campos extensos donde no llega la energia. gracias Rui.

      • Why not make the PCB smaller so this could fit with an ESP-01? Those little cheap devices desperately need power saving.

    • I’ve been reading your articles for some time now. And i have to say they are among the best on ESP8266 and HA matters. I don’t have any future requests for you, as your articles are simply fantastic. Your writing is clear, concise, and very interesting stuff.
      I’m still trying to build a simple “dash” button from one of your previous posts.
      Thanks!

      • Hi Nikola.
        Thank you so much for your nice words and for following our work.
        We always try to put our best in every tutorial.
        I hope you can finish that project. It is a very interesting one. And you can add this little circuit to the dash button to save even more power.
        Regards,
        Sara

  1. Thanks for the project! I have developed an ESP32-based LiPo charge monitor that publishes individual cell voltages and current output from a commercial charger to an Adadfruit IO Dashboard. This lets me monitor the charging process remotely. However, once the charger stops charging, the monitor becomes a load connected to the battery which gradually discharges the battery. This will let me to completely cut all power to the ESP32 by setting the powerLatch pin to LOW once a low charging current is sensed.

  2. Great tutorial Rui. I have been looking for a good “Power off” circuit for my solar low light circuit, with SuperCap power storage for some time. Now I can see a final design to push to a full working module with an AT-tiny.
    Thanks for sharing your designs..

      • Thanks Rui, your project is interesting in my opinion. I was looking for something similar to be able to leave my ESP cam inside my car managed by the existing burglar alarm control unit.
        Can I also modify the circuit to adapt it to assembly with discrete components?
        Thanks to you, keep it up.

        Grazie Rui, il tuo progetto è a mio avviso interessante. Cercavo qualcosa di simile per poter lasciare il mio ESP cam all’interno della mia auto gestito dalla centralina antifurto esistente.
        Posso anche modificare il circuito per adattarlo al montaggio con componenti discreti?
        Grazie a voi, continuate così.

  3. Hi Rui, thanks for this solution.
    As my Pool-Control-Project is nearly finished
    the next project will be some kind of house alarm system.
    I was thinking of using ESP8266s with reed switches to signalize
    status changes of windows incl. handles.
    Different to usual solutions you can buy,
    the sensors should be hidden within the window frame.
    So far i was struggling with an easy way to change batteries
    inside the frames.
    With this solution i don‘t mind replacing the batteries once in years.
    Thanks again.

      • I am working on E-ink paper with ESP8266 using battery and it wasn’t possible without your articles.

        I have almost done using deep sleep but after reading this article wishing to include this in my porject.

        My project is a retail signage in which ESP8266 takes data from server application and display to E-ink display and then goes to deep sleep for defined intervals.

        As deep sleep consume a little power and reduces battery timing for the tasks keep running which are not required after office hours.

        Now I would like to cut off the power as light goes dark and resume when office light turns on.

  4. Wonderful project just what I’ve been looking for to control my garden lights. When the Light level is low control the micro on and when the light level is rising by day switch the micro off.

    • Great project and fits perfectly to my sensor-nodes with lora on esp32 I’m working on. I already got a lot of informations and code from your website to realize this project and would be glad to be a winner.

  5. Great project.

    My own projects for this are:
    1. PIR triggered wifi camera with battery-powered ESP32

    My plea: produce a through-hole version–using vertical 1/6-watt or 1/8 watt resistors and T0-92 transistors should allow you to do it without much, if any, re-routing.

  6. Thanks Rui..
    This is exactly what i was looking for to power my (internet of things) project. I need the microcontroller to power up only when the user requested it to perform its only function (turning on water valves in a particular sequence). The user can use any method to request the set of valves to open. The chioces are: Ldr switch(for automatic once a day operation), rc switch, push button,motion,bluetooth , and wifi….. I will be studying this more…again..thanks

  7. Hi
    Very interesting project.
    One question about the process to wake up with a switch, motion sensor or reed switch.
    I did a project measuring my pool temperature with solar power and batteries.
    Can i add to my project, your project “EXTREME POWER SAVING” but i wonder :
    What kind of device can i use to wake up every hour ? Have you an idea ?
    Best regards

  8. Great great tutorials as always 🙂 I propose this project: a humid sensor that triggers to wet a field, it will allow to run an amount of water. Or a trigger that checks the oxygen in a pool with fishes to increase the oxygen, this is very useful for fishing farming.

  9. Thanks Rui,

    That’s a neat and great solution for long-term battery-powered projects!

    I’m intending to use it in a humane mouse trap – it will trigger a notification when the trapdoor (with magnetic reed switch) is closed.

      • Yes. But I expected some capacity in the circuit for giving the uc more time to get to hold the trigger. Especially if you have no debouncing in e.g. a switch. What is the timing? Also with a C you could switch off the processor after some time automatically, as long as the RC-constant is long enough for the program cycle. I think, if i find time, i will change the pcb to have the C as option, which you could mount if you need it.

        • Just to clarify… You have two options: 1) if the trigger pin is set to HIGH, the ESP will be powered on. 2) If you set the LATCH pin to HIGH, the ESP will remain on. The minimum pulse length to trig pin depends on how fast your microcontroller boots up and sets the LATCH pin to HIGH (which will depend on the firmware and processor). For example with an ESP32 and a very fast button press (without debouncing), it’s enough to activate the circuit. If you’re using an Arduino board, you might need to hold for at least 1 or 2 seconds the pushbutton.

    • Thanks for share. I relly like to test this project winning some of these boards. I have some sensors that today, they ate very power hungry.

  10. Hi,
    I have a bank of leds, powered by 3 x AA batteries. The leds ( to light a pathway) are powered on for about 1 minute only.
    The device was in use for over 6 months until I moved house. Since then, I have tested the leds about once per month.
    The batteries have not been changed for 3 years and the leds are still bright.
    The circuit uses the leds, the batteries, an NPN power transistor, a magnetic Reed switch and a multifunctional trigger/timer from eBay – these cost 99p for 10 !
    ebay.co.uk/itm/172128772065
    I have also used these in conjunction with a 2 coil latching relay which is set by the multifunctional trigger and then reset by the Arduino when the task is complete.

    As the circuit you have described, the device is triggered by 0v on the trigger pin !

    I just thought I’d pass this on as an alternative approach.

    Yours is a great site, please keep up the great work

    Kind regards
    Terry

    • Thanks for your helpful feedback! You can definitely buy similar boards. The goal is to experiment and to learn how to create custom circuits with this feature. I basically plan to create in a future project, an PCB ESP32/ESP8266 PCB with built-in power latch circuit

  11. Great article, I built a remote weather station, but the power drain overnight after a cloudy day is just a little too much for the small solar/battery power source. This project will give me the extra power savings I need without up sizing the solar cell.

  12. Great tutorial again 🙂 I have a project where I need to turn on an ESP32 every 15 min, take readings and publish them online via wifi. Is it possible to use this board with an external real time clock (RTC) sending an interrupt every 15min (and would this be better than using deepsleep in terms of power consumption)? Cheers

    • Hello, Oli! You can use a cheap Attiny13A in combination with this circuit. The ATtiny can even be put into a deep sleep with a very low consumption of a few uA. It can only sleep 8 seconds, but it counts how often it woke up. This allows you to trigger this circuit after any interval to turn on the ESP. Many greetings Stefan

  13. Great tutorial. I am sure this idea can replace some projects I have made which use a MOSFET to turn on and off peripheral devices which leak current, it kinda turns things on their head, in that now a peripheral can turn on its microcontroller.
    Another tool in my low power arsenal. Superb.
    Instead of a PIR I’d use a microwave radar, as Andreas Spiess (“the guy with the Swiss accent”) suggests in this video from a while ago : youtube.com/watch?v=9WiJJgIi3W0 – they are much more spider and fly trigger resistant!

  14. Hi Rui. Great project. I’m still very early in my learning stages but I’ve been looking for a way to sense when my sump pump either fails or water is coming in too quickly for it to keep up and the water level rises too high within the hole. I am looking for a way to signal me remotely that the water level is high. I often am away from home and a remote signal would allow me to have a neighbour check on my home, etc. This power off module would allow me to also not to have to worry about my sensor running out of power while I am away.

    Great job on the site and all the great projects.
    Kevin

  15. Nice project

    was looking for such a circuit for a room presence detector. the board could switch the controller to send the command to the tv or ac to switch it off.

  16. This is the perfect addition to my wireless thermostat.
    I used to put it on sleep, but this is better.
    Every 2 minutes, the thermostat is up, measure temperature and adjust heating or cooling.
    Now i will save a lot of battery power.
    Thanks for project.

  17. Thank you Rui – very timely! I am currently wrestling with power management for my solar-powered propane gas meter data logger. I think you have just provided me with a practical solution.

    Here is a summary of things so far: therowdens.org/RNT/solarmeter.htm

  18. I would like to use this zero power circuit to shut down a microcontroller on an observation station on the back side of the moon. Of course I will ned some help from NASA, China or India to get the rest of the project underway.

  19. Hi Rui,
    Thanks for the excellent project. I think I use your circuit to replace my 433Mhz door/window sensors with ESP’s on WiFi.
    I’m not so used to SMD components, so I’m considering editing the gerber files to fit normal sized components

  20. I could use this for my cat-cam!
    I have a “solar powered IoT garden shed”.
    It has solar panels, a 12V battery, an ESP8266 with INA260 voltage/current sensor and a BME280 weather sensor. I’d like to hook up my ESP-CAM and infrared light through the circuit, to prevent the battery draining. Only when the cats enter the shed for their nap, the camera should turn on.

  21. Hi Rui, thanks Rui. This board is a good idea. It would fit perfectly in my garden shed. At each door opening I could turn on the light and retrieve the temperature and humidity variables via wifi.

  22. Hi Tigran

    You are speaking about Tmp5111 but i try to google it
    and i don’t find any thing on it
    Can you be me precise please

    regards

  23. Hi Rui

    I am looking for a tutorial on how to use EasyEDA.
    I am trying to learn how to realize a schematic of the PCB

    Do you know if there is somewhere that kind of tutorial ?

    Thx
    Best regards

    • Hi.
      At the moment, we don’t have any tutorial on how to use EasyEDA.
      But that’s on our plans. We’ll try to create a getting started tutorial with EasyEDA soon.
      Regards,
      Sara

  24. I built a magnetic lock using a 555 timer, not too long ago.
    I had the problem that it drew too much power while doing nothing.
    Id love to retry it with this circuit and see if I can get away without having to take out the batteries Everytime

  25. This is awesome project.
    I think I need to make a auto solar project. Which enables more efficient energy to us.
    Solar moves according to sunlight
    Please make this !

  26. I’m currently using a prototype of your original latching power circuit with an ESP 01 as the microcontroller and a pushbutton to create an “amazon dash” style MQTT button.

    GPIO 2 is used for the latching signal, but as GPIO 2 needs to be HIGH at boot of the ESP 01, I have modified the circuit so that it is tied back to the pushbutton. It seems to be working well so far.

    My next step was to learn how to design a PCB and start finalising the project so this tutorial is PERFECT timing!

    Thank you Rui for another informative tutorial!

  27. Hello! first of all thank you for providing your great circuit. I implemented it on the breadboard in order to run an ESP8266 cyclically in conjunction with an ATtiny13A. It works great. Of course I would like to try the new board in combination with the ATtiny13A 😉 What I noticed with the new circuit: A transistor has been added to the trigger input. Even without this transistor the circuit worked well. What is the purpose of the additional transistor?
    What still occupies me: Can you say something about the dimensioning of the individual resistors? E.g. why R5=10kOhm and R6=220 Ohm? (Also R2, R3, R7, R1). I am also concerned with the design of diodes and transistors: Why the 1N5819W and the 2N3904? You can see from the questions that I don’t know much about electrical engineering.
    If you are interested I will send you a photo of my breadboard and the fritzing as well as the firmware of the ATtiny.
    Many greetings
    Stefan

  28. great device.
    I want to use it to inform me me when mail is dropped into the letter box – I only want to go out when I know there is something there.
    I will have a reed switch on the letter box opening and when the flap is opened for someone to drop in a letter it will wake up my esp8266 and send me an email informing me that there is mail in the mailbox . 🙂

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.