{"id":90119,"date":"2019-10-17T12:38:13","date_gmt":"2019-10-17T12:38:13","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=90119"},"modified":"2019-10-31T10:23:35","modified_gmt":"2019-10-31T10:23:35","slug":"power-saving-latching-circuit","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/power-saving-latching-circuit\/","title":{"rendered":"EXTREME POWER SAVING (0\u00b5A) with Microcontroller External Wake Up: Latching Power Circuit"},"content":{"rendered":"\n<p>In this tutorial, we&#8217;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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"EXTREME POWER SAVING 0\u00b5A with Microcontroller External Wake Up: Latching Power Circuit\" class=\"wp-image-90172\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>An <strong>Auto Power Off Circuit<\/strong> or also called<strong> Latching Power Circuit<\/strong> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the Video Tutorial<\/h2>\n\n\n\n<p>You can watch the video tutorial or continue reading for the complete project instructions.<\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/Sp8c-d6Scqw?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resources<\/h2>\n\n\n\n<p>You can find all the resources needed to build this project in the links below (or you can visit the <a href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"GitHub project (opens in a new tab)\">GitHub project<\/a>):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\"Example Sketch (for Arduino IDE)\u2028 (opens in a new tab)\" href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Latching-Power-Circuit\/master\/Code\/Latching_Power_Circuit\/Latching_Power_Circuit.ino\" target=\"_blank\">Example Sketch (for Arduino IDE)<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg\" target=\"_blank\">Schematic Diagram<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/blob\/master\/Schematics\/Gerber_Auto_Power_Off_Circuit_RandomNerdTutorials_20191009135729.zip?raw=true\" target=\"_blank\">Gerber Files<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/blob\/master\/Schematics\/Project_Auto_Power_Off_Circuit_RandomNerdTutorials_20191017093635.zip?raw=true\" target=\"_blank\">EasyEDA project files to edit the PCB<\/a><\/li><li><a href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/archive\/master.zip\"><strong>Click here to download all the files<\/strong><\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Auto Power Off PCB<\/h2>\n\n\n\n<p>We wrote a guide some time ago about <a href=\"https:\/\/randomnerdtutorials.com\/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino\/\">assembling the latching power circuit on a breadboard<\/a>, but it\u2019s more practical to have it on a dedicated PCB (shown in the following figure) if you plan to use it in multiple projects.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Circuit Latching Power Circuit PCB\" class=\"wp-image-90125\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>The PCB we&#8217;ll build is very versatile and it can be used with an <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32<\/a>, <a href=\"https:\/\/makeradvisor.com\/esp32-cam-ov2640-camera\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">ESP32-CAM<\/a>, <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\">ESP8266<\/a>, <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\">Arduino<\/a> or any other microcontroller. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/different-microcontrollers.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32, ESP32-CAM, ESP8266, Arduino or any other microcontroller\" class=\"wp-image-90124\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/different-microcontrollers.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/different-microcontrollers.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>You can power it with a battery, <a href=\"https:\/\/randomnerdtutorials.com\/power-esp32-esp8266-solar-panels-battery-level-monitoring\/\">rechargeable batteries + solar panels<\/a>, or any voltage source.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/lithium-battery.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Li-Ion Lithium LiPo batteries\" class=\"wp-image-90126\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/lithium-battery.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/lithium-battery.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>It can be turned on by different triggers for example from a <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\">pushbutton<\/a> press, motion detected by a <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/mini-hc-sr505-pir-motion-sensor\/\" target=\"_blank\">PIR sensor<\/a>, a <a href=\"https:\/\/makeradvisor.com\/tools\/magnetic-reed-switch\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">magnetic reed switch<\/a>, or any other digital sensor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"pushbutton motion detected by a PIR sensor magnetic reed switch or any other digital sensor\" class=\"wp-image-90127\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Auto Power Off vs Deep Sleep<\/h3>\n\n\n\n<p class=\"rntbox rntclblue\"><em>This project has nothing to do with deep sleep, because with the auto power off circuit, your <strong>microcontroller doesn\u2019t consume power<\/strong> when it\u2019s not executing any task.<\/em><\/p>\n\n\n\n<p>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). <a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">Learn more about deep sleep<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JLCPCB Sponsorship<\/h2>\n\n\n\n<p>This project was sponsored by <a rel=\"noreferrer noopener nofollow\" aria-label=\"JLCPCB (opens in a new tab)\" href=\"https:\/\/jlcpcb.com\/\" target=\"_blank\">JLCPCB<\/a>. JLCPCB is one of the most popular PCB brands, with more than 700,000 customers worldwide. It\u2019s specialized in quick PCB prototype and small batch production.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/jlcpcb.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"272\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-sponsorship.jpg?resize=750%2C272&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"JLCPCB how to order PCBs\" class=\"wp-image-90120\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-sponsorship.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-sponsorship.jpg?resize=300%2C109&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>You can order a minimum of 5 PCBs for just $2 + shipping which will vary depending on your country. <\/p>\n\n\n\n<p>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\u2019ll show you how to do this later in this tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Auto Power Off PCB Works<\/h2>\n\n\n\n<p>Let\u2019s 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: <a href=\"https:\/\/randomnerdtutorials.com\/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino\/\">Latching Power Switch Circuit (Auto Power Off Circuit) for ESP32, ESP8266, Arduino<\/a>.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\"><em><strong>Quick reminder:<\/strong><\/em> the auto power off circuit cuts off the power completely. So, there\u2019s 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.<\/p>\n\n\n\n<p>Here&#8217;s how the auto power off PCB works:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"303\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-1.png?resize=900%2C303&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"How the Auto Power Off PCB Works\" class=\"wp-image-90152\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-1.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-1.png?resize=300%2C101&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-1.png?resize=768%2C259&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<p>You send a HIGH signal to the TRIGGER pin (<strong>1<\/strong>). When you send a HIGH signal through this pin, the microcontroller will turn on, but only for a few microseconds (<strong>2<\/strong>). <\/p>\n\n\n\n<p>The trigger to get power to your microcontroller can be a pushbutton, a reed switch, a PIR motion sensor, or any other digital sensor. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"405\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-2.png?resize=900%2C405&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"How the Auto Power Off PCB Works remain on\" class=\"wp-image-90153\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-2.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-2.png?resize=300%2C135&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-2.png?resize=768%2C346&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<p>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) (<strong>3<\/strong>).<\/p>\n\n\n\n<p>As long as the LATCH PIN is set to HIGH you\u2019ll keep your board powered (<strong>4<\/strong>). So, you can execute any task during that time (<strong>5<\/strong>). To power this circuit, you can use a battery or any voltage source (<a href=\"https:\/\/randomnerdtutorials.com\/power-esp32-esp8266-solar-panels-battery-level-monitoring\/\">battery + solar panels<\/a>). <\/p>\n\n\n\n<p>Keep in mind that the voltage on the input side, it\u2019s the same on the output side.&nbsp;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:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/power-esp32-esp8266-solar-panels-battery-level-monitoring\/\">Power ESP32\/ESP8266 with Solar Panels<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-voltage-regulator-lipo-and-li-ion-batteries\/\">ESP8266 Voltage Regulator (LiPo and Li-ion Batteries)<\/a><\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"308\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-3.png?resize=900%2C308&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"How the Auto Power Off PCB Works turn off\" class=\"wp-image-90154\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-3.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-3.png?resize=300%2C103&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-pcb-how-it-works-3.png?resize=768%2C263&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<p>When you\u2019re done with that task, you can cut the power by sending a LOW signal to the LATCH PIN (<strong>6<\/strong>). Because the Microcontroller is completely powered off, it is not consuming any power (<strong>7<\/strong>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Designing the PCB<\/h2>\n\n\n\n<p>To design the circuit and PCB, we used <a rel=\"noreferrer noopener nofollow\" aria-label=\"EasyEDA.com (opens in a new tab)\" href=\"https:\/\/easyeda.com\/\" target=\"_blank\">EasyEDA<\/a> which is a browser based software to design PCBs.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"341\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/easyeda.jpg?resize=750%2C341&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Designing the Circuit and PCB with EasyEDA\" class=\"wp-image-90145\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/easyeda.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/easyeda.jpg?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>If you want to customize your PCB, you just need to upload the following files:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/blob\/master\/Schematics\/Project_Auto_Power_Off_Circuit_RandomNerdTutorials_20191017093635.zip?raw=true\" target=\"_blank\">EasyEDA project files to edit the PCB<\/a><\/li><\/ul>\n\n\n\n<p>Or you can simply download the <a href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/blob\/master\/Schematics\/Gerber_Auto_Power_Off_Circuit_RandomNerdTutorials_20191009135729.zip?raw=true\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Gerber files (opens in a new tab)\">Gerber files<\/a> that I\u2019ve used and order the final PCBs yourself.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-on-breadboard.png?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit Breadboard Design\" class=\"wp-image-90214\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-on-breadboard.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-on-breadboard.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Creating the circuit works like in any other circuit software tool, you place some components and you wire them together. When you\u2019re happy with your circuit and pins usage, make sure you assign each component to a footprint.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"592\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?resize=1200%2C592&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit Schematic Design\" class=\"wp-image-90174\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?w=1292&amp;quality=100&amp;strip=all&amp;ssl=1 1292w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?resize=300%2C148&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?resize=768%2C379&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-schematic.jpg?resize=1024%2C505&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Having the parts assigned, you can start placing each component and when you\u2019re happy with the layout, make all the connections and route your PCB.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"668\" height=\"486\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-pcb.png?resize=668%2C486&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit PCB Design\" class=\"wp-image-90175\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-pcb.png?w=668&amp;quality=100&amp;strip=all&amp;ssl=1 668w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-latch-circuit-pcb.png?resize=300%2C218&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/figure><\/div>\n\n\n\n<p>Once you\u2019re done, save your project and generate the Gerber files.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"484\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EASYEDA-generate-gerber-and-order-PCBs.jpg?resize=750%2C484&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit Order PCBs Export Gerber Files\" class=\"wp-image-90177\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EASYEDA-generate-gerber-and-order-PCBs.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EASYEDA-generate-gerber-and-order-PCBs.jpg?resize=300%2C194&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>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&#8217;ve built.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ordering the PCBs<\/h2>\n\n\n\n<p>You can order the PCBs easily, even if you don&#8217;t know how to design them (you just need to use our files).<\/p>\n\n\n\n<p><strong>1.<\/strong> Download the Gerber Files &#8211; <strong><a href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/blob\/master\/Schematics\/Gerber_Auto_Power_Off_Circuit_RandomNerdTutorials_20191009135729.zip?raw=true\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">click here to download the Gerber files<\/a><\/strong>.<\/p>\n\n\n\n<p><strong>2.<\/strong> Go to <a rel=\"noreferrer noopener nofollow\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/jlcpcb.com\/\" target=\"_blank\">JLCPCB.com<\/a> and click the \u201cQUOTE NOW\u201d button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"580\" height=\"475\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/jlc-pcb-order-pcbs.png?resize=580%2C475&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit How to Order PCBs\" class=\"wp-image-90146\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/jlc-pcb-order-pcbs.png?w=580&amp;quality=100&amp;strip=all&amp;ssl=1 580w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/jlc-pcb-order-pcbs.png?resize=300%2C246&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3.<\/strong> After a few seconds, you should see a \u201c<strong>Success<\/strong>\u201d message at the bottom. You can check the <em>Gerber Viewer Link<\/em> to see if everything went as expected.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"455\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-gerber-viewer-link.png?resize=750%2C455&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit Gerber viewer\" class=\"wp-image-90155\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-gerber-viewer-link.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-gerber-viewer-link.png?resize=300%2C182&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>4.<\/strong> You can order 5 PCBs of any color for just  $ 2 + shipping (approximately $6 to Portugal). When you\u2019re happy with your order you can click the <strong>SAVE TO CART<\/strong> button to complete the purchase.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"351\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-save-to-cart.png?resize=750%2C351&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Latching Power Circuit How to Order PCBs final price\" class=\"wp-image-90156\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-save-to-cart.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/JLCPCB-save-to-cart.png?resize=300%2C140&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/electronics-components-from-lcsc.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Parts Required For Auto Power Off Circuit PCB\" class=\"wp-image-90159\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/electronics-components-from-lcsc.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/electronics-components-from-lcsc.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>To build your PCB and follow this tutorial, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Microcontroller or Development Board, for example:<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32 Dev Board<\/a>&nbsp;(<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\">read ESP32 boards review<\/a>)<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\">ESP8266 NodeMCU<\/a>&nbsp;(<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\">read ESP8266 boards review<\/a>)<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\">Arduino UNO<\/a>&nbsp;(<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\">read best Arduino Starter Kits<\/a>)<\/li><\/ul><\/li><li>AO3413 SMD Transistor P-Channel MOSFET<\/li><li>2x 2N3904 SMD Transistor&nbsp;BJT NPN<\/li><li>SMD Resistors: 220K Ohm, 2x 100K Ohm, 2x 10K Ohm, 1K Ohm, 330 Ohm, and 220 Ohm (1206 package)<\/li><li>SMD LED (1206 package)<\/li><li>2x SMD Diodes (for example: 1N5819W)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/pir-motion-sensor-hc-sr501\/\" target=\"_blank\">PIR motion sensor<\/a> (or <a rel=\"noreferrer noopener\" aria-label=\"reed switch (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/magnetic-reed-switch\/\" target=\"_blank\">reed switch<\/a>, <a href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">pushbutton<\/a>, etc&#8230;)<\/li><li>Power Supply <\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<p>I\u2019ve ordered the PCB components from <a href=\"https:\/\/lcsc.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" aria-label=\" LCSC.com (opens in a new tab)\">LCSC<\/a>, but you can order them from any other electronics store.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/components-from-lcsc.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SMD Components Parts For Auto Power Off Circuit PCB\" class=\"wp-image-90158\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/components-from-lcsc.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/components-from-lcsc.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Unboxing the PCBs<\/h2>\n\n\n\n<p>In 4 business days, I\u2019ve received the PCBs at my office.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"500\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/package-from-JLCPCB.jpg?resize=750%2C500&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Unboxing Auto Power Off Circuit PCB\" class=\"wp-image-90161\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/package-from-JLCPCB.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/package-from-JLCPCB.jpg?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>As usual, everything comes very well packaged and the PCBs are really high quality, specially the silkscreen.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-from-jlcpcb.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Circuit PCBs\" class=\"wp-image-90162\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-from-jlcpcb.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-from-jlcpcb.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Soldering the PCBs<\/h2>\n\n\n\n<p>The next step is soldering the components to the PCB. Although these are SMD components I didn&#8217;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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Auto Power Off Circuit Soldering PCBs\" class=\"wp-image-90163\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>To solder the PCBs, I&#8217;ve used the TS80 soldering iron. The TS80 soldering iron is the TS100 successor. I have a <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/ts100-soldering-iron-review-best-portable-soldering-iron\/\" target=\"_blank\">review about the TS100 soldering iron<\/a>. I didn&#8217;t have time yet to write a review about the <a href=\"https:\/\/www.banggood.com\/MINI-TS80-Digital-OLED-USB-Type-C-Programable-Soldering-Iron-Station-Solder-Tool-Built-in-STM32-Chip-p-1330060.html?p=MA240439985285201910&amp;custlinkid=640788\" target=\"_blank\" rel=\"noreferrer noopener nofollow\" aria-label=\"TS80 (opens in a new tab)\">TS80<\/a>, but it&#8217;s by far the best portable soldering iron I&#8217;ve used.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/TS80-soldering-iron.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TS80 Soldering Iron\" class=\"wp-image-90164\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/TS80-soldering-iron.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/TS80-soldering-iron.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>Recommended reading:<\/strong> <a href=\"https:\/\/makeradvisor.com\/best-soldering-irons-beginners-hobbyists\/\">Best Soldering Irons for Beginners<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Assembling the circuit<\/h2>\n\n\n\n<p>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 <span class=\"rnthl rntclgreen\">GPIO 5<\/span> of the ESP32. We also connected the pin marked as LED to <span class=\"rnthl rntclblue\">GPIO 4<\/span> for testing purposes. <\/p>\n\n\n\n<p>You can follow the next schematic diagram:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"593\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?resize=1200%2C593&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit ESP32 Connected Triggered By PIR Motion Sensor\" class=\"wp-image-90167\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?resize=300%2C148&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?resize=768%2C380&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Auto-power-off-circuit-with-PIR-sensor-schematic-diagram.jpg?resize=1024%2C506&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>You can use a similar circuit for other microcontrollers, we&#8217;re using an ESP32.<\/p>\n\n\n\n<p>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&#8230;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors-1.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Pushbutton PIR motion sensor magnetic reed switch or digital sensor\" class=\"wp-image-90168\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors-1.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/several-digital-sensors-1.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Uploading the Code<\/h2>\n\n\n\n<p>To test the circuit, you can upload a sample code that keeps your board powered on for 10 seconds after a trigger signal.<\/p>\n\n\n\n<p>The following code is compatible with ESP32, ESP8266 and Arduino.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Author: Rui Santos\n\n  Complete project details at https:\/\/RandomNerdTutorials.com\/power-saving-latching-circuit\/\n\n  Permission is hereby granted, free of charge, to any person obtaining \n  a copy of this software and associated documentation files.\n\n  The above copyright notice + link to project page and this permission \n  notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n\/\/ Define power latch pin for ESP32 (GPIO 5) \/ ESP8266 (GPIO 5) \/ Arduino (Digital 5)\nconst int powerLatch = 5;\nconst int led = 4;\n\nvoid setup() {\n  \/\/ Define pin as an OUTPUT\n  pinMode(powerLatch, OUTPUT); \n  pinMode(led, OUTPUT);\n  \n  \/\/ Keeps the circuit on\n  digitalWrite(powerLatch, HIGH);\n  \n  \/\/ Turn ON an LED connected to GPIO 4\n  \/\/ (after the powerLatch pin is set to LOW, your board powers off and it also turns off this LED automatically)\n  digitalWrite(led, HIGH);\n\n  \/\/ ADD YOUR TASK HERE (HTTP REQUEST, MQTT Message, Datalogger, etc)\n  \n  \/\/ Waits for 10 seconds\n  delay(10000);\n  \n  \/\/ Turns the power latch circuit off\n  digitalWrite(powerLatch, LOW);\n}\n\nvoid loop() {\n  \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Latching-Power-Circuit\/raw\/master\/Code\/Latching_Power_Circuit\/Latching_Power_Circuit.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the code works<\/h3>\n\n\n\n<p>Start by defining the <span class=\"rnthl rntliteral\">powerLatch<\/span> pin. We\u2019re using <span class=\"rnthl rntclgreen\">GPIO 5<\/span>, but you can use any other pin. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int powerLatch = 5;<\/code><\/pre>\n\n\n\n<p>For testing purposes we&#8217;ll turn on an LED connected to <span class=\"rnthl rntclblue\">GPIO 4<\/span>. In this case, it&#8217;s the on-board LED of the auto power off PCB.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int led = 4;<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-LED.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit ESP32 Project Demonstration LED on\" class=\"wp-image-90170\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-LED.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/auto-power-off-circuit-pcb-LED.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, define the <span class=\"rnthl rntliteral\">powerLatch<\/span> and <span class=\"rnthl rntliteral\">led<\/span> pins as outputs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(powerLatch, OUTPUT);\npinMode(led, OUTPUT);<\/code><\/pre>\n\n\n\n<p>Next, set the <span class=\"rnthl rntliteral\">powerLatch<\/span> pin to <span class=\"rnthl rntliteral\">HIGH<\/span>. When we set it to <span class=\"rnthl rntliteral\">HIGH<\/span>, we ensure that <strong>there is<\/strong> power coming to feed the microcontroller.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalWrite(powerLatch, HIGH);<\/code><\/pre>\n\n\n\n<p>Turn ON the LED connected to <span class=\"rnthl rntcblue\">GPIO 4<\/span> (after the <span class=\"rnthl rntliteral\">powerLatch<\/span> pin is set to <span class=\"rnthl rntliteral\">LOW<\/span>, your board powers off and it also turns off this LED automatically)<br><\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalWrite(led, HIGH);<\/code><\/pre>\n\n\n\n<p>Next, for demonstration purposes we keep the LED on for ten seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>delay(10000);<\/code><\/pre>\n\n\n\n<p>After that, we set the <span class=\"rnthl rntliteral\">powerLatch<\/span> pin to <span class=\"rnthl rntliteral\">LOW<\/span>. When it is set to <span class=\"rnthl rntliteral\">LOW<\/span>, the power is cut off, and the microcontroller turns off.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalWrite(powerLatch, LOW);<\/code><\/pre>\n\n\n\n<p>Add the task you want to perform after setting the <span class=\"rnthl rntliteral\">powerLatch<\/span> pin to <span class=\"rnthl rntliteral\">HIGH<\/span> and before setting it to <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<p>Your task can be making an HTTP request, publish an MQTT Message, datalogging, etc&#8230;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Finally let\u2019s test this setup, and see it in action.<\/p>\n\n\n\n<p>When motion is detected, the PIR motion sensor sends a HIGH signal, and there\u2019s power coming to the ESP32 that can be confirmed by the LED remaining lit.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/trigger-auto-power-off-circuit-with-PIR-motion-sensor.png?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit with ESP32 PIR Sensor Detects Motion\" class=\"wp-image-90215\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/trigger-auto-power-off-circuit-with-PIR-motion-sensor.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/trigger-auto-power-off-circuit-with-PIR-motion-sensor.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>When the ESP32 is on, the whole circuit consumes about 65 mA.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/power-comsumption-ESP32-with-PIR-motion-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit with ESP32 Powered On measurement\" class=\"wp-image-90182\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/power-comsumption-ESP32-with-PIR-motion-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/power-comsumption-ESP32-with-PIR-motion-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>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\u2019s completely powered off.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-doesnt-consume-power-auto-power-off-pcb.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit with ESP32 Powered Off measurement\" class=\"wp-image-90181\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-doesnt-consume-power-auto-power-off-pcb.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-doesnt-consume-power-auto-power-off-pcb.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>This would work exactly the same for an ESP8266, Arduino, STM32 or any other microcontroller.<\/p>\n\n\n\n<p>The PIR motion sensor consumes very little power, about 14 uA. So, even with a small battery it would last years.&nbsp;But if you\u2019re using a pushbutton or a reed switch, <strong><em>these don&#8217;t consume any power<\/em><\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/mini-pir-motion-sensor-power-comsumption.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Latching Power Circuit with ESP32 PIR Motion Sensor Consumption\" class=\"wp-image-90183\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/mini-pir-motion-sensor-power-comsumption.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/mini-pir-motion-sensor-power-comsumption.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p><strong>[Update]<\/strong> the assembled PCB giveaway ended and the winners are: Ion Gheorghe, Domenico Carvetta, and Jan Pieter Duhen.<\/p>\n\n\n\n<p>We hope you\u2019ve 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:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino\/\">Latching Power Switch Circuit (Auto Power Off Circuit) for ESP32, ESP8266, Arduino<\/a><\/li><\/ul>\n\n\n\n<p>How to power the Auto Power Off Circuit PCB:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/power-esp32-esp8266-solar-panels-battery-level-monitoring\/\">Power ESP32\/ESP8266 with Solar Panels (includes battery level monitoring)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-voltage-regulator-lipo-and-li-ion-batteries\/\">ESP8266 Voltage Regulator for LiPo and Li-ion Batteries (ESP32 Compatible)<\/a><\/li><\/ul>\n\n\n\n<p>More projects with PCBs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-multisensor-shield\/\">Build a Multisensor Shield for ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/build-an-all-in-one-esp32-weather-station-shield\/\">Build an All-in-One ESP32 Weather Station Shield<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we&#8217;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 &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"EXTREME POWER SAVING (0\u00b5A) with Microcontroller External Wake Up: Latching Power Circuit\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/power-saving-latching-circuit\/#more-90119\" aria-label=\"Read more about EXTREME POWER SAVING (0\u00b5A) with Microcontroller External Wake Up: Latching Power Circuit\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":90172,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264],"tags":[],"class_list":["post-90119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/EXTREME-POWER-SAVING-with-Microcontroller-External-Wake-Up-Latching-Power-Circuit.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/90119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=90119"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/90119\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/90172"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=90119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=90119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=90119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}