Power off ESP32 after doing some code?

I have found this power latch circuit online and I'm complete noob when it comes to electronics, I'm good at programming, since I had a lot of experiences with HTML and different Javascript frameworks in the past. So I'm wondering what i should change here in order to control my ESP32 like this:

  • SPST button switch that will control the power of the device
  • When this button is in ON position, it should power on my device
  • When this button goes to OFF position it should trigger some code before shutting itself off

I know how I will program this in VS Code, I'm just wondering is there anything that It should be changed in this diagram to suit my needs? You can find a code and circuit diagram of this project at https://onedrive.live.com/?redeem=aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdC0xUUpqTklfTVFiNlAtalhkZklDSXhRVWc%5FZT1hSmxWNkk&id=10F323CD9840B5DF%21111&cid=10F323CD9840B5DF

Power Latch Arduino Circuit.pdf (552.1 KB)

Post the code in code tags, we don't follow links. If a physical circuit is involved we need to see YOUR wiring, draw by hand and post a photo.

1 Like

That isn't exactly a power latch description. Check the circuit by the same name at https://electronoobs.com/eng_circuitos_tut61.php. Bonus tip, change the switch to a MOSFET and gate it with a genuine RTC.

Do you mean that you want to use a SPST switch instead of a momentary button?

If so then no changes to the circuit are needed.

Pin D3 will detect a LOW signal as long as the switch is ON.

When the switch is turned OFF pin D3 will detect HIGH and in the code you initiate the shut down sequence. Be sure that pin D3 has the pull up enabled

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.