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 build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

120 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.

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

        Reply
    • 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!

      Reply
      • 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

        Reply
  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.

    Reply
  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..

    Reply
      • 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ì.

        Reply
  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.

    Reply
      • 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.

        Reply
    • For my door sensors I fell back to magnetic switches and the trigger is just power on to the esp. I have my oldest one on the back door that is used regularly. Just changed a 9v battery after 6 years. Was an ATtiny with a delayed buzzer. Now a D1 mini.

      Reply
      • I see that you are using the latching circuit for the same purpose as my project. What I don’t understand is how to use the magnetic switches (did you mean reed switches?) to trigger the latching circuit; it seems to require a momentary connection (such as supplied
        by a push button) not a semi-permanent connection (as a reed switch supplies). I have asked this question on this forum but so far have not received any reply. Perhaps it is simple but it doesn’t seem so to me. Can you explain how you did it please?

        Reply
  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.

    Reply
    • 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.

      Reply
  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.

    Reply
  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

    Reply
  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

    Reply
  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.

    Reply
  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.

    Reply
      • 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.

        Reply
        • 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.

          Reply
    • 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.

      Reply
  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

    Reply
    • 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

      Reply
  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.

    Reply
  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

    Reply
    • 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

      Reply
  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!

    Reply
  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

    Reply
  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.

    Reply
  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.

    Reply
  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

    Reply
  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.

    Reply
  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

    Reply
  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.

    Reply
  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.

    Reply
  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

    Reply
  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

    Reply
    • 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

      Reply
  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

    Reply
  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 !

    Reply
  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!

    Reply
  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

    Reply
  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 . 🙂

    Reply
  29. Hello,
    I ordered PCB and bought parts. Every time my MOSFET-P begins to smoke. I don’t understand the situation. I made two tiles and I have the same result. Please help.
    Regards,
    Bart

    Reply
  30. Hi, one question please, on EasyEDA  , I can’t find the in the VCC net connections.
    Do I miss something? I’m trying to make this as @Bart on a single side PCB, if you have it please post it. Prefer on Eagle which is easier I think.
    Thank you. 

    Reply
  31. HI Rui and Sara,
    Thank you for another great project just what I am looking for, but I need help with a small change.
    I have remote ESP8266s monitoring room temperatures in a remote house, and reporting their readings to ThingSpeak. One thing that I have noticed is that the timing of the readings is drifting. I initially them set them up well spaced apart but some are now converging, this can be because of delays in making the connection to ThingSpeak which in tern delays the next DeepSleep period. What I would like to do is to use a RTC to drive the latching power circuit so that I can be sure the the ESP8266s are awake at the correct time and enhance the battery life at the same time. This requires a change to the circuit, so that the negative signal from the RTC will start the latching process.

    When I did my electronics education Thermionic Valves were King, and transistors were what we listened to Radio Luxembourg on!

    What I think that needs to be done, is to change Q3 the 2N3904 NPN transistor to a PNP. What I would like help with is deciding which PNP transistor to use and what other circuit changes would be required. I would welcome any assistance that you can give me.

    John

    Reply
  32. You still have to power the sensor either way to set the trigger. Deep sleep uses about 2ua so is that the only savings powering off?

    Reply
  33. Thanks for sharing a great idea! Built your circuit. Unfortunately it only reduces the voltage to the LED from 3V to 2,5 volts every few seconds. The voltage to the uC is reduced from 3.3V to 2.7V every few seconds. Appreciate any suggestions. The parts and layout are identical to yours.

    Thank you.

    Reply
      • What I do with LEDs is not digitalWrite but analogWrite with a value between 12 to 25 and that reduces A LOT the current, and no need for a resistance.

        Reply
  34. I just wanted to thank you for this circuit, and providing everything in such an easy to use/order manner. I would like to share a bit of ordering humor related to it. When I placed my order for boards I opted to get a solder stencil, thinking a sheet of plastic just larger than the boards with holes would be delivered, boy was I wrong. I received a 28cmx38cm sheet of stainless steel with the solder template dead center. I think it is going to be a bit difficult to get everything aligned this way.

    Reply
  35. Hi Rui and Sara,

    First of all, it’s awesome what you created, I couldn’t find a touch for you on the internet.

    I have two questions about the push button.

    You show it on your web pages with a motion sensor, but you also show it in the video (6: 12/8: 53) with a blue-headed pushbutton, but sorry you don’t really see how the pushbutton is connected to the trigger and the VCC and GND signals.
    I, as I interpret it:
    Is one of the pushbutton pins (red wire) connected to the trigger or VCC?
    Is the other leg of the pushbutton connected to GND through the 10k resistor? And sorry where is the green wire connected?

    Can you show a picture or description of this? I would be very grateful.

    And I would have another question that I found a designer switch on the aliexpress site.
    I show the link:
    aliexpress.com/item/1449851630.html?spm=a2g0o.store_pc_allProduct.8148356.13.391958fe0RZspo

    You think this can be incorporated into your systems as a switch.
    Of course, it works with 12V, as the aliexpress shows.

    Thank you in advance for your help.

    Regards
    Peter

    Reply
  36. Hi, great project. I’ve built it and it works flawlessly. However it takes times and I’d prefer to buy them complete – is there an easy way to do that atJLCPCB or elsewhere (aliexpress?)?

    Reply
  37. Hi,
    Thank you Rui for this great tutorial. One question about the circuit’s maximum current draw. Is it depend on the transistor choice (2N3904)? Please, thank you.

    Best,
    Salai

    Reply
  38. I wonder why you use so many different resistor values, e.g. at the bottom of the drawn schematic at the two diodes (10k, 220) and on the left hand side it’s first the R then the diode, and on the right hand side, first the diode then the resistor. Also the resistors against GND are not equal. Does this really matter? Or could I use 100k for all R against GND for example? Thank you!

    Reply
  39. Thanks for the excellent tutorial. There is one thing I don’t understand – how to trigger the microcontroller with a reed switch mounted on a door or window (a common way to use them in security alarms etc)? You can get a NO/C/NC double thrown reed switch to turn on the NO when the door is closed OR turn on the NC when the door is opened but these signals are not momentary as in a pushbutton or PIR – the connection remains as long as the door (window) is left closed/open. How would you use a reed switch with the latching circuit in this case?

    Reply
  40. Is there a way this circuit could be modified to read the voltage of the input voltage? I’m thinking if I have a battery powering the ESP32 I could monitor the voltage and potentially shut it down or at least display V

    Reply
  41. Could I please ask once more the question: how do you use a reed switch with this project? I can understand a PIR or momentary push button but a reed switch does not provide such a momentary trigger signal – it is either on or off, maybe for hours or days even. Will this latching circuit still work under these conditions?

    Reply
    • @David it is the way I am using the latching PCB in my project also. It is not difficult but should work best with a NO (normally open) reed switch which will close and conduct current when it is triggerred by a magnet.

      On the 3 pin header position labelled VCC – TRIG – GND, you need to connect one side of your reed switch to the “VCC” pin and the other side of your reed switch to the “TRIG” pin. You may ignore the GND connection here if you are using a button, a microswitch or a reed switch. Connect the 2 pin header position labelled VCC-GND to your power supply, it may be a battery for example but it’s voltage must match (or at least be within the specified input voltage range for) your microcontroller.
      The rest is well described including the Arduino compatible code in Rui’s tutorial.
      In operation once your magnet closes the reed switch for long enough, the power is fed to the microcontroller which will then “enable” the “latch” using a digital output pin. When your code has run and it is time to turn off the microcontroller the voltage is removed from the “latch” which disables the P-Channel Mosfet, turning off power to your microcontroller and the whole sytem waits in standby for the next trigger from the magnet etc.

      I hope this helps?

      Reply
      • There must be something I don’t understand. When the magnet approaches the NO reed switch the circuit closes sending the triggering signal. But when the code has finished running and the latching circuit tries to switch off the power, there would still be a triggering signal (assuming it’s a door that is closed and stays that way for a certain long period of time) so the latching circuit would be triggered again … ad infinitum.
        I read this other post https://randomnerdtutorials.com/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino/ and I can’t see why the 2N3904 transistor would ever stop pulling the gate of the NDP6020P mosfet to ground and therefore why the latching circuit would ever stop supply power to the microcontroller. Can someone please explain my error here? Or maybe I am not wrong?

        Reply
        • Hi, I also have the same problem while trying to create a low power consumption door state detector using reed switches.
          Have you tried this solution electronics.stackexchange.com/questions/519758/improving-edge-detector-with-latching-circuit-for-esp8266

          Reply
  42. HI,
    Just sharing my experience using this latch circuit with an ESP01 module. I ran into a bug which took some time to solve but here is the hint for anybody going this route.

    My project used an ESP01 module running very basic code to transmit a short message using ESP-NOW. Being battery powered the whole boot & transmit cycle to the latch release takes milliseconds so is great for long battery life. DO NOT however try to use GPIO0 or GPIO2 as I did for the latch “OUTPUT”, the pins generally reserved for digital IO. These pins see a little over 1volt during the boot process and I found that using either for the latch “OUTPUT” connected to the “IN” terminal of this PCB would cause the ESP01 to “boot-loop”, it would never start or run the seutp() function.
    Once your project does not require Serial communication then GPIO3 works perfectly to drive the latching circuit on this PCB.

    I hope sharing this will save somebody the couple of evenings I lost to discover the GPIO issue.

    Beyond this, it works superbly and does exactly what we want it to do, thanks Rui and Sara!

    Reply
  43. Just put together a nodemcu (wifi disabled to save 60% of the power it uses) pcb with this on it, along with a pizeo buzzer, CR123A lithium, and reed switch for door open close detection. I expect it will get 1.25 years of battery life. Thanks so much for sharing! I used JLPCB!

    Reply
  44. Hi and thank you,
    I’ve gotten the latch circuit and example sketch to work be wiring up a push-button to power on the latch circuit pcb as described in the tutorial.
    But now I’m trying to get a DS3231 from Adafruit to power on/trigger the latching circuit on an timed interval/alarm (every third day), and I’m completely lost.. It looks to me like the DS3231 triggers a low output when the alarm fires, so I don’t understand how to get the DS3231 to turn on the power..
    Is this possible to solve or do somehow?

    This is the ds3231 I’m trying to use:
    https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout

    Would be forever grateful for any assistance!

    Reply
  45. Thanks for the tutorial. I’m trying to create a BOM for the PCB but have an issue with the list of resistors. According to the picture, in R6 you mounted a SMD resistor of value 2000 which should be 200 Ohm, but from the parts list the only remaining resistor that I cannot directly map using the SMD digit code ist a 220 Ohm resistor. Is it correct to assume, that one should use a 200 Ohm resistor at R6?

    Once finished I’d be happy to send you my BOM to use with jlcpcb as I’m trying to get fully assembled circuits. But I’d also be happy if you’d upload a BOM in this article if you have one at hand.

    Thanks.

    Reply

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.